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

Commit 1ba7f515 by Mick Hansen

Merge pull request #1990 from seegno/fix-change-column-for-enums

Fix change column migration for enums on Postgres
2 parents d934bbaa 22d12aa6
......@@ -215,6 +215,7 @@ module.exports = (function() {
if (definition.match(/^ENUM\(/)) {
query = this.pgEnum(tableName, attributeName, definition) + query;
definition = definition.replace(/^ENUM\(.+\)/, this.quoteIdentifier('enum_' + tableName + '_' + attributeName));
definition += ' USING (' + this.quoteIdentifier(attributeName) + '::' + this.quoteIdentifier(definition) + ')';
}
if (definition.match(/UNIQUE;*$/)) {
......
module.exports = {
up: function(migration, DataTypes, done) {
migration.addColumn('User', 'level', { type: DataTypes.STRING }).complete(function() {
migration.changeColumn('User', 'level', { type: DataTypes.ENUM, allowNull: false, values: ['basic', 'advanced'] }).complete(done);
});
},
down: function(migration, DataTypes, done) {
migration.removeColumn('User', 'level').complete(done);
}
};
......@@ -100,7 +100,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
SequelizeMeta.create({ from: null, to: 20111117063700 }).success(function() {
migrator.getUndoneMigrations(function(err, migrations) {
expect(err).to.be.null
expect(migrations).to.have.length(14)
expect(migrations).to.have.length(15)
expect(migrations[0].filename).to.equal('20111130161100-emptyMigration.js')
done()
})
......@@ -317,6 +317,28 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
it('changes the level column from user and casts the data to the target enum type', function(done) {
var self = this
this.init({ to: 20111205163000 }, function(migrator) {
migrator.migrate().success(function() {
self.sequelize.getQueryInterface().describeTable('User').complete(function(err, data) {
var level = data.level;
if (dialect === 'postgres') {
expect(level.type).to.equal('USER-DEFINED');
} else if (dialect === 'sqlite') {
expect(level.type).to.equal('TEXT');
} else {
expect(level.type).to.equal('ENUM(\'BASIC\',\'ADVANCED\')');
}
done()
})
})
})
})
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!