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

Commit 37e6e63f by Sushant Committed by Mick Hansen

Fix #5888, properly quote index when removing (#6221)

* properly quote index when removing

* quote index name for MSSQL
1 parent dc9741ef
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
- [CHANGED] `Sequelize.Validator` is now an independent copy of `validator` library - [CHANGED] `Sequelize.Validator` is now an independent copy of `validator` library
- [FIXED] Don't patch `validator` library globally [#6196](https://github.com/sequelize/sequelize/issues/6196) - [FIXED] Don't patch `validator` library globally [#6196](https://github.com/sequelize/sequelize/issues/6196)
- [CHANGED] `ignore` for create was renamed to `ignoreDuplicates` [#6138](https://github.com/sequelize/sequelize/issues/6138) - [CHANGED] `ignore` for create was renamed to `ignoreDuplicates` [#6138](https://github.com/sequelize/sequelize/issues/6138)
- [FIXED] Index names not quoted properly in `removeIndex` [#5888](https://github.com/sequelize/sequelize/issues/5888)
## BC breaks: ## BC breaks:
- Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive) - Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive)
......
...@@ -350,7 +350,7 @@ var QueryGenerator = { ...@@ -350,7 +350,7 @@ var QueryGenerator = {
var values = { var values = {
tableName: this.quoteIdentifiers(tableName), tableName: this.quoteIdentifiers(tableName),
indexName: indexName indexName: this.quoteIdentifiers(indexName)
}; };
return Utils._.template(sql)(values); return Utils._.template(sql)(values);
......
...@@ -195,7 +195,7 @@ const QueryGenerator = { ...@@ -195,7 +195,7 @@ const QueryGenerator = {
indexName = Utils.underscore(tableName + '_' + indexNameOrAttributes.join('_')); indexName = Utils.underscore(tableName + '_' + indexNameOrAttributes.join('_'));
} }
return `DROP INDEX ${indexName} ON ${this.quoteTable(tableName)}`; return `DROP INDEX ${this.quoteIdentifier(indexName)} ON ${this.quoteTable(tableName)}`;
}, },
attributeToSQL(attribute, options) { attributeToSQL(attribute, options) {
......
...@@ -232,7 +232,7 @@ const QueryGenerator = { ...@@ -232,7 +232,7 @@ const QueryGenerator = {
indexName = Utils.underscore(tableName + '_' + indexNameOrAttributes.join('_')); indexName = Utils.underscore(tableName + '_' + indexNameOrAttributes.join('_'));
} }
return 'DROP INDEX IF EXISTS ' + indexName; return `DROP INDEX IF EXISTS ${this.quoteIdentifier(indexName)}`;
}, },
describeTableQuery(tableName, schema, schemaDelimiter) { describeTableQuery(tableName, schema, schemaDelimiter) {
......
...@@ -521,10 +521,10 @@ if (dialect === 'mysql') { ...@@ -521,10 +521,10 @@ if (dialect === 'mysql') {
removeIndexQuery: [ removeIndexQuery: [
{ {
arguments: ['User', 'user_foo_bar'], arguments: ['User', 'user_foo_bar'],
expectation: 'DROP INDEX user_foo_bar ON `User`' expectation: 'DROP INDEX `user_foo_bar` ON `User`'
}, { }, {
arguments: ['User', ['foo', 'bar']], arguments: ['User', ['foo', 'bar']],
expectation: 'DROP INDEX user_foo_bar ON `User`' expectation: 'DROP INDEX `user_foo_bar` ON `User`'
} }
] ]
}; };
......
...@@ -147,4 +147,14 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -147,4 +147,14 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}); });
} }
}); });
suite('removeIndex', function () {
test('naming', function () {
expectsql(sql.removeIndexQuery('table', ['column1', 'column2'], {}, 'table'), {
mysql: 'DROP INDEX `table_column1_column2` ON `table`',
mssql: 'DROP INDEX [table_column1_column2] ON [table]',
default: 'DROP INDEX IF EXISTS [table_column1_column2]'
});
});
});
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!