Fix migrations so they don't show Knex warnings

cshd
Dragory 2020-08-13 03:37:01 +03:00
parent 9973f75940
commit 555a75929b
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 56 additions and 37 deletions

View File

@ -1,45 +1,64 @@
exports.up = async function(knex, Promise) { exports.up = async function(knex, Promise) {
await knex.schema.createTableIfNotExists('threads', table => { if (! await knex.schema.hasTable("threads")) {
table.string('id', 36).notNullable().primary(); await knex.schema.createTable("threads", table => {
table.integer('status').unsigned().notNullable().index(); table.string("id", 36).notNullable().primary();
table.integer('is_legacy').unsigned().notNullable(); table.integer("status").unsigned().notNullable().index();
table.string('user_id', 20).notNullable().index(); table.integer("is_legacy").unsigned().notNullable();
table.string('user_name', 128).notNullable(); table.string("user_id", 20).notNullable().index();
table.string('channel_id', 20).nullable().unique(); table.string("user_name", 128).notNullable();
table.dateTime('created_at').notNullable().index(); table.string("channel_id", 20).nullable().unique();
table.dateTime("created_at").notNullable().index();
}); });
}
await knex.schema.createTableIfNotExists('thread_messages', table => { if (! await knex.schema.hasTable("thread_messages")) {
table.increments('id'); await knex.schema.createTable("thread_messages", table => {
table.string('thread_id', 36).notNullable().index().references('id').inTable('threads').onDelete('CASCADE'); table.increments("id");
table.integer('message_type').unsigned().notNullable(); table.string("thread_id", 36).notNullable().index().references("id").inTable("threads").onDelete("CASCADE");
table.string('user_id', 20).nullable(); table.integer("message_type").unsigned().notNullable();
table.string('user_name', 128).notNullable(); table.string("user_id", 20).nullable();
table.mediumtext('body').notNullable(); table.string("user_name", 128).notNullable();
table.integer('is_anonymous').unsigned().notNullable(); table.mediumtext("body").notNullable();
table.string('dm_message_id', 20).nullable().unique(); table.integer("is_anonymous").unsigned().notNullable();
table.dateTime('created_at').notNullable().index(); table.string("dm_message_id", 20).nullable().unique();
table.dateTime("created_at").notNullable().index();
}); });
}
await knex.schema.createTableIfNotExists('blocked_users', table => { if (! await knex.schema.hasTable("blocked_users")) {
table.string('user_id', 20).primary().notNullable(); await knex.schema.createTable("blocked_users", table => {
table.string('user_name', 128).notNullable(); table.string("user_id", 20).primary().notNullable();
table.string('blocked_by', 20).nullable(); table.string("user_name", 128).notNullable();
table.dateTime('blocked_at').notNullable(); table.string("blocked_by", 20).nullable();
table.dateTime("blocked_at").notNullable();
}); });
}
await knex.schema.createTableIfNotExists('snippets', table => { if (! await knex.schema.hasTable("snippets")) {
table.string('trigger', 32).primary().notNullable(); await knex.schema.createTable("snippets", table => {
table.text('body').notNullable(); table.string("trigger", 32).primary().notNullable();
table.integer('is_anonymous').unsigned().notNullable(); table.text("body").notNullable();
table.string('created_by', 20).nullable(); table.integer("is_anonymous").unsigned().notNullable();
table.dateTime('created_at').notNullable(); table.string("created_by", 20).nullable();
table.dateTime("created_at").notNullable();
}); });
}
}; };
exports.down = async function(knex, Promise) { exports.down = async function(knex, Promise) {
await knex.schema.dropTableIfExists('thread_messages'); if (await knex.schema.hasTable("thread_messages")) {
await knex.schema.dropTableIfExists('threads'); await knex.schema.dropTable("thread_messages");
await knex.schema.dropTableIfExists('blocked_users'); }
await knex.schema.dropTableIfExists('snippets');
if (await knex.schema.hasTable("threads")) {
await knex.schema.dropTable("threads");
}
if (await knex.schema.hasTable("blocked_users")) {
await knex.schema.dropTable("blocked_users");
}
if (await knex.schema.hasTable("snippets")) {
await knex.schema.dropTable("snippets");
}
}; };