2013-05-02 00:21:49 -04:00
|
|
|
var Q = require('q');
|
2013-05-04 16:27:58 -04:00
|
|
|
module.exports = function(Knex, handler, error) {
|
|
|
|
|
|
|
|
|
|
var res = null;
|
|
|
|
|
return Q.all([
|
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_one'),
|
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_two'),
|
|
|
|
|
Knex.Schema.dropTableIfExists('test_table_three'),
|
|
|
|
|
Knex.Schema.dropTableIfExists('accounts')
|
|
|
|
|
]).then(function(resp) {
|
|
|
|
|
res = resp;
|
|
|
|
|
return Q.all([
|
2013-05-04 02:57:12 -04:00
|
|
|
Knex.Schema.createTable('test_table_one', function(table) {
|
2013-05-02 00:21:49 -04:00
|
|
|
table.increments('id');
|
|
|
|
|
table.string('first_name');
|
|
|
|
|
table.string('last_name');
|
2013-05-04 21:37:10 -04:00
|
|
|
table.string('email').unique().nullable();
|
2013-05-02 00:21:49 -04:00
|
|
|
table.integer('logins').defaultTo(1).index();
|
|
|
|
|
table.text('about');
|
|
|
|
|
table.timestamps();
|
2013-05-04 14:36:41 -04:00
|
|
|
}),
|
2013-05-04 02:57:12 -04:00
|
|
|
Knex.Schema.createTable('test_table_two', function(t) {
|
|
|
|
|
t.increments();
|
|
|
|
|
t.integer('account_id');
|
|
|
|
|
t.text('details');
|
2013-05-04 14:36:41 -04:00
|
|
|
}),
|
2013-05-04 02:57:12 -04:00
|
|
|
Knex.Schema.createTable('test_table_three', function(table) {
|
2013-05-03 23:16:15 -04:00
|
|
|
table.integer('main').primary();
|
|
|
|
|
table.text('paragraph').defaultTo('Lorem ipsum Qui quis qui in.');
|
2013-05-04 14:36:41 -04:00
|
|
|
})
|
2013-05-04 16:27:58 -04:00
|
|
|
]);
|
|
|
|
|
})
|
|
|
|
|
.then(function(resp) {
|
|
|
|
|
// Edit test table one
|
|
|
|
|
res = res.concat(resp);
|
|
|
|
|
return Knex.Schema.table('test_table_one', function(t) {
|
|
|
|
|
t.string('phone').nullable();
|
2013-05-03 23:16:15 -04:00
|
|
|
});
|
|
|
|
|
|
2013-05-04 16:27:58 -04:00
|
|
|
}).then(function(resp) {
|
|
|
|
|
// conditionally drops tables with `dropTableIfExists`
|
|
|
|
|
res.push(resp);
|
|
|
|
|
return Knex.Schema.dropTableIfExists('items');
|
|
|
|
|
})
|
|
|
|
|
.then(function(resp) {
|
|
|
|
|
res.push(resp);
|
|
|
|
|
return Knex.Schema.hasTable('test_table_two');
|
|
|
|
|
})
|
|
|
|
|
.then(function(resp) {
|
|
|
|
|
res.push(resp);
|
|
|
|
|
return Knex.Schema.renameTable('test_table_one', 'accounts');
|
|
|
|
|
})
|
|
|
|
|
.then(function(resp) {
|
|
|
|
|
res.push(resp);
|
|
|
|
|
return Knex.Schema.dropTable('test_table_three');
|
|
|
|
|
})
|
|
|
|
|
.then(function(resp) {
|
|
|
|
|
res.push(resp);
|
|
|
|
|
return res;
|
|
|
|
|
})
|
|
|
|
|
.then(handler, error);
|
2013-05-04 14:36:41 -04:00
|
|
|
|
2013-05-02 00:21:49 -04:00
|
|
|
};
|