2013-05-02 00:21:49 -04:00
|
|
|
var Q = require('q');
|
2013-05-03 23:16:15 -04:00
|
|
|
module.exports = function(Knex, item, handler, type) {
|
2013-05-02 00:21:49 -04:00
|
|
|
|
2013-05-04 14:36:41 -04:00
|
|
|
before(function(ok) {
|
2013-05-02 00:21:49 -04:00
|
|
|
|
2013-05-04 14:36:41 -04:00
|
|
|
Q.all([
|
2013-05-03 12:51:54 -04:00
|
|
|
|
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');
|
|
|
|
|
table.string('email').nullable();
|
|
|
|
|
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-03 12:51:54 -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
|
|
|
})
|
|
|
|
|
|
|
|
|
|
]).then(function(resp) {
|
2013-05-02 00:21:49 -04:00
|
|
|
|
2013-05-04 14:36:41 -04:00
|
|
|
// Edit test table one
|
|
|
|
|
return Knex.Schema.table('test_table_one', function(t) {
|
|
|
|
|
t.string('phone').nullable();
|
|
|
|
|
}).then(function(res2) {
|
|
|
|
|
resp.push(res2);
|
|
|
|
|
return resp;
|
2013-05-04 02:57:12 -04:00
|
|
|
});
|
2013-05-03 23:16:15 -04:00
|
|
|
|
2013-05-04 14:36:41 -04:00
|
|
|
}).then(handler(ok, true), ok);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe(item, function() {
|
2013-05-02 00:21:49 -04:00
|
|
|
|
|
|
|
|
it('conditionally drops tables with `dropTableIfExists` - ' + item, function(ok) {
|
2013-05-04 14:36:41 -04:00
|
|
|
Knex.Schema.dropTableIfExists('items').then(handler(ok), ok);
|
2013-05-02 00:21:49 -04:00
|
|
|
});
|
|
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
if (type !== 'String') {
|
|
|
|
|
it('checks for table existence with `hasTable` - ' + item, function(ok) {
|
|
|
|
|
Knex.Schema.hasTable('test_table_two').then(handler(ok), ok);
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-05-03 23:16:15 -04:00
|
|
|
|
2013-05-04 02:57:12 -04:00
|
|
|
it('renames tables with `renameTable` - ' + item, function(ok) {
|
|
|
|
|
Knex.Schema.renameTable('test_table_one', 'accounts').then(handler(ok), ok);
|
2013-05-03 23:16:15 -04:00
|
|
|
});
|
|
|
|
|
|
2013-05-02 00:21:49 -04:00
|
|
|
});
|
|
|
|
|
|
2013-05-04 14:36:41 -04:00
|
|
|
after(function(ok) {
|
|
|
|
|
|
|
|
|
|
Knex.Schema.dropTable('test_table_three').then(handler(ok), ok);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2013-05-02 00:21:49 -04:00
|
|
|
};
|