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

Commit e41590af by Satana Charuwichitratana Committed by Sushant

feat(mysql/addColumn): supports FIRST keyword (#7943)

1 parent 1e0d9a86
......@@ -207,6 +207,30 @@ queryInterface.addColumn(
}
)
// or with first attribute to put the column at the beginning of the table
// currently supports only in MySQL
queryInterface.addColumn(
'nameOfAnExistingTable',
'nameOfTheNewAttribute',
{
type: Sequelize.STRING,
first: true
}
)
// or with after attribute to put the column after a specific column
// currently supports only in MySQL
queryInterface.addColumn(
'nameOfAnExistingTable',
'nameOfTheNewAttribute',
{
type: Sequelize.STRING,
after: 'nameOfAnExistingColumn'
}
)
// or with an explicit schema:
queryInterface.addColumn({
......
......@@ -104,6 +104,7 @@ const QueryGenerator = {
tableName: table,
foreignKey: key
});
return `ALTER TABLE ${this.quoteTable(table)} ADD ${this.quoteIdentifier(key)} ${definition};`;
},
......@@ -251,6 +252,9 @@ const QueryGenerator = {
template += ' PRIMARY KEY';
}
if (attribute.first) {
template += ' FIRST';
}
if (attribute.after) {
template += ' AFTER ' + this.quoteIdentifier(attribute.after);
}
......
......@@ -42,6 +42,14 @@ if (current.dialect.name === 'mysql') {
});
});
it('properly generate alter queries with FIRST', () => {
return expectsql(sql.addColumnQuery(Model.getTableName(), 'test_added_col_first', current.normalizeAttribute({
type: DataTypes.STRING,
first: true
})), {
mysql: 'ALTER TABLE `users` ADD `test_added_col_first` VARCHAR(255) FIRST;'
});
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!