MCPcopy
hub / github.com/sequelize/sequelize / renameColumn

Method renameColumn

lib/dialects/abstract/query-interface.js:504–528  ·  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

502 * @returns {Promise}
503 */
504 async renameColumn(tableName, attrNameBefore, attrNameAfter, options) {
505 options = options || {};
506 const data = (await this.assertTableHasColumn(tableName, attrNameBefore, options))[attrNameBefore];
507
508 const _options = {};
509
510 _options[attrNameAfter] = {
511 attribute: attrNameAfter,
512 type: data.type,
513 allowNull: data.allowNull,
514 defaultValue: data.defaultValue
515 };
516
517 // fix: a not-null column cannot have null as default value
518 if (data.defaultValue === null && !data.allowNull) {
519 delete _options[attrNameAfter].defaultValue;
520 }
521
522 const sql = this.queryGenerator.renameColumnQuery(
523 tableName,
524 attrNameBefore,
525 this.queryGenerator.attributesToSQL(_options)
526 );
527 return await this.sequelize.query(sql, options);
528 }
529
530 /**
531 * 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