From bc219e0499f36a2fbcca7c255fe774b182f0b129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 22 May 2024 16:56:05 +0200 Subject: [PATCH] refactor(core): Make execution status non-nullable (no-changelog) (#9483) --- .../src/databases/entities/ExecutionEntity.ts | 2 +- ...33768521-MakeExecutionStatusNonNullable.ts | 22 +++++++++++++++++++ .../src/databases/migrations/mysqldb/index.ts | 2 ++ .../databases/migrations/postgresdb/index.ts | 2 ++ .../src/databases/migrations/sqlite/index.ts | 2 ++ .../CredentialsRiskReporter.test.ts | 2 ++ .../test/integration/shared/db/executions.ts | 2 +- 7 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/databases/migrations/common/1714133768521-MakeExecutionStatusNonNullable.ts diff --git a/packages/cli/src/databases/entities/ExecutionEntity.ts b/packages/cli/src/databases/entities/ExecutionEntity.ts index 14fad4d50e..dbd597a828 100644 --- a/packages/cli/src/databases/entities/ExecutionEntity.ts +++ b/packages/cli/src/databases/entities/ExecutionEntity.ts @@ -40,7 +40,7 @@ export class ExecutionEntity { @Column({ nullable: true }) retrySuccessId: string; - @Column('varchar', { nullable: true }) + @Column('varchar') status: ExecutionStatus; @Column(datetimeColumnType) diff --git a/packages/cli/src/databases/migrations/common/1714133768521-MakeExecutionStatusNonNullable.ts b/packages/cli/src/databases/migrations/common/1714133768521-MakeExecutionStatusNonNullable.ts new file mode 100644 index 0000000000..c3ccfed43d --- /dev/null +++ b/packages/cli/src/databases/migrations/common/1714133768521-MakeExecutionStatusNonNullable.ts @@ -0,0 +1,22 @@ +import type { IrreversibleMigration, MigrationContext } from '@/databases/types'; + +export class MakeExecutionStatusNonNullable1714133768521 implements IrreversibleMigration { + async up({ escape, runQuery, schemaBuilder }: MigrationContext) { + const executionEntity = escape.tableName('execution_entity'); + const status = escape.columnName('status'); + const finished = escape.columnName('finished'); + + const query = ` + UPDATE ${executionEntity} + SET ${status} = CASE + WHEN ${finished} = true THEN 'success' + WHEN ${finished} = false THEN 'error' + END + WHERE ${status} IS NULL; + `; + + await runQuery(query); + + await schemaBuilder.addNotNull('execution_entity', 'status'); + } +} diff --git a/packages/cli/src/databases/migrations/mysqldb/index.ts b/packages/cli/src/databases/migrations/mysqldb/index.ts index daa57b2c5b..8b467999f5 100644 --- a/packages/cli/src/databases/migrations/mysqldb/index.ts +++ b/packages/cli/src/databases/migrations/mysqldb/index.ts @@ -56,6 +56,7 @@ import { DropRoleMapping1705429061930 } from '../common/1705429061930-DropRoleMa import { RemoveFailedExecutionStatus1711018413374 } from '../common/1711018413374-RemoveFailedExecutionStatus'; import { MoveSshKeysToDatabase1711390882123 } from '../common/1711390882123-MoveSshKeysToDatabase'; import { RemoveNodesAccess1712044305787 } from '../common/1712044305787-RemoveNodesAccess'; +import { MakeExecutionStatusNonNullable1714133768521 } from '../common/1714133768521-MakeExecutionStatusNonNullable'; export const mysqlMigrations: Migration[] = [ InitialMigration1588157391238, @@ -115,4 +116,5 @@ export const mysqlMigrations: Migration[] = [ MoveSshKeysToDatabase1711390882123, RemoveNodesAccess1712044305787, CreateProject1714133768519, + MakeExecutionStatusNonNullable1714133768521, ]; diff --git a/packages/cli/src/databases/migrations/postgresdb/index.ts b/packages/cli/src/databases/migrations/postgresdb/index.ts index b31e2970d2..6ca797c1da 100644 --- a/packages/cli/src/databases/migrations/postgresdb/index.ts +++ b/packages/cli/src/databases/migrations/postgresdb/index.ts @@ -55,6 +55,7 @@ import { DropRoleMapping1705429061930 } from '../common/1705429061930-DropRoleMa import { RemoveFailedExecutionStatus1711018413374 } from '../common/1711018413374-RemoveFailedExecutionStatus'; import { MoveSshKeysToDatabase1711390882123 } from '../common/1711390882123-MoveSshKeysToDatabase'; import { RemoveNodesAccess1712044305787 } from '../common/1712044305787-RemoveNodesAccess'; +import { MakeExecutionStatusNonNullable1714133768521 } from '../common/1714133768521-MakeExecutionStatusNonNullable'; export const postgresMigrations: Migration[] = [ InitialMigration1587669153312, @@ -113,4 +114,5 @@ export const postgresMigrations: Migration[] = [ MoveSshKeysToDatabase1711390882123, RemoveNodesAccess1712044305787, CreateProject1714133768519, + MakeExecutionStatusNonNullable1714133768521, ]; diff --git a/packages/cli/src/databases/migrations/sqlite/index.ts b/packages/cli/src/databases/migrations/sqlite/index.ts index 834354fd6b..aefd1649b4 100644 --- a/packages/cli/src/databases/migrations/sqlite/index.ts +++ b/packages/cli/src/databases/migrations/sqlite/index.ts @@ -53,6 +53,7 @@ import { DropRoleMapping1705429061930 } from './1705429061930-DropRoleMapping'; import { RemoveFailedExecutionStatus1711018413374 } from '../common/1711018413374-RemoveFailedExecutionStatus'; import { MoveSshKeysToDatabase1711390882123 } from '../common/1711390882123-MoveSshKeysToDatabase'; import { RemoveNodesAccess1712044305787 } from '../common/1712044305787-RemoveNodesAccess'; +import { MakeExecutionStatusNonNullable1714133768521 } from '../common/1714133768521-MakeExecutionStatusNonNullable'; const sqliteMigrations: Migration[] = [ InitialMigration1588102412422, @@ -109,6 +110,7 @@ const sqliteMigrations: Migration[] = [ MoveSshKeysToDatabase1711390882123, RemoveNodesAccess1712044305787, CreateProject1714133768519, + MakeExecutionStatusNonNullable1714133768521, ]; export { sqliteMigrations }; diff --git a/packages/cli/test/integration/security-audit/CredentialsRiskReporter.test.ts b/packages/cli/test/integration/security-audit/CredentialsRiskReporter.test.ts index c395147e1d..4fdc54dbc1 100644 --- a/packages/cli/test/integration/security-audit/CredentialsRiskReporter.test.ts +++ b/packages/cli/test/integration/security-audit/CredentialsRiskReporter.test.ts @@ -161,6 +161,7 @@ test('should report credential in not recently executed workflow', async () => { stoppedAt: date, workflowId: workflow.id, waitTill: null, + status: 'success', }); await Container.get(ExecutionDataRepository).save({ execution: savedExecution, @@ -228,6 +229,7 @@ test('should not report credentials in recently executed workflow', async () => stoppedAt: date, workflowId: workflow.id, waitTill: null, + status: 'success', }); await Container.get(ExecutionDataRepository).save({ diff --git a/packages/cli/test/integration/shared/db/executions.ts b/packages/cli/test/integration/shared/db/executions.ts index 7e791a08fe..4ac838888c 100644 --- a/packages/cli/test/integration/shared/db/executions.ts +++ b/packages/cli/test/integration/shared/db/executions.ts @@ -30,7 +30,7 @@ export async function createExecution( ...(workflow !== undefined && { workflowId: workflow.id }), stoppedAt: stoppedAt ?? new Date(), waitTill: waitTill ?? null, - status, + status: status ?? 'success', deletedAt, });