DATABASE_URL to this path when we either provide
or can detect the database.
For cases where an external database is used, you can set this yourself using
fly secrets set.
Accessing the DATABASE_URL value
The way you access theDATABASE_URL value depends on the module or ORM you are using.
For Prisma, ensure your prisma/schema.prisma file contains:
SSL/TLS
If your database is hosted external to fly.io, you generally will want to connect to it securely. The way to do so varies by database and adapter. An example for postgres can be found at node-postgres features > ssl. Equally important, if your database is hosted within the Fly.io private network, you will not want to connect with SSL/TLS connection options.Migrations
In order to use a database we need to load and evolve a schema. This often involves running a tool like Prisma’s migrate tool. For databases other than Sqlite3, this is best done as a one-off command run in a temporary VM. This can be accomplished by adding arelease_command in your fly.toml file.
For sqlite3, a different approach is required as the migration will need to be run on each machine that has a volume mounted. This can be accomplished by creating a small script that first runs the migrate command then run the web server start script. You can place this script in your source tree, and then use the following command to replace the CMD in the Dockerfile: