Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Migration for soft deletions for executions #7088

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was adding createdAt here because we are currently using startedAt incorrectly as createdAt in queue mode, and I wanted to avoid creating 2 separate migrations.
But now that the execution data is in a separate table, perhaps another migration isn't actually going to be that bad. if that's the case, we should also remove the field from the entity.

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 };
Loading