Files
n8n-enterprise-unlocked/packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts
T
c21c8b3369 ⚡ Simplify config imports in cli package (#1840)
* ⚡ Set path alias for config

* ⚡ Update config export

* ⚡ Simplify config imports

* ⚡ Update also additional imports

* ⚡ Update path in collation migration

* ⚡ Resolve aliased paths

* 👕 Fix Codacy issue

* 👕 Retry to fix Codacy issue

Co-authored-by: Jan <janober@users.noreply.github.com>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
2021-06-22 23:18:52 +02:00

24 lines
1.2 KiB
TypeScript

import {MigrationInterface, QueryRunner} from "typeorm";
import { config } from '@config';
export class MakeStoppedAtNullable1607431743769 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
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);
}
async down(queryRunner: QueryRunner): Promise<void> {
// This cannot be undone as the table might already have nullable values
}
}