diff --git a/src/sql/migrations/20240918171424_rename_last_params_seurat.js b/src/sql/migrations/20240918171424_rename_last_params_seurat.js index fbfab6227..77b341600 100644 --- a/src/sql/migrations/20240918171424_rename_last_params_seurat.js +++ b/src/sql/migrations/20240918171424_rename_last_params_seurat.js @@ -3,11 +3,16 @@ * @returns { Promise } */ exports.up = async (knex) => { - // Update the last_pipeline_params to set sampleTechnology to seurat_object where it is currently seurat + // 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({ pipeline_type: 'obj2s' }) + .where(knex.raw("pipeline_type::text = 'obj2s'")) // Cast enum to text for comparison .update({ - last_pipeline_params: knex.raw("jsonb_set(last_pipeline_params::jsonb, '{sampleTechnology}', '\"seurat_object\"'::jsonb)"), + // Use jsonb_set to update the `sampleTechnology` key in the last_pipeline_params JSON field. + // The third parameter, true, allows us to create the key if it doesn't exist. + last_pipeline_params: knex.raw( + 'jsonb_set(last_pipeline_params::jsonb, \'{sampleTechnology}\', \'"seurat_object"\'::jsonb, true)', + ), }); }; @@ -16,10 +21,13 @@ exports.up = async (knex) => { * @returns { Promise } */ exports.down = async (knex) => { - // Revert sampleTechnology back to seurat + // Revert the same logic in the down migration: cast the enum to text to avoid issues. await knex('experiment_execution') - .where({ pipeline_type: 'obj2s' }) + .where(knex.raw("pipeline_type::text = 'obj2s'")) // Again, cast enum to text for comparison .update({ - last_pipeline_params: knex.raw("jsonb_set(last_pipeline_params::jsonb, '{sampleTechnology}', '\"seurat\"'::jsonb)"), + // Revert `sampleTechnology` key back to 'seurat' in the last_pipeline_params JSON field. + last_pipeline_params: knex.raw( + 'jsonb_set(last_pipeline_params::jsonb, \'{sampleTechnology}\', \'"seurat"\'::jsonb, true)', + ), }); };