@@ -462,14 +462,14 @@ export class BaseDuplicateService {
462462 const prisma = this . prismaService . txClient ( ) ;
463463 const tableId2DbTableNameMap : Record < string , string > = { } ;
464464 const allTableId = Object . keys ( tableIdMap ) . concat ( Object . values ( tableIdMap ) ) ;
465- const sourceTableRaws = await this . prismaService . txClient ( ) . tableMeta . findMany ( {
465+ const sourceTableRaws = await prisma . tableMeta . findMany ( {
466466 where : { id : { in : allTableId } , deletedTime : null } ,
467467 select : {
468468 id : true ,
469469 dbTableName : true ,
470470 } ,
471471 } ) ;
472- const targetTableRaws = await this . prismaService . txClient ( ) . tableMeta . findMany ( {
472+ const targetTableRaws = await prisma . tableMeta . findMany ( {
473473 where : { id : { in : allTableId } , deletedTime : null } ,
474474 select : {
475475 id : true ,
@@ -503,9 +503,10 @@ export class BaseDuplicateService {
503503 } [ ] ;
504504
505505 // delete foreign keys if(exist) then duplicate table data
506+ // 1. collect foreign keys info
506507 for ( const dbTableName of dbTableNames ) {
507508 const foreignKeysInfoSql = this . dbProvider . getForeignKeysInfo ( dbTableName ) ;
508- const foreignKeysInfo = await this . prismaService . txClient ( ) . $queryRawUnsafe <
509+ const foreignKeysInfo = await prisma . $queryRawUnsafe <
509510 {
510511 constraint_name : string ;
511512 column_name : string ;
@@ -521,6 +522,7 @@ export class BaseDuplicateService {
521522 allForeignKeyInfos . push ( ...newForeignKeyInfos ) ;
522523 }
523524
525+ // 2. drop foreign keys
524526 for ( const { constraint_name, column_name, dbTableName } of allForeignKeyInfos ) {
525527 const dropForeignKeyQuery = this . knex . schema
526528 . alterTable ( dbTableName , ( table ) => {
@@ -531,6 +533,7 @@ export class BaseDuplicateService {
531533 await prisma . $executeRawUnsafe ( dropForeignKeyQuery ) ;
532534 }
533535
536+ // 3. duplicate table data
534537 for ( const tableId of oldTableId ) {
535538 const newTableId = tableIdMap [ tableId ] ;
536539 const oldDbTableName = tableId2DbTableNameMap [ tableId ] ;
@@ -544,6 +547,7 @@ export class BaseDuplicateService {
544547 ) ;
545548 }
546549
550+ // 4. repair foreign keys
547551 for ( const {
548552 constraint_name : constraintName ,
549553 column_name : columnName ,
0 commit comments