SQLite
Rails is promoting sqlite and there’s allure to the simplicity. SQLite does not require a separate server process to operate. The database is stored as a single file on the disk.
However, it requires special consideration. We need to mount the path for the docker container path to the host path where the sqlite db is located to make sure it persists.
Volume Configuration
When using SQLite with your application, you need to configure a volume mount to store the database file.
Steps:
- Go to the App Resource Config section
- Under Volumes set
- Host Path: /data/apps/rails-sqlite/storage
- Container Path: /workspace/storage
This should store SQLite database files in a mounted shared directory that persists between deployments.
Production Thoughts
- SQLite will be limited to single-server deployments since the app and db need to be on the same server without resorting to more complex and slower shared filesystems like EFS.
- I’m not quite yet convinced that it’s best for most production use cases. I prefer databases like postgresql and mysql for production. It’s also quite easy to run a service with Blossom or cloud vendors.
Schema Load
Remember to load the schema for each of the databases. Example:
rails db:schema:load:cable
rails db:schema:load:cache
rails db:schema:load:queue
Important: This is a destructive action and will wipe away your current tables so be sure it’s what you want to do.
Remember to set up your config/database.yml for the multiple databases. I found you needed them for the current Rails env and test env also.