Skip to content

Commit

Permalink
Make mysql work for databases that are not all lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hutchins committed Feb 28, 2017
1 parent 06199ac commit 32f9f83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/database-cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var DatabaseCleaner = module.exports = function(type, config) {

var count = 0;
var length = tables.length;
var tableName = 'Tables_in_' + database;
var tableName = 'Tables_in_' + database.toLowerCase();
var skippedTables = config.mysql.skipTables;
var strategy = config.mysql.strategy || 'deletion';
if (strategy !== 'deletion' && strategy !== 'truncation') {
Expand Down
21 changes: 9 additions & 12 deletions test/mysql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ var should = require('should'),
async = require('async'),
databaseCleaner;

var config = {
host: process.env.MYSQL_HOST || 'localhost',
user: 'root',
database: 'database_cleaner'
}
var mysql = require('mysql'),
client = new mysql.createConnection({
host: process.env.MYSQL_HOST || 'localhost',
user: 'root',
database: 'database_cleaner'
}),
pool = new mysql.createPool({
host: process.env.MYSQL_HOST || 'localhost',
user: 'root',
database: 'database_cleaner'
});
client = new mysql.createConnection(config),
pool = new mysql.createPool(config);

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

describe('mysql', function() {
beforeEach(function(done) {
client.query('CREATE DATABASE database_cleaner', function(err) {
client.query('CREATE DATABASE ' + config.database, function(err) {
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
}
Expand Down Expand Up @@ -145,7 +142,7 @@ describe('mysql', function() {

describe('mysql empty', function() {
beforeEach(function(done) {
client.query('CREATE DATABASE database_cleaner', function(err) {
client.query('CREATE DATABASE ' + config.database, function(err) {
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
}
Expand Down

0 comments on commit 32f9f83

Please sign in to comment.