Search code examples
ruby-on-railsrubyrubygemsbundlergemfile

How to run one database engine that is different from other developers sharing the same repo?


Saw How to customize Gemfile per developer?, but it didn't really do what I want and it is old.

Use case: I want to use Postgres and other developers are using SQLite.

One solution is to modify my Gemfile and not commit it, but then it will be out of sync if anyone makes any changes to it. And it will get accidentally committed after a while anyway.

Is there a clean way to remove the SQLite gem and add the Postgres gem in my environment, without affecting other developers' environments and other gems in the Gemfile?

FWIW, these changes only affect development and test environments. Not staging or production.

Or, perhaps it isn't necessary to change the Gemfile at all. Is it possible to install both gems and switch on the db config file? If so, how to set up a per-developer db config?

EDIT: Changing the Gemfile is not necessary. Just install the pg gem and change database.yml config file.


Solution

  • The correct approach for your case is to include all gems used by any developer in the gemfile and have a separate database.yml file per developer. You can simply leave database.yml as non-source-controlled, and provide a sample config file (database.yml.sample) for developers to copy and modify to their environment as needed.

    As others have pointed out, using different databases among developers is not very good practice as these differences can have unintended consequences in the non-original environment. In a case where you need to support multiple databases, this may not be a bad idea, but in such a case, each developer should have access to all the target database systems so that across-the-board testing can be done by everyone.