SQLite empty after deployment

I have a set up a volume with my sqlite file. The connection works and I can add data. Wehen I deploy the application, however, the database is empty again. Ist this a configuration on my side issue?

btw. how do you connect to a SQLite DB on the volume? Installing sqlite3 or can we mount the volume using wireguard and macfuse/sshfs?

General approach for sqlite:

  • Create volume with flyctl volumes create
  • Mount the volume by editing your fly.toml
  • Specify the location of the database by setting an environment variable, typically something like DATABASE_URL = "sqlite3:///mnt/volume/production.sqlite3". This can be done by setting a secret or even by edting the [env] section of your fly.toml.
  • remove any migrate instructions you may have from [deploy] section of your fly.tomll
  • create a small initialization script that does your database migrate followed by launching your server. Change your startup to involve this script. Depending on your setup, this may require changes to either your Dockerfile or your fly.toml.

For Rails, we are developing scripts to make all of these changes for you: fly.io-rails | RubyGems.org | your community gem host

1 Like

Hi @rico!

Have you properly configured your fly.toml to mount your volume to the folder where your database.sqlite file is located?

For example, your fly.toml file should contain a [mounts] section like below:


→ the source is the name you’ve specified for the volume you created
→ the destination is the path to the folder your sqlite database file is located in

Let’s say your database file is located here: /var/www/html/storage/database/database.sqlite

You’ll want to make sure the path in your [mounts] section points to a directory where you can eventually arrive at the database.sqlite file, like: /var/www/html/storage/database

For a step by step guide on volumizing an SQLite database in a Laravel Fly App, you can also checkout our documentation here: Databases · Fly Docs
( NOTE: the guide above mounts the volume to /var/www/html/storage to persist data in the storage directory including the contents of its subdirectories, like /var/www/html/storage/database folder )

1 Like

This works now. I basically followed SQLite in a Laravel Fly App and created a simple script in .fly/scripts to set up the storage directory with all the stuff Laravel and my app needs, including the sqlite file.

1 Like