From dc102d04ed87fde4f7de32dcb7c7dd0aa55567d8 Mon Sep 17 00:00:00 2001 From: Kristaps Fabians Geikins Date: Mon, 27 May 2024 15:20:00 +0300 Subject: [PATCH] fix(server): automation migration down problems --- .../modules/automate/migrations/20240321092858_triggers.ts | 7 +++++-- .../automate/migrations/20240404173455_automation_token.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/server/modules/automate/migrations/20240321092858_triggers.ts b/packages/server/modules/automate/migrations/20240321092858_triggers.ts index a2845590f..a6afbd71a 100644 --- a/packages/server/modules/automate/migrations/20240321092858_triggers.ts +++ b/packages/server/modules/automate/migrations/20240321092858_triggers.ts @@ -56,10 +56,13 @@ export async function down(knex: Knex): Promise { // TODO: Remove, this is a temporary shortcut to avoid messing up the db schema which makes it difficult to jump to different branches if (process.env.SKIP_AUTOMATE_MIGRATION_DEV) return + // delete invalid data + await knex.delete().from(AUTOMATION_RUNS_TABLE_NAME) + await knex.schema.alterTable(REVISIONS_TABLE_NAME, (table) => { // old schema - table.jsonb('triggers').notNullable() // { "triggers": [{ "modelId": "asdf", "type": "commit"}...]} - table.boolean('published').notNullable() + table.jsonb('triggers').notNullable().defaultTo('[]') + table.boolean('published').notNullable().defaultTo(false) }) await knex.schema.alterTable(AUTOMATION_RUNS_TABLE_NAME, (table) => { table diff --git a/packages/server/modules/automate/migrations/20240404173455_automation_token.ts b/packages/server/modules/automate/migrations/20240404173455_automation_token.ts index 83ceb4114..e1433a6eb 100644 --- a/packages/server/modules/automate/migrations/20240404173455_automation_token.ts +++ b/packages/server/modules/automate/migrations/20240404173455_automation_token.ts @@ -50,8 +50,8 @@ export async function down(knex: Knex): Promise { }) await knex.schema.alterTable('automation_runs', (table) => { - table.jsonb('functionRuns').notNullable() // schema defined in code - table.jsonb('triggers').notNullable() + table.jsonb('functionRuns').notNullable().defaultTo('{}') + table.jsonb('triggers').notNullable().defaultTo('{}') }) await knex.schema.alterTable('automation_revisions', (table) => {