Skip to content

Commit 32f9f83

Browse files
author
Eric Hutchins
committed
Make mysql work for databases that are not all lowercase
1 parent 06199ac commit 32f9f83

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

lib/database-cleaner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var DatabaseCleaner = module.exports = function(type, config) {
5555

5656
var count = 0;
5757
var length = tables.length;
58-
var tableName = 'Tables_in_' + database;
58+
var tableName = 'Tables_in_' + database.toLowerCase();
5959
var skippedTables = config.mysql.skipTables;
6060
var strategy = config.mysql.strategy || 'deletion';
6161
if (strategy !== 'deletion' && strategy !== 'truncation') {

test/mysql.test.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ var should = require('should'),
44
async = require('async'),
55
databaseCleaner;
66

7+
var config = {
8+
host: process.env.MYSQL_HOST || 'localhost',
9+
user: 'root',
10+
database: 'database_cleaner'
11+
}
712
var mysql = require('mysql'),
8-
client = new mysql.createConnection({
9-
host: process.env.MYSQL_HOST || 'localhost',
10-
user: 'root',
11-
database: 'database_cleaner'
12-
}),
13-
pool = new mysql.createPool({
14-
host: process.env.MYSQL_HOST || 'localhost',
15-
user: 'root',
16-
database: 'database_cleaner'
17-
});
13+
client = new mysql.createConnection(config),
14+
pool = new mysql.createPool(config);
1815

1916
var queryClient = _.curry(function(query, values, next) {
2017
client.query(query, values, next);
2118
});
2219

2320
describe('mysql', function() {
2421
beforeEach(function(done) {
25-
client.query('CREATE DATABASE database_cleaner', function(err) {
22+
client.query('CREATE DATABASE ' + config.database, function(err) {
2623
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
2724
throw err;
2825
}
@@ -145,7 +142,7 @@ describe('mysql', function() {
145142

146143
describe('mysql empty', function() {
147144
beforeEach(function(done) {
148-
client.query('CREATE DATABASE database_cleaner', function(err) {
145+
client.query('CREATE DATABASE ' + config.database, function(err) {
149146
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
150147
throw err;
151148
}

0 commit comments

Comments
 (0)