@@ -74,26 +74,28 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
7474 } ) ) ;
7575 }
7676
77+ private async hasPgCascadeFk ( tableName : string ) : Promise < void > {
78+ const [ fkResults ] = await this . client . execute (
79+ `
80+ SELECT
81+ TABLE_NAME AS child_table,
82+ CONSTRAINT_NAME
83+ FROM information_schema.REFERENTIAL_CONSTRAINTS
84+ WHERE CONSTRAINT_SCHEMA = DATABASE()
85+ AND REFERENCED_TABLE_NAME = ?
86+ AND DELETE_RULE = 'CASCADE'
87+ ` ,
88+ [ tableName ]
89+ ) ;
90+
91+ for ( const fk of fkResults as any [ ] ) {
92+ afLogger . warn ( `The database has ON DELETE CASCADE, which may conflict with adminForth cascade deletion and upload logic. Please remove it.` ) ;
93+ }
94+ }
95+
7796 async discoverFields ( resource ) {
7897 const [ results ] = await this . client . execute ( "SHOW COLUMNS FROM " + resource . table ) ;
79- const [ fkResults ] = await this . client . execute ( `
80- SELECT
81- kcu.COLUMN_NAME,
82- kcu.TABLE_NAME AS child_table,
83- rc.DELETE_RULE
84- FROM information_schema.KEY_COLUMN_USAGE AS kcu
85- JOIN information_schema.REFERENTIAL_CONSTRAINTS AS rc
86- ON kcu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
87- AND kcu.CONSTRAINT_SCHEMA = rc.CONSTRAINT_SCHEMA
88- WHERE kcu.REFERENCED_TABLE_NAME = ?
89- AND kcu.TABLE_SCHEMA = DATABASE()
90- ` , [ resource . table ] ) ;
91-
92- for ( const fk of fkResults as any [ ] ) {
93- if ( fk . DELETE_RULE ?. toUpperCase ( ) === 'CASCADE' ) {
94- afLogger . warn ( `The database has ON DELETE CASCADE, which may conflict with adminForth cascade deletion and upload logic. Please remove it.` ) ;
95- }
96- }
98+ await this . hasPgCascadeFk ( resource . table ) ;
9799 const fieldTypes = { } ;
98100 results . forEach ( ( row ) => {
99101 const field : any = { } ;
0 commit comments