Skip to content

Commit

Permalink
Merge pull request #528 from hms-dbmi-cellenics/fix-migration
Browse files Browse the repository at this point in the history
fix migration
  • Loading branch information
alexvpickering authored Sep 20, 2024
2 parents a7d7898 + d7fcf30 commit 0195a50
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/sql/migrations/20240918171424_rename_last_params_seurat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* @returns { Promise<void> }
*/
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)',
),
});
};

Expand All @@ -16,10 +21,13 @@ exports.up = async (knex) => {
* @returns { Promise<void> }
*/
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)',
),
});
};

0 comments on commit 0195a50

Please sign in to comment.