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

Commit 24160754 by Nuno Sousa Committed by Sushant

Fix `showIndex()` query regexp (#7492)

* Fix `showIndex()` query regexp

* [ci skip] changelog for #7492
1 parent 6730bc00
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
- [FIXED] Model.validate runs validation hooks by default [#7182](https://github.com/sequelize/sequelize/pull/7182) - [FIXED] Model.validate runs validation hooks by default [#7182](https://github.com/sequelize/sequelize/pull/7182)
- [ADDED] Added support for associations aliases in orders and groups. [#7425](https://github.com/sequelize/sequelize/issues/7425) - [ADDED] Added support for associations aliases in orders and groups. [#7425](https://github.com/sequelize/sequelize/issues/7425)
- [REMOVED] Removes support for `{raw: 'injection goes here'}` for order and group. [#7188](https://github.com/sequelize/sequelize/issues/7188) - [REMOVED] Removes support for `{raw: 'injection goes here'}` for order and group. [#7188](https://github.com/sequelize/sequelize/issues/7188)
- [FIXED] `showIndex` breaks with newline characters [#7492](https://github.com/sequelize/sequelize/pull/7492)
## BC breaks: ## BC breaks:
- Model.validate instance method now runs validation hooks by default. Previously you needed to pass { hooks: true }. You can override this behavior by passing { hooks: false } - Model.validate instance method now runs validation hooks by default. Previously you needed to pass { hooks: true }. You can override this behavior by passing { hooks: false }
......
...@@ -137,7 +137,7 @@ class Query extends AbstractQuery { ...@@ -137,7 +137,7 @@ class Query extends AbstractQuery {
if (this.isShowIndexesQuery()) { if (this.isShowIndexesQuery()) {
for (const result of results) { for (const result of results) {
const attributes = /ON .*? (?:USING .*?\s)?\((.*)\)/gi.exec(result.definition)[1].split(','); const attributes = /ON .*? (?:USING .*?\s)?\(([^]*)\)/gi.exec(result.definition)[1].split(',');
// Map column index in table to column name // Map column index in table to column name
const columns = _.zipObject( const columns = _.zipObject(
......
...@@ -205,6 +205,21 @@ if (dialect.match(/^postgres/)) { ...@@ -205,6 +205,21 @@ if (dialect.match(/^postgres/)) {
})); }));
}); });
it('supports newlines', function() {
return this.queryInterface.addIndex('Group', [this.sequelize.literal(`(
CASE "username"
WHEN 'foo' THEN 'bar'
ELSE 'baz'
END
)`)], { name: 'group_username_case' })
.then(() => this.queryInterface.showIndex('Group'))
.then(indexes => {
const indexColumns = _.uniq(indexes.map(index => index.name));
expect(indexColumns).to.include('group_username_case');
});
});
it('adds, reads and removes a named functional index to the table', function() { it('adds, reads and removes a named functional index to the table', function() {
return this.queryInterface.addIndex('Group', [this.sequelize.fn('lower', this.sequelize.col('username'))], { return this.queryInterface.addIndex('Group', [this.sequelize.fn('lower', this.sequelize.col('username'))], {
name: 'group_username_lower' name: 'group_username_lower'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!