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

Commit b42d8a02 by sdepold

spec for addColumn

1 parent 0e3c0c19
module.exports = {
up: function(migration, DataTypes) {
migration.addColumn('User', 'signature', DataTypes.TEXT)
migration.addColumn('User', 'shopId', { type: DataTypes.INTEGER, allowNull: true })
migration.addColumn('User', 'isAdmin', { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false })
},
down: function(migration, DataTypes) {
migration.removeColumn('User', 'signature')
migration.removeColumn('User', 'shopId')
migration.removeColumn('User', 'isAdmin')
}
}
...@@ -22,6 +22,7 @@ describe('Migrator', function() { ...@@ -22,6 +22,7 @@ describe('Migrator', function() {
SequelizeMeta = _SequelizeMeta SequelizeMeta = _SequelizeMeta
done() done()
}) })
.error(function(err) { console.log(err) })
}) })
} }
...@@ -92,7 +93,7 @@ describe('Migrator', function() { ...@@ -92,7 +93,7 @@ describe('Migrator', function() {
SequelizeMeta.create({ lastMigrationId: '20111117063700' }).success(function() { SequelizeMeta.create({ lastMigrationId: '20111117063700' }).success(function() {
migrator.getUndoneMigrations(function(err, migrations) { migrator.getUndoneMigrations(function(err, migrations) {
expect(err).toBeFalsy() expect(err).toBeFalsy()
expect(migrations.length).toEqual(3) expect(migrations.length).toEqual(4)
expect(migrations[0].filename).toEqual('20111123060700-addBirthdateToPerson.js') expect(migrations[0].filename).toEqual('20111123060700-addBirthdateToPerson.js')
done() done()
}) })
...@@ -101,7 +102,7 @@ describe('Migrator', function() { ...@@ -101,7 +102,7 @@ describe('Migrator', function() {
}) })
}) })
describe('migrate', function() { describe('migrations', function() {
beforeEach(function() { beforeEach(function() {
setup({ from: 20111117063700, to: 20111117063700 }) setup({ from: 20111117063700, to: 20111117063700 })
...@@ -110,74 +111,111 @@ describe('Migrator', function() { ...@@ -110,74 +111,111 @@ describe('Migrator', function() {
}) })
}) })
it("executes migration #20111117063700 and correctly creates the table", function() { describe('executions', function() {
Helpers.async(function(done) { it("executes migration #20111117063700 and correctly creates the table", function() {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { Helpers.async(function(done) {
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
expect(tableNames.length).toEqual(1) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames[0]).toEqual('Person') expect(tableNames.length).toEqual(1)
done() expect(tableNames[0]).toEqual('Person')
done()
})
}) })
}) })
})
it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() { it("executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)", function() {
Helpers.async(function(done) { Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(1) expect(tableNames.length).toEqual(1)
done()
})
})
Helpers.async(function(done) {
migrator.migrate({ method: 'down' }).success(function() {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(0)
done()
}).error(function(err){ console.log(err); done() })
}).error(function(err){ console.log(err); done() })
})
})
it("executes the empty migration #20111130161100", function() {
Helpers.async(function(done) {
setup({ from: 20111130161100, to: 20111130161100})
done() done()
}) })
Helpers.async(function(done) {
migrator.migrate().success(done).error(function(err) { console.log(err) })
// this migration isn't actually testing anything but
// should not timeout
})
}) })
})
Helpers.async(function(done) { describe('renameTable', function() {
migrator.migrate({ method: 'down' }).success(function() { it("executes migration #20111205064000 and renames a table", function() {
Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(0) expect(tableNames.length).toEqual(1)
expect(tableNames[0]).toEqual('Person')
done() done()
}).error(function(err){ console.log(err); done() }) })
}).error(function(err){ console.log(err); done() }) })
})
})
it("executes the empty migration #20111130161100", function() { setup({from: 20111205064000, to: 20111205064000})
Helpers.async(function(done) {
setup({ from: 20111130161100, to: 20111130161100})
done()
})
Helpers.async(function(done) { Helpers.async(function(done) {
migrator.migrate().success(done).error(function(err) { console.log(err) }) migrator.migrate().success(done).error(function(err) { console.log(err) })
// this migration isn't actually testing anything but })
// should not timeout
Helpers.async(function(done) {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) {
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(1)
expect(tableNames[0]).toEqual('User')
done()
})
})
}) })
}) })
it("executes migration #20111205064000 and renames a table", function() { describe('addColumn', function() {
Helpers.async(function(done) { it('adds a column to the user table', function() {
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { setup({from: 20111205064000, to: 20111205162700})
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' })
expect(tableNames.length).toEqual(1) Helpers.async(function(done) {
expect(tableNames[0]).toEqual('Person') migrator.migrate().success(done).error(function(err) { console.log(err) })
done()
}) })
})
setup({from: 20111205064000, to: 20111205064000}) Helpers.async(function(done) {
sequelize.getQueryInterface().describeTable('User').success(function(data) {
var signature = data.filter(function(hash){ return hash.Field == 'signature' })[0]
, isAdmin = data.filter(function(hash){ return hash.Field == 'isAdmin' })[0]
, shopId = data.filter(function(hash){ return hash.Field == 'shopId' })[0]
Helpers.async(function(done) { expect(signature.Field).toEqual('signature')
migrator.migrate().success(done).error(function(err) { console.log(err) }) expect(signature.Null).toEqual('NO')
})
Helpers.async(function(done) { expect(isAdmin.Field).toEqual('isAdmin')
sequelize.getQueryInterface().showAllTables().success(function(tableNames) { expect(isAdmin.Null).toEqual('NO')
tableNames = tableNames.filter(function(e){ return e != 'SequelizeMeta' }) expect(isAdmin.Default).toEqual('0')
expect(tableNames.length).toEqual(1)
expect(tableNames[0]).toEqual('User') expect(shopId.Field).toEqual('shopId')
done() expect(shopId.Null).toEqual('YES')
done()
}).error(function(err) {
console.log(err)
})
}) })
}) })
}) })
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!