diff --git a/src/data/migrations/20210120231512_fix_moderator_role_overrides_thread_id_nullability.js b/src/data/migrations/20210120231512_fix_moderator_role_overrides_thread_id_nullability.js new file mode 100644 index 0000000..cbad0ba --- /dev/null +++ b/src/data/migrations/20210120231512_fix_moderator_role_overrides_thread_id_nullability.js @@ -0,0 +1,41 @@ +exports.up = async function(knex) { + await knex.schema.renameTable("moderator_role_overrides", "old_moderator_role_overrides"); + + await knex.schema.createTable("moderator_role_overrides", table => { + table.increments("id"); + table.string("moderator_id", 20).notNullable(); + table.string("thread_id", 36).nullable().defaultTo(null); + table.string("role_id", 20).notNullable(); + + table.unique(["moderator_id", "thread_id"]); + }); + + const rows = await knex.table("old_moderator_role_overrides") + .select(); + + await knex.table("moderator_role_overrides").insert(rows); + + await knex.schema.dropTable("old_moderator_role_overrides"); +}; + +exports.down = async function(knex) { + await knex.schema.renameTable("moderator_role_overrides", "new_moderator_role_overrides"); + + await knex.schema.createTable("moderator_role_overrides", table => { + table.string("moderator_id", 20); + table.string("thread_id", 36).nullable().defaultTo(null); + table.string("role_id", 20); + + table.primary(["moderator_id", "thread_id"]); + }); + + const rows = await knex.table("new_moderator_role_overrides") + .select(); + + await knex.table("moderator_role_overrides").insert(rows.map(r => { + delete r.id; + return r; + })); + + await knex.schema.dropTable("new_moderator_role_overrides"); +};