diff --git a/packages/cli/src/ActiveExecutions.ts b/packages/cli/src/ActiveExecutions.ts index e24c1f0451..f2970e9e41 100644 --- a/packages/cli/src/ActiveExecutions.ts +++ b/packages/cli/src/ActiveExecutions.ts @@ -39,10 +39,10 @@ export class ActiveExecutions { async add(executionData: IWorkflowExecutionDataProcess, process?: ChildProcess): Promise { const fullExecutionData: IExecutionDb = { - data: executionData.executionData!, // check if we can use ! here + data: executionData.executionData!, // this is only empty for CLI executions but works fine. mode: executionData.executionMode, finished: false, - startedAt: new Date(), // check if this is right + startedAt: new Date(), workflowData: executionData.workflowData, }; diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index b9758c294d..450a191521 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -35,29 +35,29 @@ export let collections: IDatabaseCollections = { import { CreateIndexStoppedAt1594828256133, InitialMigration1587669153312, - WebhookModel1589476000887, MakeStoppedAtNullable1607431743768, + WebhookModel1589476000887, } from './databases/postgresdb/migrations'; import { CreateIndexStoppedAt1594910478695, InitialMigration1587563438936, - WebhookModel1592679094242, MakeStoppedAtNullable1607431743766, + WebhookModel1592679094242, } from './databases/mongodb/migrations'; import { CreateIndexStoppedAt1594902918301, InitialMigration1588157391238, - WebhookModel1592447867632, MakeStoppedAtNullable1607431743767, + WebhookModel1592447867632, } from './databases/mysqldb/migrations'; import { CreateIndexStoppedAt1594825041918, InitialMigration1588102412422, - WebhookModel1592445003908, MakeStoppedAtNullable1607431743769, + WebhookModel1592445003908, } from './databases/sqlite/migrations'; import * as path from 'path'; diff --git a/packages/cli/src/databases/mongodb/migrations/1607431743766-MakeStoppedAtNullable.ts b/packages/cli/src/databases/mongodb/migrations/1607431743766-MakeStoppedAtNullable.ts index a1b49d1e23..131733eb13 100644 --- a/packages/cli/src/databases/mongodb/migrations/1607431743766-MakeStoppedAtNullable.ts +++ b/packages/cli/src/databases/mongodb/migrations/1607431743766-MakeStoppedAtNullable.ts @@ -1,13 +1,13 @@ import {MigrationInterface, QueryRunner} from "typeorm"; -import * as config from '../../../../config'; - export class MakeStoppedAtNullable1607431743766 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - } + async up(queryRunner: QueryRunner): Promise { - public async down(queryRunner: QueryRunner): Promise { - } + } + + async down(queryRunner: QueryRunner): Promise { + + } } diff --git a/packages/cli/src/databases/mysqldb/migrations/1607431743767-MakeStoppedAtNullable.ts b/packages/cli/src/databases/mysqldb/migrations/1607431743767-MakeStoppedAtNullable.ts index f7c53ea463..dd261b6620 100644 --- a/packages/cli/src/databases/mysqldb/migrations/1607431743767-MakeStoppedAtNullable.ts +++ b/packages/cli/src/databases/mysqldb/migrations/1607431743767-MakeStoppedAtNullable.ts @@ -1,17 +1,17 @@ -import {MigrationInterface, QueryRunner} from "typeorm"; +import { MigrationInterface, QueryRunner } from "typeorm"; import * as config from '../../../../config'; export class MakeStoppedAtNullable1607431743767 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { + async up(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query('ALTER TABLE `' + tablePrefix + 'execution_entity` MODIFY `stoppedAt` datetime', undefined); - } + } - public async down(queryRunner: QueryRunner): Promise { + async down(queryRunner: QueryRunner): Promise { const tablePrefix = config.get('database.tablePrefix'); await queryRunner.query('ALTER TABLE `' + tablePrefix + 'execution_entity` MODIFY `stoppedAt` datetime NOT NULL', undefined); - } + } } diff --git a/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts b/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts index c096100698..bed94ea48c 100644 --- a/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts +++ b/packages/cli/src/databases/postgresdb/migrations/1607431743768-MakeStoppedAtNullable.ts @@ -4,13 +4,13 @@ import * as config from '../../../../config'; export class MakeStoppedAtNullable1607431743768 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - await queryRunner.query('ALTER TABLE `' + tablePrefix + 'execution_entity` ALTER COLUMN `stoppedAt` DROP NOT NULL', undefined); - } + async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + await queryRunner.query('ALTER TABLE `' + tablePrefix + 'execution_entity` ALTER COLUMN `stoppedAt` DROP NOT NULL', undefined); + } - public async down(queryRunner: QueryRunner): Promise { - // Cannot be undone as column might already have null values - } + async down(queryRunner: QueryRunner): Promise { + // Cannot be undone as column might already have null values + } } diff --git a/packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts b/packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts index 558bc0820b..29285c9192 100644 --- a/packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts +++ b/packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts @@ -4,16 +4,20 @@ import * as config from '../../../../config'; export class MakeStoppedAtNullable1607431743769 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - const tablePrefix = config.get('database.tablePrefix'); - console.log(`UPDATE SQLITE_MASTER SET SQL = 'CREATE TABLE IF NOT EXISTS "${tablePrefix}execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime, "workflowData" text NOT NULL, "workflowId" varchar)' WHERE NAME = "${tablePrefix}execution_entity";`); - await queryRunner.query(`PRAGMA writable_schema = 1; `, undefined); - await queryRunner.query(`UPDATE SQLITE_MASTER SET SQL = 'CREATE TABLE IF NOT EXISTS "${tablePrefix}execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime, "workflowData" text NOT NULL, "workflowId" varchar)' WHERE NAME = "${tablePrefix}execution_entity";`, undefined); - await queryRunner.query(`PRAGMA writable_schema = 0;`, undefined); - } + async up(queryRunner: QueryRunner): Promise { + const tablePrefix = config.get('database.tablePrefix'); + // SQLite does not allow us to simply "alter column" + // We're hacking the way sqlite identifies tables + // Allowing a column to become nullable + // This is a very strict case when this can be done safely + // As no collateral effects exist. + await queryRunner.query(`PRAGMA writable_schema = 1; `, undefined); + await queryRunner.query(`UPDATE SQLITE_MASTER SET SQL = 'CREATE TABLE IF NOT EXISTS "${tablePrefix}execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "data" text NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime NOT NULL, "stoppedAt" datetime, "workflowData" text NOT NULL, "workflowId" varchar)' WHERE NAME = "${tablePrefix}execution_entity";`, undefined); + await queryRunner.query(`PRAGMA writable_schema = 0;`, undefined); + } - public async down(queryRunner: QueryRunner): Promise { - // This cannot be undone as the table might already have nullable values - } + async down(queryRunner: QueryRunner): Promise { + // This cannot be undone as the table might already have nullable values + } }