hey am trying to run a drizzle migration on my bun project
wasimo420lol
HOBBYOP

10 months ago

so am trying to run a migration and a seed.ts afterwards to seed and migrate my db service (postgress) and i do not know how to do that since there is no terminal in the web app or anything like that

Solved$10 Bounty

9 Replies

bytekeim
PRO

10 months ago

hey,

u can run migrations as part of your deployment process , run migrations in your start script

modify your package.json to run migrations before starting your app:

{
  "scripts": {
    "start": "bun run migrate && bun run seed && bun run index.ts",
    "migrate": "bun run drizzle-kit migrate",
    "seed": "bun run seed.ts"
  }
}

in Railway:

set your start command to: bun run start (to set start command in Railway: settings → deploy → custom start Command → bun run start

this automatically runs migrations → seeding → starts your app on every deploy

lmk if it works


bytekeim
PRO

10 months ago

also make sure:

-DATABASE_URL is set in Railway environment variables

-Your drizzle.config.ts points to process.env.DATABASE_URL

- Your seed.ts checks if data exists before inserting (to avoid duplicates on redeployment)


wasimo420lol
HOBBYOP

10 months ago

Thanks for the reply i will try it and thanks for the heads up


bytekeim
PRO

10 months ago

no problem! let me know if it works or if you run into any issues with the setup


wasimo420lol
HOBBYOP

10 months ago

uhh so the commands didn't work because i was using a postges standard template but i needed the geometry one postgis for it to work so am trying again


wasimo420lol
HOBBYOP

10 months ago

because that's what am using on my local machine


wasimo420lol
HOBBYOP

10 months ago

and it wOrked

1444469503743361165


wasimo420lol
HOBBYOP

10 months ago

thank you


10 months ago

You can also run your migration commands in a pre-deploy command.

https://docs.railway.com/guides/pre-deploy-command


Status changed to Solved medim • 10 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...