1- import * as path from 'path'
2- import { promises as fs } from 'fs'
1+ import * as path from 'node: path'
2+ import { promises as fs } from 'node: fs'
33
44import {
55 FileMigrationProvider ,
6- Migration ,
7- MigrationResultSet ,
6+ type Migration ,
7+ type MigrationResultSet ,
88 DEFAULT_MIGRATION_LOCK_TABLE ,
99 DEFAULT_MIGRATION_TABLE ,
10+ type MigrationProvider ,
1011 Migrator ,
1112 NO_MIGRATIONS ,
12- MigratorProps ,
13+ type MigratorProps ,
1314 type Kysely ,
1415} from '../../../'
1516
@@ -845,7 +846,6 @@ for (const dialect of DIALECTS) {
845846 }
846847 } )
847848
848-
849849 it ( 'should execute in transaction if disableTransactions is false when calling `migrateUp` and transactionDdl supported' , async ( ) => {
850850 const [ migrator , executedUpMethods ] = createMigrations ( [ 'migration1' ] , {
851851 disableTransactions : true ,
@@ -867,6 +867,36 @@ for (const dialect of DIALECTS) {
867867 expect ( transactionSpy . called ) . to . be . false
868868 }
869869 } )
870+
871+ it ( 'should run migrations using a provided transaction' , async ( ) => {
872+ const migrationName = 'trx_connection_method_fail_case'
873+
874+ const trx = await ctx . db . startTransaction ( ) . execute ( )
875+
876+ const provider : MigrationProvider = {
877+ getMigrations : async ( ) => ( {
878+ [ migrationName ] : {
879+ async up ( db : Kysely < any > ) : Promise < void > {
880+ expect ( db ) . to . equal ( trx )
881+ } ,
882+ } ,
883+ } ) ,
884+ }
885+
886+ const migrator = new Migrator ( { db : trx , provider } )
887+
888+ const { results, error } = await migrator . migrateUp ( )
889+
890+ expect ( trx . isCommitted ) . to . be . false
891+ expect ( trx . isRolledBack ) . to . be . false
892+
893+ await trx . rollback ( ) . execute ( )
894+
895+ expect ( error ) . to . be . undefined
896+ expect ( results ) . to . eql ( [
897+ { migrationName, direction : 'Up' , status : 'Success' } ,
898+ ] )
899+ } )
870900 } )
871901
872902 describe ( 'migrateDown' , ( ) => {
0 commit comments