ramirez/db/migrations/20171223203915_create_table...

46 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-12-24 15:09:25 -05:00
exports.up = async function(knex, Promise) {
await knex.schema.createTableIfNotExists('threads', table => {
table.string('id', 36).notNullable().primary();
table.integer('status').unsigned().notNullable().index();
table.integer('is_legacy').unsigned().notNullable();
table.string('user_id', 20).notNullable().index();
2017-12-24 15:09:25 -05:00
table.string('user_name', 128).notNullable();
table.string('channel_id', 20).nullable().unique();
2017-12-24 15:09:25 -05:00
table.dateTime('created_at').notNullable().index();
});
await knex.schema.createTableIfNotExists('thread_messages', table => {
table.increments('id');
table.string('thread_id', 36).notNullable().index().references('id').inTable('threads').onDelete('CASCADE');
table.integer('message_type').unsigned().notNullable();
table.string('user_id', 20).nullable();
2017-12-24 15:09:25 -05:00
table.string('user_name', 128).notNullable();
table.mediumtext('body').notNullable();
2017-12-31 19:16:05 -05:00
table.integer('is_anonymous').unsigned().notNullable();
table.string('dm_message_id', 20).nullable().unique();
2017-12-24 15:09:25 -05:00
table.dateTime('created_at').notNullable().index();
});
await knex.schema.createTableIfNotExists('blocked_users', table => {
table.string('user_id', 20).primary().notNullable();
2017-12-24 15:09:25 -05:00
table.string('user_name', 128).notNullable();
table.string('blocked_by', 20).nullable();
2017-12-24 15:09:25 -05:00
table.dateTime('blocked_at').notNullable();
});
await knex.schema.createTableIfNotExists('snippets', table => {
table.string('trigger', 32).primary().notNullable();
table.text('body').notNullable();
table.integer('is_anonymous').unsigned().notNullable();
table.string('created_by', 20).nullable();
2017-12-24 15:09:25 -05:00
table.dateTime('created_at').notNullable();
});
};
exports.down = async function(knex, Promise) {
await knex.schema.dropTableIfExists('thread_messages');
await knex.schema.dropTableIfExists('threads');
await knex.schema.dropTableIfExists('blocked_users');
await knex.schema.dropTableIfExists('snippets');
};