Open shoooe opened 4 days ago
Having individual transaction for each migration would certainly make other things easier too. For example we could easily implement disabling transactions for individual migrations. There has been a feature request open for that forever.
However, there was a reason why it was implemented the way it is. I just can't remember it right now.
Changing the behaviour could also be a major breaking change and I don't know if we can do it without a massive deprecation period.
You could already migrate up one migration at a time to get individual transactions.
Oh true. For reference to others this is what I went with:
const migrations = await migrator.getMigrations();
const pendingMigrations = migrations.filter((m) => isUndefined(m.executedAt));
if (isEmpty(pendingMigrations)) {
console.info(`✅ Migrations are up to date!`);
}
for (const migration of pendingMigrations) {
const { error, results } = await migrator.migrateTo(migration.name);
results?.map((it) => {
if (it.status === "Success") {
console.info(
`✅ Migration "${it.migrationName}" was executed successfully`
);
} else if (it.status === "Error") {
console.error(`❌ Failed to execute migration "${it.migrationName}"`);
}
});
if (error) {
console.error("❌ Failed to migrate");
console.error(error);
process.exit(1);
}
}
Let's leave this open. It might make sense to have individual transactions.
Maybe we could ship both and allow enabling this? no breaking change..
Maybe. But enabling/disabling transaction for a single migration when we run a batch of migrations in one transaction would be horrible to implement. Basically we'd only allow that when the "transaction per migration" setting is enabled.
If you have a migration 0001 with this:
and a migration 0002 with this:
and then some migration 0003 that uses
some_enum
with valuevalue_3
then:From what I understand from the code this is caused by
migrateToLatest
running all pending migrations in a single transaction.Shouldn't each migration be independent and run in its own transaction? IME this is the behaviour that most other migration systems adopt (e.g. Django migrations).
Despite this ^ I'm loving this library more and more every day, so thank you again for this magical tool. ❤️