Files
Automata/packages/cli/src/databases/migrations/sqlite/1664196174000-WorkflowStatistics.ts
freya 1722c6b0c5 feat(core): Workflow Execution Statistics (#4200)
Add recording and reporting of workflow execution statistics
2022-12-06 14:55:40 +00:00

41 lines
1.3 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
import { logMigrationEnd, logMigrationStart } from '../../utils/migrationHelpers';
import config from '@/config';
export class WorkflowStatistics1664196174000 implements MigrationInterface {
name = 'WorkflowStatistics1664196174000';
async up(queryRunner: QueryRunner): Promise<void> {
logMigrationStart(this.name);
const tablePrefix = config.getEnv('database.tablePrefix');
await queryRunner.query(
`CREATE TABLE \`${tablePrefix}workflow_statistics\` (
"count" INTEGER DEFAULT 0,
"latestEvent" DATETIME,
"name" VARCHAR(128) NOT NULL,
"workflowId" INTEGER,
PRIMARY KEY("workflowId", "name"),
FOREIGN KEY("workflowId") REFERENCES \`${tablePrefix}workflow_entity\`("id") ON DELETE CASCADE
)`,
);
// Add dataLoaded column to workflow table
await queryRunner.query(
`ALTER TABLE \`${tablePrefix}workflow_entity\` ADD COLUMN "dataLoaded" BOOLEAN DEFAULT false`,
);
logMigrationEnd(this.name);
}
async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.getEnv('database.tablePrefix');
await queryRunner.query(`DROP TABLE "${tablePrefix}workflow_statistics"`);
await queryRunner.query(
`ALTER TABLE \`${tablePrefix}workflow_entity\` DROP COLUMN "dataLoaded"`,
);
}
}