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

Commit 3fd1d95b by sdepold

removed obsolete migration + createTable can handle complex attribute definition

1 parent 4312d328
......@@ -9,6 +9,17 @@ module.exports = (function() {
Utils.addEventEmitter(QueryInterface)
QueryInterface.prototype.createTable = function(tableName, attributes, options) {
var attributeHashes = {}
Utils._.each(attributes, function(dataTypeOrOptions, attributeName) {
if(Utils._.values(DataTypes).indexOf(dataTypeOrOptions) > -1)
attributeHashes[attributeName] = { type: dataTypeOrOptions }
else
attributeHashes[attributeName] = dataTypeOrOptions
})
attributes = this.QueryGenerator.attributesToSQL(attributeHashes)
var sql = this.QueryGenerator.createTableQuery(tableName, attributes, options)
return queryAndEmit.call(this, sql, 'createTable')
}
......
module.exports = {
up: function(migration, DataTypes) {
migration.createTable('Person', {
name: DataTypes.STRING
name: DataTypes.STRING,
isBetaMember: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
}
})
},
down: function(migration) {
......
......@@ -62,21 +62,21 @@ describe('Migrator', function() {
})
it("returns also the file which is exactly options.from or options.to", function() {
setup({ from: 20111117063700, to: 20111123060700 })
setup({ from: 20111117063700, to: 20111130161100 })
Helpers.async(function(done) {
migrator.getUndoneMigrations(function(err, migrations) {
expect(err).toBeNull()
expect(migrations.length).toEqual(2)
expect(migrations[0].filename).toEqual('20111117063700-createPerson.js')
expect(migrations[1].filename).toEqual('20111123060700-addBirthdateToPerson.js')
expect(migrations[1].filename).toEqual('20111130161100-emptyMigration.js')
done()
})
})
})
it("returns all files to options.to if no options.from is defined", function() {
setup({ to: 20111123060700 })
setup({ to: 20111130161100 })
Helpers.async(function(done) {
migrator.getUndoneMigrations(function(err, migrations) {
......@@ -94,8 +94,8 @@ describe('Migrator', function() {
SequelizeMeta.create({ from: null, to: '20111117063700' }).success(function() {
migrator.getUndoneMigrations(function(err, migrations) {
expect(err).toBeNull()
expect(migrations.length).toEqual(7)
expect(migrations[0].filename).toEqual('20111123060700-addBirthdateToPerson.js')
expect(migrations.length).toEqual(6)
expect(migrations[0].filename).toEqual('20111130161100-emptyMigration.js')
done()
})
})
......@@ -124,6 +124,16 @@ describe('Migrator', function() {
})
})
it("executes migration #20111117063700 and correctly adds isBetaMember", function() {
Helpers.async(function(done) {
sequelize.getQueryInterface().describeTable('Person').success(function(data) {
var beta = data.filter(function(d) { return d.Field == 'isBetaMember'})
expect(beta).toBeDefined()
done()
})
})
})
it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() {
Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!