This part was simple. We just followed this guide to clone and deploy a demo app that was provided for us by fly. The first time you do this, you have to set up your account and add a credit card.
You can use psql
to create a new database that your local application will connect to. Once it's connected, you should connect to it in your code with a connection string. Make sure the connection string is set to a DATABASE_URL env var in your .env
file.
DATABASE_URL='postgres://localhost:5432/your_db_name'
Now that your database is set up, you want to update the schema to support your apps functionality. To do this, we'll use migrations.
Check out the docs and look at the package.json
file and db/migrations
directory in this repo for inspiration.
Once you've run your migraton to create a table, you can use psql
to add some data to it for testing purposes.
You can checkout the server.js
file in this repo for ideas.
Make sure it's all working locally!
fly postgres create
fly postgres attach --app <app-name> <postgres-app-name>
This sets the DATABASE_URL
env var on your express app so the server code you've written can connect to postgres without an additional configuration.
To do this, you need to add the following to your fly.toml
[deploy]
release_command = "npm run migrate up"
(Assuming you've defined a migrate
script in your package.json
file.)
Now that your fly infrastructure is set up, all you have to is remember to make all database schema changes with migrations, and then deploy as you normally would! š„³