chore(server): remove conditional migration flag (#2313)

This commit is contained in:
Gergő Jedlicska
2024-06-03 16:23:10 +02:00
committed by GitHub
parent 9eea906158
commit 8f2974f8d4
8 changed files with 20 additions and 74 deletions
@@ -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<void> {
// 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<void> {
}
export async function down(knex: Knex): Promise<void> {
// 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)
@@ -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<void> {
// 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<void> {
}
export async function down(knex: Knex): Promise<void> {
// 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)
@@ -3,18 +3,12 @@ import { Knex } from 'knex'
const REVISIONS_TABLE_NAME = 'automation_revisions'
export async function up(knex: Knex): Promise<void> {
// 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<void> {
// 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')
})
@@ -1,9 +1,6 @@
import { Knex } from 'knex'
export async function up(knex: Knex): Promise<void> {
// 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<void> {
}
export async function down(knex: Knex): Promise<void> {
// 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) => {
@@ -3,9 +3,6 @@ import { Knex } from 'knex'
const TABLE_NAME = 'automation_function_runs'
export async function up(knex: Knex): Promise<void> {
// 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<void> {
}
export async function down(knex: Knex): Promise<void> {
// 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')
@@ -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<void> {
// 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<void> {
}
export async function down(knex: Knex): Promise<void> {
// 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,
+20 -31
View File
@@ -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<T extends string, C extends string> = {
/**
@@ -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']
)
@@ -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(