MCPcopy Index your code
hub / github.com/sequelize/sequelize / renameColumn

Method renameColumn

src/dialects/abstract/query-interface.js:526–550  ·  view source on GitHub ↗

* Rename a column * * @param {string} tableName Table name whose column to rename * @param {string} attrNameBefore Current column name * @param {string} attrNameAfter New column name * @param {object} [options] Query option * * @returns {Promise}

(tableName, attrNameBefore, attrNameAfter, options)

Source from the content-addressed store, hash-verified

524 * @returns {Promise}
525 */
526 async renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
527 options = options || {};
528 const data = (await this.assertTableHasColumn(tableName, attrNameBefore, options))[attrNameBefore];
529
530 const _options = {};
531
532 _options[attrNameAfter] = {
533 attribute: attrNameAfter,
534 type: data.type,
535 allowNull: data.allowNull,
536 defaultValue: data.defaultValue
537 };
538
539 // fix: a not-null column cannot have null as default value
540 if (data.defaultValue === null && !data.allowNull) {
541 delete _options[attrNameAfter].defaultValue;
542 }
543
544 const sql = this.queryGenerator.renameColumnQuery(
545 tableName,
546 attrNameBefore,
547 this.queryGenerator.attributesToSQL(_options)
548 );
549 return await this.sequelize.query(sql, options);
550 }
551
552 /**
553 * Add an index to a column

Callers 3

testFunction · 0.45

Calls 4

assertTableHasColumnMethod · 0.95
renameColumnQueryMethod · 0.45
attributesToSQLMethod · 0.45
queryMethod · 0.45

Tested by 1

testFunction · 0.36