diff --git a/db/.gitignore b/db/.gitignore index d743e61..08f41a1 100644 --- a/db/.gitignore +++ b/db/.gitignore @@ -1,3 +1,3 @@ -* +/* !/.gitignore -!/migrations +!/migrations/ diff --git a/db/migrations/20171223203915_create_tables.js b/db/migrations/20171223203915_create_tables.js new file mode 100644 index 0000000..d12fdda --- /dev/null +++ b/db/migrations/20171223203915_create_tables.js @@ -0,0 +1,44 @@ +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.bigInteger('user_id').unsigned().notNullable().index(); + table.string('user_name', 128).notNullable(); + table.bigInteger('channel_id').unsigned().nullable().unique(); + 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.bigInteger('user_id').unsigned().notNullable(); + table.string('user_name', 128).notNullable(); + table.text('body').notNullable(); + table.bigInteger('original_message_id').unsigned().nullable(); + table.dateTime('created_at').notNullable().index(); + }); + + await knex.schema.createTableIfNotExists('blocked_users', table => { + table.bigInteger('user_id').unsigned().primary().notNullable(); + table.string('user_name', 128).notNullable(); + table.bigInteger('blocked_by').unsigned().nullable(); + 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.bigInteger('created_by').unsigned().nullable(); + 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'); +};