how to properly auto migrate db in prod

so i have set up some automations to auto deploy my application that uses drizzle but i dont know what is the correct way to make it migrate. Like when i should do it
2 Replies
El Grande Padre
Option 4 on this page describes how you can migrate at run time https://orm.drizzle.team/docs/migrations#:~:text=Expand%20details-,Option%204,-I%20want%20to
// index.ts
import { drizzle } from "drizzle-orm/node-postgres"
import { migrate } from 'drizzle-orm/node-postgres/migrator';

const db = drizzle(process.env.DATABASE_URL);

await migrate(db);
// index.ts
import { drizzle } from "drizzle-orm/node-postgres"
import { migrate } from 'drizzle-orm/node-postgres/migrator';

const db = drizzle(process.env.DATABASE_URL);

await migrate(db);
Drizzle ORM - Migrations
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
El Grande Padre
I like to put my call to migrate behind an api endpoint so I still have control of when migrations happen. This does get a bit tricky if you're bundling your server side code because you need to have a way to reference the migration files.

Did you find this page helpful?