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

Commit 11d4a209 by Paul Mowat Committed by Sushant

feat(postgres): drop enum support (#9641)

1 parent 37145bc9
......@@ -293,6 +293,27 @@ class QueryInterface {
}
/**
* Drop specified enum from database, Postgres Only
* @param {String} [enumName] Enum name to drop
* @param {Object} options Query options
*
* @return {Promise}
* @private
*/
dropEnum(enumName, options) {
if (this.sequelize.getDialect() !== 'postgres') {
return Promise.resolve();
}
options = options || {};
return this.sequelize.query(
this.QueryGenerator.pgEnumDrop(null, null, this.QueryGenerator.pgEscapeAndQuote(enumName)),
_.assign({}, options, { raw: true })
);
}
/**
* Drop all enums from database, Postgres Only
*
* @param {Object} options Query options
......
'use strict';
const chai = require('chai');
const expect = chai.expect;
const Support = require(__dirname + '/../support');
const DataTypes = require(__dirname + '/../../../lib/data-types');
const dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('QueryInterface'), () => {
beforeEach(function() {
this.sequelize.options.quoteIdenifiers = true;
this.queryInterface = this.sequelize.getQueryInterface();
});
afterEach(function() {
return this.sequelize.dropAllSchemas();
});
describe('dropEnum', () => {
beforeEach(function() {
return this.queryInterface.createTable('menus', {
structuretype: {
type: DataTypes.ENUM('menus', 'submenu', 'routine'),
allowNull: true
},
sequence: {
type: DataTypes.INTEGER,
allowNull: true
},
name: {
type: DataTypes.STRING,
allowNull: true
}
});
});
if (dialect === 'postgres') {
it('should be able to drop the specified enum', function() {
return this.queryInterface.removeColumn('menus', 'structuretype').bind(this).then(function() {
return this.queryInterface.pgListEnums('menus');
}).then(enumList => {
expect(enumList).to.have.lengthOf(1);
expect(enumList[0]).to.have.property('enum_name').and.to.equal('enum_menus_structuretype');
}).then(() => {
return this.queryInterface.dropEnum('enum_menus_structuretype');
}).then(() => {
return this.queryInterface.pgListEnums('menus');
}).then(enumList => {
expect(enumList).to.be.an('array');
expect(enumList).to.have.lengthOf(0);
});
});
}
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!