@@ -24,6 +24,9 @@ export class MigrationService {
2424 ) { }
2525
2626 async connect ( ) {
27+ if ( this . configService . config . hooks ) {
28+ return this . configService . config . hooks . connection ( ) as never ;
29+ }
2730 await this . database . mongooseConnect ( ) ;
2831 return this . database . connect ( ) ;
2932 }
@@ -62,14 +65,22 @@ export class MigrationService {
6265 } ) ;
6366 throw error ;
6467 }
65- const collection = client
66- . db ( )
67- . collection ( this . configService . config . changelogCollectionName ) ;
68+
6869 const { fileName } = item ;
6970 const appliedAt = new Date ( ) ;
7071
7172 try {
72- await collection . insertOne ( { fileName, appliedAt } ) ;
73+ if (
74+ this . configService . config . hooks &&
75+ typeof this . configService . config . hooks . up === 'function'
76+ ) {
77+ await this . configService . config . hooks . up ( fileName ) ;
78+ } else {
79+ const collection = client
80+ . db ( )
81+ . collection ( this . configService . config . changelogCollectionName ) ;
82+ await collection . insertOne ( { fileName, appliedAt } ) ;
83+ }
7384 } catch ( err ) {
7485 await logger . error ( {
7586 migrated,
@@ -135,11 +146,20 @@ export class MigrationService {
135146 } ) ;
136147 throw error ;
137148 }
138- const collection = client
139- . db ( )
140- . collection ( this . configService . config . changelogCollectionName ) ;
149+
141150 try {
142- await collection . deleteOne ( { fileName : lastAppliedItem . fileName } ) ;
151+ if (
152+ this . configService . config . hooks &&
153+ typeof this . configService . config . hooks . down === 'function'
154+ ) {
155+ await this . configService . config . hooks . down ( lastAppliedItem . fileName ) ;
156+ } else {
157+ const collection = client
158+ . db ( )
159+ . collection ( this . configService . config . changelogCollectionName ) ;
160+ await collection . deleteOne ( { fileName : lastAppliedItem . fileName } ) ;
161+ }
162+
143163 const res : ReturnType = {
144164 fileName : lastAppliedItem . fileName ,
145165 appliedAt : new Date ( ) ,
@@ -230,6 +250,12 @@ export class MigrationService {
230250
231251 async statusInternal ( ) {
232252 const fileNames = await this . migrationsResolver . getFileNames ( ) ;
253+ if (
254+ this . configService . config . hooks &&
255+ typeof this . configService . config . hooks . status === 'function'
256+ ) {
257+ return this . configService . config . hooks . status ( fileNames ) ;
258+ }
233259 const client = await this . connect ( ) ;
234260 const collection = client
235261 . db ( )
0 commit comments