migrations for multiple environment #1593
-
I want to use the same schema for different environments (production, development, preview, etc.). I did it like this: // _table.ts
export const pgTable = pgTableCreator((name) => `myapp_${process.env.NODE_ENV}_${name}`) // drizzle.config.ts
export default {
schema: "./schema",
driver: "pg",
dbCredentials: {
connectionString: process.env.DATABASE_URL,
},
tablesFilter: [`myapp_${process.env.NODE_ENV}_*`],
out: "./migrations",
} satisfies Config; it works perfectly. but the question is what should I do with the migrations? PS: I know this is not a drizzle-specific question but I am not a backend expert so I don't know the best practices. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You definitely need to configure and apply migrations in all environments. Otherwise you'll have differences in your environments and won't be able to track bugs and have issues everywhere. All your environments should be in sync. I believe you can just run the generate command once per migration, and then apply it to each environment. To be honest I think this is a great idea. |
Beta Was this translation helpful? Give feedback.
-
You can create your own migration approach I guess. Have not tested the following extensively but it basically does the same thing.
|
Beta Was this translation helpful? Give feedback.
You definitely need to configure and apply migrations in all environments. Otherwise you'll have differences in your environments and won't be able to track bugs and have issues everywhere. All your environments should be in sync.
I believe you can just run the generate command once per migration, and then apply it to each environment. To be honest I think this is a great idea.