Skip to content

Commit

Permalink
feat(core): Migration for soft deletions for executions (#7088)
Browse files Browse the repository at this point in the history
Based on #7065

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
  • Loading branch information
ivov and netroy authored Sep 4, 2023
1 parent 58e55ba commit 413e0bc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/cli/src/databases/entities/ExecutionEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class ExecutionEntity {
@Column({ type: datetimeColumnType, nullable: true })
stoppedAt: Date;

@Column(datetimeColumnType)
deletedAt: Date;

@Column({ nullable: true })
workflowId: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { MigrationContext, ReversibleMigration } from '@/databases/types';

/**
* Add an indexed column `deletedAt` to track soft-deleted executions.
* Add an index on `stoppedAt`, used by executions pruning.
*/
export class ExecutionSoftDelete1693491613982 implements ReversibleMigration {
async up({ schemaBuilder: { addColumns, column, createIndex } }: MigrationContext) {
await addColumns('execution_entity', [column('deletedAt').timestamp()]);
await createIndex('execution_entity', ['deletedAt']);
await createIndex('execution_entity', ['stoppedAt']);
}

async down({ schemaBuilder: { dropColumns, dropIndex } }: MigrationContext) {
await dropIndex('execution_entity', ['stoppedAt']);
await dropIndex('execution_entity', ['deletedAt']);
await dropColumns('execution_entity', ['deletedAt']);
}
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/mysqldb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { RemoveResetPasswordColumns1690000000030 } from '../common/1690000000030
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
import { AddMfaColumns1690000000030 } from './../common/1690000000040-AddMfaColumns';
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
import { ExecutionSoftDelete1693491613982 } from '../common/1693491613982-ExecutionSoftDelete';

export const mysqlMigrations: Migration[] = [
InitialMigration1588157391238,
Expand Down Expand Up @@ -95,4 +96,5 @@ export const mysqlMigrations: Migration[] = [
CreateWorkflowNameIndex1691088862123,
AddMfaColumns1690000000030,
CreateWorkflowHistoryTable1692967111175,
ExecutionSoftDelete1693491613982,
];
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/postgresdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { AddMissingPrimaryKeyOnExecutionData1690787606731 } from './169078760673
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
import { AddMfaColumns1690000000030 } from './../common/1690000000040-AddMfaColumns';
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
import { ExecutionSoftDelete1693491613982 } from '../common/1693491613982-ExecutionSoftDelete';

export const postgresMigrations: Migration[] = [
InitialMigration1587669153312,
Expand Down Expand Up @@ -91,4 +92,5 @@ export const postgresMigrations: Migration[] = [
CreateWorkflowNameIndex1691088862123,
AddMfaColumns1690000000030,
CreateWorkflowHistoryTable1692967111175,
ExecutionSoftDelete1693491613982,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExecutionSoftDelete1693491613982 as BaseMigration } from '../common/1693491613982-ExecutionSoftDelete';

export class ExecutionSoftDelete1693491613982 extends BaseMigration {
transaction = false as const;
}
2 changes: 2 additions & 0 deletions packages/cli/src/databases/migrations/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { RemoveResetPasswordColumns1690000000030 } from './1690000000030-RemoveR
import { CreateWorkflowNameIndex1691088862123 } from '../common/1691088862123-CreateWorkflowNameIndex';
import { AddMfaColumns1690000000030 } from './1690000000040-AddMfaColumns';
import { CreateWorkflowHistoryTable1692967111175 } from '../common/1692967111175-CreateWorkflowHistoryTable';
import { ExecutionSoftDelete1693491613982 } from './1693491613982-ExecutionSoftDelete';

const sqliteMigrations: Migration[] = [
InitialMigration1588102412422,
Expand Down Expand Up @@ -89,6 +90,7 @@ const sqliteMigrations: Migration[] = [
CreateWorkflowNameIndex1691088862123,
AddMfaColumns1690000000030,
CreateWorkflowHistoryTable1692967111175,
ExecutionSoftDelete1693491613982,
];

export { sqliteMigrations };

0 comments on commit 413e0bc

Please sign in to comment.