Optional database connection in the initializer

Hi!

I’m working on a project that uses rails and I would like to have an onboarding process where rails works even if there’s no database connection. I detect if ActiveRecord::Base is connected and if not, I show an html page to the user that explains how to connect it to the database.

With how the initializers works, I believe it’s not possible to include ActiveRecord and not have it connected to a database so I created a fork and wanted to discuss about it here.

Here’s the patch in my fork as it is right now:

https://github.com/pothibo/rails/commit/f359fd6288bc3a05f41266eeecbce04e21d8a5a2

Here’s a few things that might be worth discussing:

  • Is it something that can make it to master?

  • configuration name: can I name it better?

Have a good day,

Pier-Olivier Thibault

Hi Pier-Olivier,

Somewhat related - you might want to take a look at this approach that LevelUp uses to process payments when their system is too bogged down to process transactions in the database:

http://www.confreaks.com/videos/2481-railsconf2013-zero-downtime-payment-platforms

Not sure if this quite fits your use case, but it might be an alternative method of solving your root problem.

-Geoff

I don’t think it does, I’m talking about the initialization sequence and unless I’m mistaken, they are talking about database outage when the app is running.

Hi,

Your use case is rather specific, I don't think we should add such an option.

BTW, you may override active_record's init in your application.rb file. I did a proof of concept, see this gist: https://gist.github.com/phurni/caac3efcbb43a38b8946

Cheers,

Pascal

Yeah I know the solution, I wanted to know if you were interested making it into rails (I would have a provided the PR). All good then, I won’t submit a patch.