Why I didn't mount `rails/db` to persist my database in production
If you use Rails 8’s default SQLite database with default Kamal setup, you don’t need to mount rails/db in production because Rails 8 already persists SQLite in production by storing the database in storage/, which Kamal mounts by default.
My confusion started by the LLMs suggestion of adding a line to the deploy.yml file to make my database persist. The suggestion was confusing because my previous posts were able to survive multiple deploys. With a bit of digging, it turned out there’s no indication of database files under rails/db when I went through the project folder. This discovery firmed my suspicions further, and led me to open the database.yml file:
...skip previous lines...
# Store production database in the storage/ directory, which by default
# is mounted as a persistent Docker volume in config/deploy.yml.
production:
primary:
<<: *default
database: storage/production.sqlite3
The comment explained that the database lives in the storage/ directory.
With this info, I utilize kamal to execute the command below in the production container to verify that Rails was indeed storing the database using the storage/ path.
bundle exec kamal app exec -- "bin/rails runner 'puts ActiveRecord::Base.connection_db_config.database'"
I later confirmed this behaviour in the Rails 8 documentation.
In conclusion, if your project uses Rails 8 with default SQLite setup, you don’t need to mount rails/db for production to persist the database because the defaults set everything up for you already!