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

9 days 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

9 days 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

9 days 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
FREEOP

9 days ago

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


bytekeim
PRO

9 days ago

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


wasimo420lol
FREEOP

9 days 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
FREEOP

9 days ago

because that's what am using on my local machine


wasimo420lol
FREEOP

9 days ago

and it wOrked

1444469503743361300


wasimo420lol
FREEOP

9 days ago

thank you


medim
MODERATOR

9 days 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 7 days ago


Loading...