mirror of
https://github.com/n8n-io/n8n.git
synced 2025-11-20 17:46:34 +00:00
Add entity
This commit is contained in:
parent
4ce78619ee
commit
f96086d3c7
27
packages/@n8n/db/src/entities/workflow-publish-history.ts
Normal file
27
packages/@n8n/db/src/entities/workflow-publish-history.ts
Normal 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;
|
||||
}
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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 });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user