diff --git a/db/migrations/20200818214801_change_alert_id_to_alert_ids.js b/db/migrations/20200818214801_change_alert_id_to_alert_ids.js new file mode 100644 index 0000000..9ba6f5d --- /dev/null +++ b/db/migrations/20200818214801_change_alert_id_to_alert_ids.js @@ -0,0 +1,21 @@ +exports.up = async function(knex) { + await knex.schema.table("threads", table => { + table.text("alert_ids").nullable(); + }); + + await knex("threads") + .update({ + alert_ids: knex.raw("alert_id"), + }); + + await knex.schema.table("threads", table => { + table.dropColumn("alert_id"); + }); +}; + +exports.down = async function(knex) { + await knex.schema.table("threads", table => { + table.dropColumn("alert_ids"); + table.text("alert_id").nullable(); + }); +}; diff --git a/src/data/Thread.js b/src/data/Thread.js index 87e407a..37526a7 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -23,7 +23,7 @@ const {THREAD_MESSAGE_TYPE, THREAD_STATUS, DISCORD_MESSAGE_ACTIVITY_TYPES} = req * @property {String} scheduled_close_id * @property {String} scheduled_close_name * @property {Number} scheduled_close_silent - * @property {String} alert_id + * @property {String} alert_ids * @property {String} created_at */ class Thread { @@ -334,8 +334,8 @@ class Thread { await this.postSystemMessage(`<@!${this.scheduled_close_id}> Thread that was scheduled to be closed got a new reply. Cancelling.`); } - if (this.alert_id) { - const ids = this.alert_id.split(","); + if (this.alert_ids) { + const ids = this.alert_ids.split(","); let mentions = ""; ids.forEach(id => { @@ -604,9 +604,9 @@ class Thread { async addAlert(userId) { let alerts = await knex("threads") .where("id", this.id) - .select("alert_id") + .select("alert_ids") .first(); - alerts = alerts.alert_id; + alerts = alerts.alert_ids; if (alerts == null) { alerts = [userId] @@ -621,7 +621,7 @@ class Thread { await knex("threads") .where("id", this.id) .update({ - alert_id: alerts + alert_ids: alerts }); } @@ -632,9 +632,9 @@ class Thread { async removeAlert(userId) { let alerts = await knex("threads") .where("id", this.id) - .select("alert_id") + .select("alert_ids") .first(); - alerts = alerts.alert_id; + alerts = alerts.alert_ids; if (alerts != null) { alerts = alerts.split(","); @@ -657,7 +657,7 @@ class Thread { await knex("threads") .where("id", this.id) .update({ - alert_id: alerts + alert_ids: alerts }); } @@ -668,7 +668,7 @@ class Thread { await knex("threads") .where("id", this.id) .update({ - alert_id: null + alert_ids: null }) }