-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔊 create logger helper for migrations (#2944)
* 🔥 remove unused database * 🔊 add migration logging for sqlite * 🔥 remove unnecessary index creation * ⚡️ change log level to warn
- Loading branch information
1 parent
49f82dc
commit cfd1484
Showing
16 changed files
with
310 additions
and
144 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 9 additions & 6 deletions
15
packages/cli/src/databases/sqlite/migrations/1592445003908-WebhookModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
packages/cli/src/databases/sqlite/migrations/1594825041918-CreateIndexStoppedAt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import * as config from '../../../../config'; | ||
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers'; | ||
|
||
export class CreateIndexStoppedAt1594825041918 implements MigrationInterface { | ||
name = 'CreateIndexStoppedAt1594825041918'; | ||
|
||
async up(queryRunner: QueryRunner): Promise<void> { | ||
logMigrationStart(this.name); | ||
|
||
const tablePrefix = config.get('database.tablePrefix'); | ||
|
||
await queryRunner.query(`CREATE INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1" ON "${tablePrefix}execution_entity" ("stoppedAt") `); | ||
await queryRunner.query( | ||
`CREATE INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1" ON "${tablePrefix}execution_entity" ("stoppedAt") `, | ||
); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
const tablePrefix = config.get('database.tablePrefix'); | ||
|
||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1"`); | ||
} | ||
|
||
} |
15 changes: 11 additions & 4 deletions
15
packages/cli/src/databases/sqlite/migrations/1607431743769-MakeStoppedAtNullable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import * as config from '../../../../config'; | ||
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers'; | ||
|
||
export class MakeStoppedAtNullable1607431743769 implements MigrationInterface { | ||
name = 'MakeStoppedAtNullable1607431743769'; | ||
|
||
async up(queryRunner: QueryRunner): Promise<void> { | ||
logMigrationStart(this.name); | ||
|
||
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( | ||
`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); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
// This cannot be undone as the table might already have nullable values | ||
} | ||
|
||
} |
35 changes: 27 additions & 8 deletions
35
packages/cli/src/databases/sqlite/migrations/1611071044839-AddWebhookId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,45 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import * as config from '../../../../config'; | ||
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers'; | ||
|
||
export class AddWebhookId1611071044839 implements MigrationInterface { | ||
name = 'AddWebhookId1611071044839'; | ||
|
||
async up(queryRunner: QueryRunner): Promise<void> { | ||
logMigrationStart(this.name); | ||
|
||
const tablePrefix = config.get('database.tablePrefix'); | ||
|
||
await queryRunner.query(`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, "pathLength" integer, PRIMARY KEY ("webhookPath", "method"))`); | ||
await queryRunner.query(`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`); | ||
await queryRunner.query( | ||
`CREATE TABLE "temporary_webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, "pathLength" integer, PRIMARY KEY ("webhookPath", "method"))`, | ||
); | ||
await queryRunner.query( | ||
`INSERT INTO "temporary_webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "${tablePrefix}webhook_entity"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "${tablePrefix}webhook_entity"`); | ||
await queryRunner.query(`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`); | ||
await queryRunner.query(`CREATE INDEX "IDX_${tablePrefix}742496f199721a057051acf4c2" ON "${tablePrefix}webhook_entity" ("webhookId", "method", "pathLength") `); | ||
await queryRunner.query( | ||
`ALTER TABLE "temporary_webhook_entity" RENAME TO "${tablePrefix}webhook_entity"`, | ||
); | ||
await queryRunner.query( | ||
`CREATE INDEX "IDX_${tablePrefix}742496f199721a057051acf4c2" ON "${tablePrefix}webhook_entity" ("webhookId", "method", "pathLength") `, | ||
); | ||
|
||
logMigrationEnd(this.name); | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> { | ||
const tablePrefix = config.get('database.tablePrefix'); | ||
|
||
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}742496f199721a057051acf4c2"`); | ||
await queryRunner.query(`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`); | ||
await queryRunner.query(`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`); | ||
await queryRunner.query(`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "${tablePrefix}webhook_entity" RENAME TO "temporary_webhook_entity"`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TABLE "${tablePrefix}webhook_entity" ("workflowId" integer NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, PRIMARY KEY ("webhookPath", "method"))`, | ||
); | ||
await queryRunner.query( | ||
`INSERT INTO "${tablePrefix}webhook_entity"("workflowId", "webhookPath", "method", "node") SELECT "workflowId", "webhookPath", "method", "node" FROM "temporary_webhook_entity"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "temporary_webhook_entity"`); | ||
} | ||
} |
Oops, something went wrong.