@@ -235,9 +235,11 @@ class MySQLCassette {
235235 if ( options && options . clean ) {
236236 try {
237237 let tables = await conn . raw ( "SHOW TABLES" ) ;
238+ await conn . raw ( "SET foreign_key_checks = 0" ) ;
238239 for ( let table of tables [ 0 ] ) {
239- await conn . raw ( `DROP TABLE IF EXISTS ${ table . Tables_in_track } CASCADE ` ) ;
240+ await conn . raw ( `DROP TABLE IF EXISTS ${ table . Tables_in_track } ` ) ;
240241 }
242+ await conn . raw ( "SET foreign_key_checks = 1" ) ;
241243 } catch ( e2 ) { console . error ( e2 ) ; }
242244 }
243245 return conn ;
@@ -267,21 +269,22 @@ class MySQLCassette {
267269 ` ;
268270 }
269271 updateAutoIncrementSql ( table , column ) {
270- return `ALTER TABLE ${ table } AUTO_INCREMENT = ? + 1 ` ;
272+ return `ALTER TABLE ${ table } AUTO_INCREMENT = ?` ;
271273 }
272274 lastValueSql ( table , idCol ) {
273275 return `SELECT * FROM ${ table } WHERE ${ idCol } = LAST_INSERT_ID()` ;
274276 }
275277 async listFk ( table , conn ) {
276278 return await conn . query ( `
277279 SELECT
278- kcu.column_name AS column,
279- ccu.table_name AS foreign_table,
280- ccu.column_name AS foreign_column
281- FROM information_schema.table_constraints AS tc
282- INNER JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
283- INNER JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
284- WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = '${ table } '
280+ COLUMN_NAME AS \`column\`,
281+ REFERENCED_TABLE_NAME AS foreign_table,
282+ REFERENCED_COLUMN_NAME AS foreign_column
283+ FROM information_schema.KEY_COLUMN_USAGE
284+ WHERE
285+ TABLE_SCHEMA = DATABASE()
286+ AND TABLE_NAME = '${ table } '
287+ AND REFERENCED_TABLE_NAME IS NOT NULL
285288 ` ) ;
286289 }
287290 errorOf ( e ) {
@@ -591,6 +594,9 @@ class Connection {
591594
592595 async updateAutoIncrement ( table , column , count ) {
593596 const sql = this . _cassette . updateAutoIncrementSql ( table , column ) ;
597+ if ( this . _cassette instanceof MySQLCassette ) {
598+ count = ( count || 0 ) + 1 ;
599+ }
594600 return await this . query ( sql , [ count ] ) ;
595601 }
596602
0 commit comments