* 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)
| 546 | * @returns {Promise} |
| 547 | */ |
| 548 | async addIndex(tableName, attributes, options, rawTablename) { |
| 549 | class="cm">// Support for passing tableName, attributes, options or tableName, options (with a fields param which is the attributes) |
| 550 | if (!Array.isArray(attributes)) { |
| 551 | rawTablename = options; |
| 552 | options = attributes; |
| 553 | attributes = options.fields; |
| 554 | } |
| 555 | |
| 556 | if (!rawTablename) { |
| 557 | class="cm">// Map for backwards compat |
| 558 | rawTablename = tableName; |
| 559 | } |
| 560 | |
| 561 | options = Utils.cloneDeep(options); |
| 562 | options.fields = attributes; |
| 563 | const sql = this.queryGenerator.addIndexQuery(tableName, options, rawTablename); |
| 564 | return await this.sequelize.query(sql, { ...options, supportsSearchPath: false }); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Show indexes on a table |