Add entity

This commit is contained in:
Charlie Kolb 2025-11-17 17:11:42 +01:00
parent 4ce78619ee
commit f96086d3c7
No known key found for this signature in database
3 changed files with 33 additions and 9 deletions

View File

@ -0,0 +1,27 @@
import { Column, Entity, Index, JoinColumn, ManyToOne } from '@n8n/typeorm';
import { WithCreatedAt } from './abstract-entity';
import { WorkflowEntity } from './workflow-entity';
@Entity()
@Index(['workflowId', 'versionId'])
@Index(['workflowId', 'versionId', 'createdAt'], { unique: true })
export class WorkflowPublishHistory extends WithCreatedAt {
@Column()
workflowId: string;
@Column()
versionId: string;
@Column()
status: 'activated' | 'deactivated';
@ManyToOne('WorkflowEntity', {
onDelete: 'CASCADE',
})
@JoinColumn({
foreignKeyConstraintName: 'id',
referencedColumnName: 'workflowId',
})
workflow: WorkflowEntity;
}

View File

@ -3,14 +3,14 @@ import type { MigrationContext, ReversibleMigration } from '../migration-types';
const workflowPublishHistoryTableName = 'workflow_publish_history';
export class CreateWorkflowPublishHistoryTable1763387043735 implements ReversibleMigration {
async up({ schemaBuilder: { createTable, column }, runQuery }: MigrationContext) {
async up({ schemaBuilder: { createTable, column }, runQuery, escape }: MigrationContext) {
await createTable(workflowPublishHistoryTableName)
.withColumns(
column('workflowId').varchar(36).notNull,
column('versionId').varchar(36).notNull,
column('status').varchar(36).notNull,
)
.withUpdatedAt.withForeignKey('workflowId', {
.withCreatedAt.withForeignKey('workflowId', {
tableName: 'workflow_entity',
columnName: 'id',
onDelete: 'CASCADE',
@ -20,11 +20,13 @@ export class CreateWorkflowPublishHistoryTable1763387043735 implements Reversibl
columnName: 'versionId',
onDelete: 'CASCADE',
})
.withUniqueConstraintOn(['workflowId', 'versionId'])
.withUniqueConstraintOn(['workflowId', 'versionId', 'updatedAt'])
.withIndexOn(['workflowId', 'versionId']);
const workflowEntityTableName = escape.tableName('workflow_entity');
const activeWorkflows = await runQuery<Array<{ id: string; versionId: string }>>(
'SELECT we.id, we.versionId FROM workflow_entity we WHERE we.active;',
`SELECT we.id, we.versionId FROM ${workflowEntityTableName} we WHERE we.active;`,
);
console.log(activeWorkflows);

View File

@ -46,11 +46,6 @@ export class CreateTable extends TableOperation {
return this;
}
get withUpdatedAt() {
this.columns.push(new Column('updatedAt').timestampTimezone().notNull.default('NOW()'));
return this;
}
withIndexOn(columnName: string | string[], isUnique = false) {
const columnNames = Array.isArray(columnName) ? columnName : [columnName];
this.indices.add({ columnNames, isUnique });