From 4793c8f1be36c1ab42db38ca6e6c5b1348cb4023 Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young Date: Mon, 23 Sep 2024 16:20:49 -0700 Subject: [PATCH 1/2] update null sign id values to direct sighting --- .../20240923161500_update_obs_sign_id.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 database/src/migrations/20240923161500_update_obs_sign_id.ts diff --git a/database/src/migrations/20240923161500_update_obs_sign_id.ts b/database/src/migrations/20240923161500_update_obs_sign_id.ts new file mode 100644 index 0000000000..b001dc1204 --- /dev/null +++ b/database/src/migrations/20240923161500_update_obs_sign_id.ts @@ -0,0 +1,23 @@ +import { Knex } from 'knex'; + +/** + * Bug fix: + * Observation subcount sign id cannot be null, so this updates observation subcount records to change null values to 'direct sighting'. + * + * @export + * @param {Knex} knex + * @return {*} {Promise} + */ +export async function up(knex: Knex): Promise { + await knex.raw(`--sql + SET SEARCH_PATH=biohub; + + UPDATE observation_subcount + SET observation_subcount_sign_id = (SELECT observation_subcount_sign_id FROM observation_subcount_sign WHERE lower(name) = 'direct sighting') + WHERE observation_subcount_sign_id IS NULL; + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(``); +} From d98fa0708aebbc69a043e743c5b35a7f12d7583f Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young Date: Mon, 23 Sep 2024 18:06:38 -0700 Subject: [PATCH 2/2] cleanup --- database/src/migrations/20240923161500_update_obs_sign_id.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/src/migrations/20240923161500_update_obs_sign_id.ts b/database/src/migrations/20240923161500_update_obs_sign_id.ts index b001dc1204..5f86479d98 100644 --- a/database/src/migrations/20240923161500_update_obs_sign_id.ts +++ b/database/src/migrations/20240923161500_update_obs_sign_id.ts @@ -9,7 +9,7 @@ import { Knex } from 'knex'; * @return {*} {Promise} */ export async function up(knex: Knex): Promise { - await knex.raw(`--sql + await knex.raw(` SET SEARCH_PATH=biohub; UPDATE observation_subcount