From a4f8e88898eeb891e1cc1d8f736f8a5611b48f2e Mon Sep 17 00:00:00 2001 From: hms-dbmi-cellenics Date: Fri, 20 Sep 2024 00:49:25 +0000 Subject: [PATCH] Update from https://github.com/hms-dbmi-cellenics/api/commit/e750868bf5e957a380fac079c3d6f0525ff972db --- ...0240919171424_rename_last_status_seurat.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 migrations/sql/20240919171424_rename_last_status_seurat.js diff --git a/migrations/sql/20240919171424_rename_last_status_seurat.js b/migrations/sql/20240919171424_rename_last_status_seurat.js new file mode 100644 index 0000000000..42ecbd8ea0 --- /dev/null +++ b/migrations/sql/20240919171424_rename_last_status_seurat.js @@ -0,0 +1,33 @@ +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.up = async (knex) => { + // We're using `pipeline_type::text = 'obj2s'` to cast the enum to a text type. + // This avoids the potential issue of "unsafe use of new value" caused by enum strictness. + await knex('experiment_execution') + .where(knex.raw("pipeline_type::text = 'obj2s'")) // Cast enum to text for comparison + .update({ + // Use jsonb_set to add the new `obj2s` key to last_status_response with the value from `seurat`. + // Then, remove the old `seurat` key from last_status_response. + last_status_response: knex.raw( + 'jsonb_set(last_status_response::jsonb, \'{obj2s}\', last_status_response::jsonb->\'seurat\', true) - \'seurat\'', + ), + }); +}; + +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +exports.down = async (knex) => { + // Revert the same logic in the down migration: cast the enum to text to avoid issues. + await knex('experiment_execution') + .where(knex.raw("pipeline_type::text = 'obj2s'")) // Again, cast enum to text for comparison + .update({ + // Revert the key change by adding `seurat` back and removing `obj2s`. + last_status_response: knex.raw( + 'jsonb_set(last_status_response::jsonb, \'{seurat}\', last_status_response::jsonb->\'obj2s\', true) - \'obj2s\'', + ), + }); +};