Budi
Explore posts from serversHow to sync state of production database to PR or staging environment?
Do you happen to have a template or an example of a Github Actions call where the dynamic database URL is requested? Specifically, the hard part would be knowing which
environmentId
to use in the API call.37 replies
How to sync state of production database to PR or staging environment?
I'm finally working on this and think this may work better if I use Github Actions for the db migration and pg_dump and pg_restore.
I want to ask for your input however. What's the most robust way to go about this? Currently I'm using Github PR auto-deploys on Railway and Railway's automatically deploying based on the the Dockerfile I have in my root folder.
Sonnet tells me the best way would be to separate the database migrations, backups and restorations from the build steps, so that it's more compatible with continuous deployment and horizontal scaling. Therefore it says I should put the
db migration
and pg_dump
and pg_restore
steps in a Github Actions workflow. Is that what you would recommend?
If so, what's the best way to access the public database URL of my postgres database in a staging environment? Do I need to call the Railway API in the Github Action to access this?
Also if I take this route, would you suggest keeping the automatic deployments via Railway's recognition of the Dockerfile (and leaving it out of the Github Action) and enabling "wait for CI", or would you recommend I rather disable that feature and call railway up
at the end of the Github Actions workflow?37 replies
How to sync state of production database to PR or staging environment?
I believe that Railway automatically injects
NODE_ENV=production
but only in runtime so I needed to force NODE_ENV
to production so dotenvx
can use the right environment file, decrypt the relevant .env.*
file and inject those env vars.37 replies
How to sync state of production database to PR or staging environment?
Glad you're asking. I had some issues with the
NODE_ENV
being properly inferred.
My Dockerfile ends with:
CMD ["pnpm", "start"]
And my start script is:
"pnpm db:prod:migrate && NODE_ENV=production node build"
"db:prod:migrate": "NODE_ENV=production dotenvx run -- vite-node .drizzle/migrate.ts"
37 replies
How to sync state of production database to PR or staging environment?
Also if I can use the
railway.json
, do I just put this in my root folder?
How would I modify this to work in addition to the start scripts I'm running in package.json
?
The docs suggest:
Is that startCommand
something that runs prior to the start
script from the package.json
which my Dockerfile refers to as the start CMD? This is now defined to first migrate, then build, like so: "start": "pnpm db:prod:migrate && NODE_ENV=production node build"
.37 replies