不要怂,就是干,撸起袖子干!

Commit 5dda5428 by Chris Coggburn Committed by Sushant

Fixes #6824 Add ROW_FORMAT support to mysql query-generator (#6825)

* Add ROW_FORMAT support to mysql query-generator

InnoDB's new Barracuda file format offers 2 new types of row formats
which offer significant improvements if working with utf8mb4 collation
by supporting index key prefixes up to 3072 bytes instead of the
default of 767 bytes offered with COMPACT or REDUNDANT row types
offered in the legacy Antelope file format.

This commit adds `ROW_FORMAT` support to the query-generator for
the mysql dialect by adding `options.format` for sequelize.define().

* Add tests for overrides global format option and inherits global format option

* Fix row-format test to use correct assert

* Add explicit test for options.format to SQL ROW_FORMAT

* Fix incorrect assert causing failing tests on row_format for options.format

* Correct changelog issue/hash to point to the same place.

* Rename options.format to options.rowFormat

* Fix missed format to rowFormat variable name
1 parent 7029d2d6
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
- [FIXED] groupedLimit.through.where support - [FIXED] groupedLimit.through.where support
- [ADDED] `option.silent` for increment and decrement [#6795](https://github.com/sequelize/sequelize/pull/6795) - [ADDED] `option.silent` for increment and decrement [#6795](https://github.com/sequelize/sequelize/pull/6795)
- [CHANGED] `now` function allow milliseconds in timestamps on mysql [#6441](https://github.com/sequelize/sequelize/issues/6441) - [CHANGED] `now` function allow milliseconds in timestamps on mysql [#6441](https://github.com/sequelize/sequelize/issues/6441)
- [ADDED] `options.rowFormat` added to Query Generator for MySQL dialect using InnoDB engines [#6824] (https://github.com/sequelize/sequelize/issues/6824)
## BC breaks: ## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type - `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
......
...@@ -547,6 +547,7 @@ For more about validation, see [Validations](http://docs.sequelizejs.com/en/late ...@@ -547,6 +547,7 @@ For more about validation, see [Validations](http://docs.sequelizejs.com/en/late
| [options.charset] | String | | | [options.charset] | String | |
| [options.comment] | String | | | [options.comment] | String | |
| [options.collate] | String | | | [options.collate] | String | |
| [options.rowFormat] | String | Specify the ROW_FORMAT for use with the MySQL InnoDB engine. |
| [options.initialAutoIncrement] | String | Set the initial AUTO_INCREMENT value for the table in MySQL. | | [options.initialAutoIncrement] | String | Set the initial AUTO_INCREMENT value for the table in MySQL. |
| [options.hooks] | Object | An object of hook function that are called before and after certain lifecycle events. The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook functions and their signatures. Each property can either be a function, or an array of functions. | | [options.hooks] | Object | An object of hook function that are called before and after certain lifecycle events. The possible hooks are: beforeValidate, afterValidate, beforeBulkCreate, beforeBulkDestroy, beforeBulkUpdate, beforeCreate, beforeDestroy, beforeUpdate, afterCreate, afterDestroy, afterUpdate, afterBulkCreate, afterBulkDestory and afterBulkUpdate. See Hooks for more information about hook functions and their signatures. Each property can either be a function, or an array of functions. |
| [options.validate] | Object | An object of model wide validations. Validations have access to all model values via `this`. If the validator function takes an argument, it is assumed to be async, and is called with a callback that accepts an optional error. | | [options.validate] | Object | An object of model wide validations. Validations have access to all model values via `this`. If the validator function takes an argument, it is assumed to be async, and is called with a callback that accepts an optional error. |
......
...@@ -23,10 +23,11 @@ const QueryGenerator = { ...@@ -23,10 +23,11 @@ const QueryGenerator = {
createTableQuery(tableName, attributes, options) { createTableQuery(tableName, attributes, options) {
options = Utils._.extend({ options = Utils._.extend({
engine: 'InnoDB', engine: 'InnoDB',
charset: null charset: null,
rowFormat: null
}, options || {}); }, options || {});
const query = 'CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>) ENGINE=<%= engine %><%= comment %><%= charset %><%= collation %><%= initialAutoIncrement %>'; const query = 'CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>) ENGINE=<%= engine %><%= comment %><%= charset %><%= collation %><%= initialAutoIncrement %><%= rowFormat %>';
const primaryKeys = []; const primaryKeys = [];
const foreignKeys = {}; const foreignKeys = {};
const attrStr = []; const attrStr = [];
...@@ -65,6 +66,7 @@ const QueryGenerator = { ...@@ -65,6 +66,7 @@ const QueryGenerator = {
engine: options.engine, engine: options.engine,
charset: (options.charset ? ' DEFAULT CHARSET=' + options.charset : ''), charset: (options.charset ? ' DEFAULT CHARSET=' + options.charset : ''),
collation: (options.collate ? ' COLLATE ' + options.collate : ''), collation: (options.collate ? ' COLLATE ' + options.collate : ''),
rowFormat: options.rowFormat ? ' ROW_FORMAT=' + options.rowFormat : '',
initialAutoIncrement: (options.initialAutoIncrement ? ' AUTO_INCREMENT=' + options.initialAutoIncrement : '') initialAutoIncrement: (options.initialAutoIncrement ? ' AUTO_INCREMENT=' + options.initialAutoIncrement : '')
}; };
const pkString = primaryKeys.map(pk => this.quoteIdentifier(pk)).join(', '); const pkString = primaryKeys.map(pk => this.quoteIdentifier(pk)).join(', ');
......
...@@ -924,12 +924,24 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() { ...@@ -924,12 +924,24 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
expect(DAO.options.collate).to.equal('utf8_bin'); expect(DAO.options.collate).to.equal('utf8_bin');
}); });
it('overwrites global rowFormat options', function() {
var sequelize = Support.createSequelizeInstance({ define: { rowFormat: 'compact' } });
var DAO = sequelize.define('foo', {bar: DataTypes.STRING}, { rowFormat: 'default' });
expect(DAO.options.rowFormat).to.equal('default');
});
it('inherits global collate option', function() { it('inherits global collate option', function() {
var sequelize = Support.createSequelizeInstance({ define: { collate: 'utf8_general_ci' } }); var sequelize = Support.createSequelizeInstance({ define: { collate: 'utf8_general_ci' } });
var DAO = sequelize.define('foo', {bar: DataTypes.STRING}); var DAO = sequelize.define('foo', {bar: DataTypes.STRING});
expect(DAO.options.collate).to.equal('utf8_general_ci'); expect(DAO.options.collate).to.equal('utf8_general_ci');
}); });
it('inherits global rowFormat option', function() {
var sequelize = Support.createSequelizeInstance({ define: { rowFormat: 'default' } });
var DAO = sequelize.define('foo', {bar: DataTypes.STRING});
expect(DAO.options.rowFormat).to.equal('default');
});
it('uses the passed tableName', function() { it('uses the passed tableName', function() {
var self = this var self = this
, Photo = this.sequelize.define('Foto', { name: DataTypes.STRING }, { tableName: 'photos' }); , Photo = this.sequelize.define('Foto', { name: DataTypes.STRING }, { tableName: 'photos' });
......
...@@ -102,6 +102,10 @@ if (dialect === 'mysql') { ...@@ -102,6 +102,10 @@ if (dialect === 'mysql') {
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`title` ENUM(\"A\", \"B\", \"C\"), `name` VARCHAR(255)) ENGINE=InnoDB DEFAULT CHARSET=latin1;' expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`title` ENUM(\"A\", \"B\", \"C\"), `name` VARCHAR(255)) ENGINE=InnoDB DEFAULT CHARSET=latin1;'
}, },
{ {
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}, { rowFormat: 'default' }],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=InnoDB ROW_FORMAT=default;'
},
{
arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}], arguments: ['myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)', id: 'INTEGER PRIMARY KEY'}],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255), `id` INTEGER , PRIMARY KEY (`id`)) ENGINE=InnoDB;' expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255), `id` INTEGER , PRIMARY KEY (`id`)) ENGINE=InnoDB;'
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!