@@ -47,45 +47,50 @@ var DatabaseCleaner = module.exports = function(type, config) {
4747 } ;
4848
4949 cleaner [ 'mysql' ] = function ( db , callback ) {
50- db . query ( 'show tables' , function ( err , tables ) {
51- if ( err ) return callback ( err ) ;
50+ db . query ( 'show global variables like "lower_case_table_names"' , function ( err , values ) {
5251
53- var database = db . config . connectionConfig ?
54- db . config . connectionConfig . database : db . config . database ;
52+ var lowerCaseTableNames = values [ 0 ] [ 'Value' ] === 2 ;
5553
56- var count = 0 ;
57- var length = tables . length ;
58- var tableName = 'Tables_in_' + database ;
59- var skippedTables = config . mysql . skipTables ;
60- var strategy = config . mysql . strategy || 'deletion' ;
61- if ( strategy !== 'deletion' && strategy !== 'truncation' ) {
62- return callback ( new Error ( 'Invalid deletion strategy: ' + strategy ) ) ;
63- }
54+ db . query ( 'show tables' , function ( err , tables ) {
55+ if ( err ) return callback ( err ) ;
6456
65- if ( length === 0 ) {
66- // The database is empty
67- return callback ( ) ;
68- }
57+ var database = db . config . connectionConfig ?
58+ db . config . connectionConfig . database : db . config . database ;
6959
70- tables . forEach ( function ( table ) {
71- if ( skippedTables . indexOf ( table [ tableName ] ) === - 1 ) {
72- var statement = strategy === 'deletion' ? 'DELETE FROM ' : 'TRUNCATE TABLE '
73- db . query ( statement + table [ tableName ] , function ( err ) {
74- if ( err ) {
75- return callback ( err ) ;
76- }
60+ var count = 0 ;
61+ var length = tables . length ;
62+ var tableName = 'Tables_in_' + ( lowerCaseTableNames ? database . toLowerCase ( ) : database ) ;
63+ var skippedTables = config . mysql . skipTables ;
64+ var strategy = config . mysql . strategy || 'deletion' ;
65+ if ( strategy !== 'deletion' && strategy !== 'truncation' ) {
66+ return callback ( new Error ( 'Invalid deletion strategy: ' + strategy ) ) ;
67+ }
68+
69+ if ( length === 0 ) {
70+ // The database is empty
71+ return callback ( ) ;
72+ }
73+
74+ tables . forEach ( function ( table ) {
75+ if ( skippedTables . indexOf ( table [ tableName ] ) === - 1 ) {
76+ var statement = strategy === 'deletion' ? 'DELETE FROM ' : 'TRUNCATE TABLE '
77+ db . query ( statement + table [ tableName ] , function ( err ) {
78+ if ( err ) {
79+ return callback ( err ) ;
80+ }
7781
82+ count ++ ;
83+ if ( count >= length ) {
84+ callback ( ) ;
85+ }
86+ } ) ;
87+ } else {
7888 count ++ ;
7989 if ( count >= length ) {
8090 callback ( ) ;
8191 }
82- } ) ;
83- } else {
84- count ++ ;
85- if ( count >= length ) {
86- callback ( ) ;
8792 }
88- }
93+ } ) ;
8994 } ) ;
9095 } ) ;
9196 } ;
0 commit comments