Budi
Budi
Explore posts from servers
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Is it correct I need to use DATABASE_PUBLIC_URL instead of the private networking var? I'm running migrations via Github Actions prior to building the app.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Great. I got a Github Actions script to do this using the GraphQL API.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Sorry, I understand. I see this is something for the Pro plan.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How 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
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Bumping once more. I'm kinda stuck on this!
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Kindly bumping this team
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
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
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
I'll report back on my results.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Got it. Thanks Brody! Will implement this.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Please let me know about the startCommand too if you get a chance.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Okay I will try it, thanks.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Is this how I'd define the startCommand? If so I'll give that a shot!
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
It's working.
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
It's referring to my build script in package.json however. Isn't that correct? "build": "dotenvx run -f .env.production -- vite build"
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
I don't understand sorry. What do you mean?
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Hope that makes sense
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
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
RRailway
Created by Budi on 10/28/2024 in #✋|help
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
RRailway
Created by Budi on 10/28/2024 in #✋|help
How to sync state of production database to PR or staging environment?
Ah I see. So I would make it something like: "pnpm db:prod:dumprestore && pnpm db:prod:migrate && NODE_ENV=production node build"?
37 replies
RRailway
Created by Budi on 10/28/2024 in #✋|help
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:
{
"environments": {
"pr": {
"deploy": {
"startCommand": "echo 'start command for all pull requests!'"
}
}
}
}
{
"environments": {
"pr": {
"deploy": {
"startCommand": "echo 'start command for all pull requests!'"
}
}
}
}
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