0

I have encountered this in my Gemfile while learning ruby on rails:

group :development, :test do
  gem 'sqlite3', '~> 1.4'

group :production do
  gem 'pg'

So far I have understood that sqlite3 is not a production-ready database as it does not support multiple users to write the database at the same time. In this case, why don't we just use postgres in development?

  • 2
    What prevents you from changing that? –  Jan 16 '22 at 08:06
  • 2
    Using different databases in development/test and production is a huge mistake. Presumably using SQLite in development is easier because you don't have to install and configure a PostgreSQL server but it really only makes things harder when things don't work the same in development, test, and production. So that Gemfile is false laziness. – mu is too short Jan 16 '22 at 08:39
  • @a_horse_with_no_name nothing is preventing, just want to understand why it is written like that when generating a new rails application – Michelle Loh Jan 16 '22 at 10:15
  • Why? Because you choose to do so. If it wasn't you, ask the one who gave you this code. – Frank Heikens Jan 16 '22 at 11:21
  • 2
    Write concurrency isn't really the main problem with SQLite until you reach a fairly large scale. The immediate problems are that it lacks a lot of features - has a quirky interpretation of the SQL standards and doesn't work with ephemeral file systems such as the one in Heroku. – max Jan 16 '22 at 11:43
  • 1
    One of the reasons ppl do this is that ActiveRecord (and any ORM really) comes with the false promise that it abstract away any of the differences between the backing services so that it won't matter. What actually happens is that the inconsistency will only pop up after deployment. https://12factor.net/dev-prod-parity – max Jan 16 '22 at 11:48
  • 3
    The reason it's done in learning materials like Michael Hartls book is just to simplify the setup so that you can cover the stuff that matters for learning. One thing to be aware of when learning is that tutorials are often very far from actual best practices or something that should actually be used in paid work. – max Jan 16 '22 at 11:54

1 Answers1

0

There is no reason you can’t. It just requires additional configuration. It’s actually best practice to use the same database in development and production. SQLite is included for ease of use, and would probably fine for a lot of applications. But SQLite cannot be used on Heroku and some other hosting platforms. So you are better off setting up Postgres on your local machine for development in my opinion.