From 8f2974f8d4ecdbd7d197d11062352e334ad8a512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= <57442769+gjedlicska@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:23:10 +0200 Subject: [PATCH] chore(server): remove conditional migration flag (#2313) --- .../migrations/20240305120620_automate.ts | 6 --- .../migrations/20240321092858_triggers.ts | 6 --- .../20240404075414_revision_active.ts | 6 --- .../20240404173455_automation_token.ts | 6 --- ...40507075055_add_function_run_timestamps.ts | 6 --- .../20240304143445_rename_tables.ts | 6 --- packages/server/modules/core/dbSchema.ts | 51 ++++++++----------- .../modules/shared/helpers/envHelper.ts | 7 --- 8 files changed, 20 insertions(+), 74 deletions(-) diff --git a/packages/server/modules/automate/migrations/20240305120620_automate.ts b/packages/server/modules/automate/migrations/20240305120620_automate.ts index 32897d42e..e98c65b47 100644 --- a/packages/server/modules/automate/migrations/20240305120620_automate.ts +++ b/packages/server/modules/automate/migrations/20240305120620_automate.ts @@ -6,9 +6,6 @@ const REVISION_FUNCTIONS_TABLE_NAME = 'automation_revision_functions' const AUTOMATION_RUNS_TABLE_NAME = 'automation_runs' export async function up(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 - await knex.schema.createTable(AUTOMATIONS_TABLE_NAME, (table) => { table.text('id').primary({ constraintName: 'automation_id_pk' }) table.text('name').notNullable() @@ -92,9 +89,6 @@ export async function up(knex: Knex): Promise { } 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 - await knex.schema.dropTable(AUTOMATION_RUNS_TABLE_NAME) await knex.schema.dropTable(REVISION_FUNCTIONS_TABLE_NAME) await knex.schema.dropTable(REVISIONS_TABLE_NAME) diff --git a/packages/server/modules/automate/migrations/20240321092858_triggers.ts b/packages/server/modules/automate/migrations/20240321092858_triggers.ts index a6afbd71a..a439c5de8 100644 --- a/packages/server/modules/automate/migrations/20240321092858_triggers.ts +++ b/packages/server/modules/automate/migrations/20240321092858_triggers.ts @@ -6,9 +6,6 @@ const AUTOMATION_RUNS_TABLE_NAME = 'automation_runs' const AUTOMATION_FUNCTION_RUNS_TABLE_NAME = 'automation_function_runs' export async function up(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 - await knex.schema.alterTable(REVISIONS_TABLE_NAME, (table) => { table.dropColumn('triggers') table.dropColumn('published') @@ -53,9 +50,6 @@ export async function up(knex: Knex): Promise { } 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) diff --git a/packages/server/modules/automate/migrations/20240404075414_revision_active.ts b/packages/server/modules/automate/migrations/20240404075414_revision_active.ts index 0ea20313d..f816a34a2 100644 --- a/packages/server/modules/automate/migrations/20240404075414_revision_active.ts +++ b/packages/server/modules/automate/migrations/20240404075414_revision_active.ts @@ -3,18 +3,12 @@ import { Knex } from 'knex' const REVISIONS_TABLE_NAME = 'automation_revisions' export async function up(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 - await knex.schema.alterTable(REVISIONS_TABLE_NAME, (table) => { table.boolean('active').notNullable().defaultTo(false) }) } 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 - await knex.schema.alterTable(REVISIONS_TABLE_NAME, (table) => { table.dropColumn('active') }) diff --git a/packages/server/modules/automate/migrations/20240404173455_automation_token.ts b/packages/server/modules/automate/migrations/20240404173455_automation_token.ts index e1433a6eb..e566b9bc1 100644 --- a/packages/server/modules/automate/migrations/20240404173455_automation_token.ts +++ b/packages/server/modules/automate/migrations/20240404173455_automation_token.ts @@ -1,9 +1,6 @@ import { Knex } from 'knex' export async function up(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 - await knex.schema.createTable('automation_tokens', (table) => { // yes I'm using an FK as a PK. it's deliberately a 1-1 relationship // the tokens are a lot more sensitive, that should only be queried if needed @@ -40,9 +37,6 @@ export async function up(knex: Knex): Promise { } 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 - await knex.schema.dropTable('automation_tokens') await knex.schema.dropTable('automation_run_triggers') await knex.schema.alterTable('automations', (table) => { diff --git a/packages/server/modules/automate/migrations/20240507075055_add_function_run_timestamps.ts b/packages/server/modules/automate/migrations/20240507075055_add_function_run_timestamps.ts index c0d364305..c0c316a9d 100644 --- a/packages/server/modules/automate/migrations/20240507075055_add_function_run_timestamps.ts +++ b/packages/server/modules/automate/migrations/20240507075055_add_function_run_timestamps.ts @@ -3,9 +3,6 @@ import { Knex } from 'knex' const TABLE_NAME = 'automation_function_runs' export async function up(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 - await knex.schema.alterTable(TABLE_NAME, (table) => { table .timestamp('createdAt', { precision: 3, useTz: true }) @@ -19,9 +16,6 @@ export async function up(knex: Knex): Promise { } 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 - await knex.schema.alterTable(TABLE_NAME, (table) => { table.dropColumn('createdAt') table.dropColumn('updatedAt') diff --git a/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts b/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts index 407fb448d..01790cb34 100644 --- a/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts +++ b/packages/server/modules/betaAutomations/migrations/20240304143445_rename_tables.ts @@ -13,9 +13,6 @@ const AUTOMATION_FUNCTION_RUNS_RESULT_VERSIONS_TABLE_NAME_NEW = 'beta_automation_function_runs_result_versions' export async function up(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 - await knex.schema.renameTable(AUTOMATIONS_TABLE_NAME_OLD, AUTOMATIONS_TABLE_NAME_NEW) await knex.schema.renameTable( AUTOMATION_RUNS_TABLE_NAME_OLD, @@ -32,9 +29,6 @@ export async function up(knex: Knex): Promise { } 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 - await knex.schema.renameTable(AUTOMATIONS_TABLE_NAME_NEW, AUTOMATIONS_TABLE_NAME_OLD) await knex.schema.renameTable( AUTOMATION_RUNS_TABLE_NAME_NEW, diff --git a/packages/server/modules/core/dbSchema.ts b/packages/server/modules/core/dbSchema.ts index fde05771c..ba559d89b 100644 --- a/packages/server/modules/core/dbSchema.ts +++ b/packages/server/modules/core/dbSchema.ts @@ -4,7 +4,6 @@ import knex from '@/db/knex' import { BaseMetaRecord } from '@/modules/core/helpers/meta' import { Knex } from 'knex' import { reduce } from 'lodash' -import { skipAutomateMigrations } from '@/modules/shared/helpers/envHelper' type BaseInnerSchemaConfig = { /** @@ -490,36 +489,28 @@ export const FileUploads = buildTableHelper('file_uploads', [ 'convertedCommitId' ]) -export const BetaAutomations = buildTableHelper( - skipAutomateMigrations() ? 'automations' : 'beta_automations', - [ - 'automationId', - 'automationRevisionId', - 'automationName', - 'projectId', - 'modelId', - 'createdAt', - 'updatedAt', - 'webhookId' - ] -) +export const BetaAutomations = buildTableHelper('beta_automations', [ + 'automationId', + 'automationRevisionId', + 'automationName', + 'projectId', + 'modelId', + 'createdAt', + 'updatedAt', + 'webhookId' +]) -export const BetaAutomationRuns = buildTableHelper( - skipAutomateMigrations() ? 'automation_runs' : 'beta_automation_runs', - [ - 'automationId', - 'automationRevisionId', - 'automationRunId', - 'versionId', - 'createdAt', - 'updatedAt' - ] -) +export const BetaAutomationRuns = buildTableHelper('beta_automation_runs', [ + 'automationId', + 'automationRevisionId', + 'automationRunId', + 'versionId', + 'createdAt', + 'updatedAt' +]) export const BetaAutomationFunctionRuns = buildTableHelper( - skipAutomateMigrations() - ? 'automation_function_runs' - : 'beta_automation_function_runs', + 'beta_automation_function_runs', [ 'automationRunId', 'functionId', @@ -534,9 +525,7 @@ export const BetaAutomationFunctionRuns = buildTableHelper( ) export const BetaAutomationFunctionRunsResultVersions = buildTableHelper( - skipAutomateMigrations() - ? 'automation_function_runs_result_version' - : 'beta_automation_function_runs_result_versions', + 'beta_automation_function_runs_result_versions', ['automationRunId', 'functionId', 'resultVersionId'] ) diff --git a/packages/server/modules/shared/helpers/envHelper.ts b/packages/server/modules/shared/helpers/envHelper.ts index 234dabd8a..b130fa1a6 100644 --- a/packages/server/modules/shared/helpers/envHelper.ts +++ b/packages/server/modules/shared/helpers/envHelper.ts @@ -273,13 +273,6 @@ export function delayGraphqlResponsesBy() { return getIntFromEnv('DELAY_GQL_RESPONSES_BY', '0') } -/** - * TODO: Remove, this is a temporary shortcut to avoid messing up the db schema which makes it difficult to jump to different branches - */ -export function skipAutomateMigrations() { - return getBooleanFromEnv('SKIP_AUTOMATE_MIGRATION_DEV') -} - export function getAutomateEncryptionKeysPath() { if (!process.env.AUTOMATE_ENCRYPTION_KEYS_PATH) { throw new MisconfiguredEnvironmentError(