Connecting to Postgres instance on github action for migratioin

Hey,
Am trying to perform migration on github action but i cant directly connect to the postgres instance on fly because of the IP. So i need to connect to it through poxy flyctl proxy 5432 -a <postgres-app-name> . The step of connecting to postgres on github action works fine but the issue is that when connection the posgres is established, the terminal remains open this makes the steps on github action to run for ever.
Is there any way to run the connection in the background so i can run other commands.
or other way of connecting to postgres with keeping the terminal open ?

Thanks

1 Like

Hi, I’m already interested in that. Did you solve this by any chance? Thanks

This is probably the wrong way to do postgres migrations, unless you have a very specific reason to set it up this way.

It’s best to use a release_command for migrations, then we run them for you: App Configuration (fly.toml) · Fly Docs

3 Likes

I wasn’t aware of release_command - sounds perfect. Though the docs say that the command runs in a temporary VM. I will need some context, specifically the sqlx-cli, to invoke the migration.

And specifically for sqlx-cli - it expects the DATABASE_URL env var, but the DATABASE_URL that the Fly App uses is a bit different. SQLx expects the dbname parameter as part of the URL, whereas the Fly App connect directly to the correct dbname.
Is there an idiomatic way of working that out?

Thanks

Release commands run in a temporary VM, but they still have the same image, so you just have to make sure that sqlx-cli is installed in your app’s image. Note that the filesystem is ephemeral, though!

As for DATABASE_URL, that’s on you to specify. Probably the simplest solution is to have the release command be a shell script that sets up the environment variables, then calls sqlx-cli from that

It could look something like this:

#!/bin/bash
export DATABASE_URL="$DATABASE_URL/dbname"
sqlx-cli [...]
1 Like