Replies: 3 comments 2 replies
-
I don't think your question have a right answer. There might be recommended ways, but I don't think it's correct or anything. I don't really like push, I feel like I'm not in control, it just runs. With migrations, I can see the migration file and make sure is correct. |
Beta Was this translation helpful? Give feedback.
-
It is surprising that there isn't a way to mark migrations as already complete. This feature exists in mikro-orm. Looking at the migrations table, this is the structure:
I might try to manually create a new row and see how it handles |
Beta Was this translation helpful? Give feedback.
-
For anyone needing a workaround to mark your migrations as completed, since they were by // fix_drizzle_push.ts
import original_config from "./drizzle.config";
import { MigrationConfig, readMigrationFiles } from "drizzle-orm/migrator";
import postgres from "postgres";
const config = {
...original_config,
migrationsFolder: original_config.out,
migrationsTable: original_config.migrations?.table ?? "__drizzle_migrations",
migrationsSchema: original_config.migrations?.schema ?? "drizzle",
} as MigrationConfig;
const migrations = readMigrationFiles(config);
const sql = postgres(process.env.POSTGRES_URL!);
const table_name = `${config.migrationsSchema}.${config.migrationsTable}`;
const get_db_migrations = sql`SELECT id, hash, created_at FROM ${sql(
table_name
)}`;
async function main() {
const db_migrations_hashs = (await get_db_migrations.execute()).map((m) => {
return m.hash as string;
});
for (const migration of migrations) {
if (!db_migrations_hashs.includes(migration.hash)) {
console.log(
`######## Adding migration to ${table_name}:\n\n${migration.sql}\n\n`
);
const new_db_migration = {
hash: migration.hash,
created_at: migration.folderMillis,
};
await sql`INSERT INTO ${sql(table_name)} ${sql(
new_db_migration,
"hash",
"created_at"
)}`.execute();
}
}
}
main().finally(() => process.exit(0)); |
Beta Was this translation helpful? Give feedback.
-
I'm a little bit in doubt what the intended flow of development is.
I have a local dev database, as i'm working on a new feature i'll modify my schema. I can then push the schema to my database using
push
, and test my queries.Once i'm certain about my changes, i then want to generate the migration file, but now I can't apply that migration to my local instance because the changes have already been applied, so the migration might fail.
So how do i get out of this situation? What I want to do is mark that the migration has already happened so its ignored, but so future migration files do get applied.
My only solution is to either hack the migration file so its empty when I apply, or nuke my db.
Beta Was this translation helpful? Give feedback.
All reactions