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

Commit 18dcc7ee by Sushant Committed by GitHub

fix(postgres): addColumn support ARRAY(ENUM) (#12259)

1 parent 461c9242
......@@ -244,17 +244,19 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return super.handleSequelizeMethod.call(this, smth, tableName, factory, options, prepend);
}
addColumnQuery(table, key, dataType) {
const dbDataType = this.attributeToSQL(dataType, { context: 'addColumn', table, key });
addColumnQuery(table, key, attribute) {
const dbDataType = this.attributeToSQL(attribute, { context: 'addColumn', table, key });
const dataType = attribute.type || attribute;
const definition = this.dataTypeMapping(table, key, dbDataType);
const quotedKey = this.quoteIdentifier(key);
const quotedTable = this.quoteTable(this.extractTableDetails(table));
let query = `ALTER TABLE ${quotedTable} ADD COLUMN ${quotedKey} ${definition};`;
if (dataType.type && dataType.type instanceof DataTypes.ENUM || dataType instanceof DataTypes.ENUM) {
if (dataType instanceof DataTypes.ENUM) {
query = this.pgEnum(table, key, dataType) + query;
} else if (dataType.type && dataType.type instanceof DataTypes.ENUM) {
query = this.pgEnum(table, key, dataType.type) + query;
}
return query;
......
......@@ -380,6 +380,23 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
values: ['value1', 'value2', 'value3']
});
});
if (dialect === 'postgres') {
it('should be able to add a column of type of array of enums', async function() {
await this.queryInterface.addColumn('users', 'tags', {
allowNull: false,
type: Sequelize.ARRAY(Sequelize.ENUM(
'Value1',
'Value2',
'Value3'
))
});
const result = await this.queryInterface.describeTable('users');
expect(result).to.have.property('tags');
expect(result.tags.type).to.equal('ARRAY');
expect(result.tags.allowNull).to.be.false;
});
}
});
describe('describeForeignKeys', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!