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

Commit a73e3b74 by Mick Hansen

Merge pull request #3675 from mikrofusion/master

fix addIndexQuery when an object is provided as the tableName
2 parents 3dd94d84 0c43f919
# Next
- [BUG] Fix addIndexQuery error when the model has a schema
# 2.1.3
- [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
- [BUG] Fix managed transactions not rolling back if no thenable was provided in the transaction block [3667](https://github.com/sequelize/sequelize/pull/3667)
......
......@@ -479,7 +479,7 @@ module.exports = (function() {
}
options.prefix = options.prefix || rawTablename || tableName;
if (options.prefix) {
if (options.prefix && _.isString(options.prefix)) {
options.prefix = options.prefix.replace(/\./g, '_');
options.prefix = options.prefix.replace(/(\"|\')/g, '');
}
......@@ -542,6 +542,12 @@ module.exports = (function() {
options.where = this.whereQuery(options.where);
}
if (_.isString(tableName)) {
tableName = this.quoteIdentifiers(tableName);
} else {
tableName = this.quoteTable(tableName);
}
return Utils._.compact([
'CREATE',
options.unique ? 'UNIQUE' : '',
......@@ -549,7 +555,7 @@ module.exports = (function() {
this._dialect.supports.index.concurrently && options.concurrently ? 'CONCURRENTLY' : undefined,
this.quoteIdentifiers(options.name),
this._dialect.supports.index.using === 1 && options.using ? 'USING ' + options.using : '',
'ON', this.quoteIdentifiers(tableName),
'ON', tableName,
this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '',
'(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')',
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined),
......
......@@ -20,6 +20,13 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
});
expectsql(sql.addIndexQuery({
schema: 'schema',
tableName: 'table'
}, ['column1', 'column2'], {}, 'schema_table'), {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
});
expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({
schema: 'schema',
tableName: 'table'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!