Skip to content

Commit

Permalink
test: Fix COMPRESSION table option and add tests+coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoltman committed Dec 2, 2016
1 parent 1916ddc commit 78cb795
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,3 @@ Compatible types:
# Roadmap

+ Prepared statements
+ Travis CI tests with MySQL 5.7 (waiting on [this issue](https://github.com/travis-ci/travis-ci/issues/5122))
1 change: 0 additions & 1 deletion jsdoc2md/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,3 @@ Compatible types:
# Roadmap

+ Prepared statements
+ Travis CI tests with MySQL 5.7 (waiting on [this issue](https://github.com/travis-ci/travis-ci/issues/5122))
9 changes: 3 additions & 6 deletions lib/TableDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,10 @@ class TableDefinition {
}

// COMPRESSION
/* istanbul ignore next: Can only test compression with MySQL 5.7 */
if (newSchema.compression && newSchema.compression !== oldSchema.compression) {
operations.push(Operation.create(
Operation.Types.MODIFY_TABLE_OPTIONS,
'ALTER TABLE ' + this._escapedName + ' COMPRESSION=\'' + newSchema.compression + '\''
'ALTER TABLE ' + this._escapedName + ' COMPRESSION=' + this._pool.escape(newSchema.compression)
));
}

Expand Down Expand Up @@ -367,9 +366,8 @@ class TableDefinition {
if (schema.collate) {
sql += ' COLLATE=' + schema.collate;
}
/* istanbul ignore if: Can only test compression with MySQL 5.7 */
if (schema.compression) {
sql += ' COMPRESSION=' + schema.compression;
sql += ' COMPRESSION=' + pool.escape(schema.compression);
}
if (schema.rowFormat) {
sql += ' ROW_FORMAT=' + schema.rowFormat;
Expand Down Expand Up @@ -580,8 +578,7 @@ function sqlToSchema(sql) {
schema.collate = match[1];
}

match = /COMPRESSION=(\w+)/.exec(tableOptions);
/* istanbul ignore if: Can only test compression with MySQL 5.7 */
match = /COMPRESSION='(\w+)'/.exec(tableOptions);
if (match) {
schema.compression = match[1];
}
Expand Down
7 changes: 4 additions & 3 deletions test/integration/MySQLPlus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,13 @@ describe('MySQLPlus', function() {
autoIncrement: 10,
charset: 'ascii',
collate: 'ascii_bin',
compression: 'zlib',
rowFormat: 'REDUNDANT',
};
const optionsTableExpectedSQL =
'CREATE TABLE `options_table` (\n' +
' `id` int(11) DEFAULT NULL\n' +
') ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=ascii COLLATE=ascii_bin ROW_FORMAT=REDUNDANT';
') ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=ascii COLLATE=ascii_bin ROW_FORMAT=REDUNDANT COMPRESSION=\'zlib\'';

const optionsTableMigratedSchema = {
columns: {
Expand All @@ -378,13 +379,13 @@ describe('MySQLPlus', function() {
engine: 'InnoDB',
charset: 'latin1',
collate: 'latin1_bin',
// compression: 'LZ4', // MySQL 5.7 only
compression: 'LZ4',
rowFormat: 'DEFAULT',
};
const optionsTableMigratedExpectedSQL =
'CREATE TABLE `options_table` (\n' +
' `id` int(11) DEFAULT NULL\n' +
') ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin';
') ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin COMPRESSION=\'LZ4\'';

const textTableName = 'text_table';
const textTableSchema = {
Expand Down

0 comments on commit 78cb795

Please sign in to comment.