2013-05-08 20:16:39 -04:00
|
|
|
var When = require('when');
|
2013-05-09 03:47:03 -04:00
|
|
|
module.exports = function(Knex, resolver, error) {
|
2013-05-04 16:27:58 -04:00
|
|
|
|
|
|
|
|
var res = null;
|
2013-05-08 20:16:39 -04:00
|
|
|
|
|
|
|
|
return When.all([
|
2013-05-04 16:27:58 -04:00
|
|
|
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) {
|
2013-05-08 20:16:39 -04:00
|
|
|
|
2013-05-05 13:54:43 -04:00
|
|
|
res = [resp[0]]; // only really need one of these for the test output.
|
2013-05-08 20:16:39 -04:00
|
|
|
|
|
|
|
|
return When.all([
|
2013-05-04 02:57:12 -04:00
|
|
|
Knex.Schema.createTable('test_table_one', function(table) {
|
2013-05-15 19:58:27 -04:00
|
|
|
table.engine('InnoDB');
|
2013-06-16 20:27:24 +10:00
|
|
|
table.comment('A table comment.')
|
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-06-16 20:27:24 +10:00
|
|
|
table.integer('logins').defaultTo(1).index().comment();
|
|
|
|
|
table.text('about').comment('A comment.');
|
2013-05-02 00:21:49 -04:00
|
|
|
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) {
|
2013-05-15 19:58:27 -04:00
|
|
|
t.engine('InnoDB');
|
2013-05-04 02:57:12 -04:00
|
|
|
t.increments();
|
|
|
|
|
t.integer('account_id');
|
|
|
|
|
t.text('details');
|
2013-05-14 17:31:54 -04:00
|
|
|
t.tinyint('status');
|
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-15 19:58:27 -04:00
|
|
|
table.engine('InnoDB');
|
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;
|
|
|
|
|
})
|
2013-05-09 03:47:03 -04:00
|
|
|
.then(resolver, error);
|
2013-05-04 14:36:41 -04:00
|
|
|
|
2013-06-16 20:27:24 +10:00
|
|
|
};
|