* Add an index to a column * * @param {string|object} tableName Table name to add index on, can be a object with schema * @param {Array} [attributes] Use options.fields instead, List of attributes to add index on * @param {object} options indexes options * @param {Arr
(tableName, attributes, options, rawTablename)
| 568 | * @returns {Promise} |
| 569 | */ |
| 570 | async addIndex(tableName, attributes, options, rawTablename) { |
| 571 | // Support for passing tableName, attributes, options or tableName, options (with a fields param which is the attributes) |
| 572 | if (!Array.isArray(attributes)) { |
| 573 | rawTablename = options; |
| 574 | options = attributes; |
| 575 | attributes = options.fields; |
| 576 | } |
| 577 | |
| 578 | if (!rawTablename) { |
| 579 | // Map for backwards compat |
| 580 | rawTablename = tableName; |
| 581 | } |
| 582 | |
| 583 | options = Utils.cloneDeep(options); |
| 584 | options.fields = attributes; |
| 585 | const sql = this.queryGenerator.addIndexQuery(tableName, options, rawTablename); |
| 586 | return await this.sequelize.query(sql, { ...options, supportsSearchPath: false }); |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Show indexes on a table |