K
Kysely2w ago
mike

Any update on all migrations in single-transaction?

Is there anything new with the single-transaction for all migrations? Need something like this:
void (async () => {
await db.transaction().execute(async (trx) => {
await migrator.migrateToLatest({trx})
})
})();
void (async () => {
await db.transaction().execute(async (trx) => {
await migrator.migrateToLatest({trx})
})
})();
Unmanaged approach for multiple databases I am also considering to use unmanaged transactions which could (hopefully) solve multiple database migrations in one self-managed transaction like this. Did anybody here try this approach?
// Creating two independent transactions for two databases
DB1.query('BEGIN')
DB2.query('BEGIN')

try {
// run all DB1 migrations
// run all DB2 migrations

// Commit everything
DB1.query('COMMIT')
DB2.query('COMMIT')
} catch {
// Rollback everyting
DB1.query('ROLLBACK')
DB2.query('ROLLBACK')
} finally {
// Closing connections
DB1.CLOSE()
DB2.CLOSE()
}
// Creating two independent transactions for two databases
DB1.query('BEGIN')
DB2.query('BEGIN')

try {
// run all DB1 migrations
// run all DB2 migrations

// Commit everything
DB1.query('COMMIT')
DB2.query('COMMIT')
} catch {
// Rollback everyting
DB1.query('ROLLBACK')
DB2.query('ROLLBACK')
} finally {
// Closing connections
DB1.CLOSE()
DB2.CLOSE()
}
Reference: https://github.com/kysely-org/kysely/issues/1154
GitHub
Multiple migrations are run in a single transaction · Issue #1154 ·...
If you have a migration 0001 with this: export async function up(db: Kysely<unknown>): Promise<void> { await db.schema.createType("some_enum").asEnum(["value_1", &qu...
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server