mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
wip: Create table test_entity, add typeorm entity
This commit is contained in:
parent
5c69ba2c44
commit
59af12ec6c
44
packages/cli/src/databases/entities/test-entity.ts
Normal file
44
packages/cli/src/databases/entities/test-entity.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
Column,
|
||||
Entity,
|
||||
Generated,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToOne,
|
||||
PrimaryColumn,
|
||||
RelationId,
|
||||
} from '@n8n/typeorm';
|
||||
import { Length } from 'class-validator';
|
||||
|
||||
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
|
||||
import { WorkflowEntity } from '@/databases/entities/workflow-entity';
|
||||
|
||||
import { WithTimestamps } from './abstract-entity';
|
||||
|
||||
@Entity()
|
||||
@Index(['workflow'])
|
||||
@Index(['evaluationWorkflow'])
|
||||
export class TestEntity extends WithTimestamps {
|
||||
@Generated()
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ length: 255 })
|
||||
@Length(1, 255, { message: 'Test name must be $constraint1 to $constraint2 characters long.' })
|
||||
name: string;
|
||||
|
||||
@RelationId((test: TestEntity) => test.workflow)
|
||||
workflowId: number;
|
||||
|
||||
@ManyToOne('WorkflowEntity', 'tests')
|
||||
workflow: WorkflowEntity;
|
||||
|
||||
@RelationId((test: TestEntity) => test.evaluationWorkflow)
|
||||
evaluationWorkflowId: number;
|
||||
|
||||
@ManyToOne('WorkflowEntity', 'evaluationTests')
|
||||
evaluationWorkflow: WorkflowEntity;
|
||||
|
||||
@OneToOne('AnnotationTagEntity', 'test')
|
||||
annotationTag: AnnotationTagEntity;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
import type { MigrationContext, ReversibleMigration } from '@/databases/types';
|
||||
|
||||
const testEntityTableName = 'test_entity';
|
||||
|
||||
export class CreateTestEntityTable1730386903556 implements ReversibleMigration {
|
||||
async up({ schemaBuilder: { createTable, column } }: MigrationContext) {
|
||||
await createTable(testEntityTableName)
|
||||
.withColumns(
|
||||
column('id').int.notNull.primary.autoGenerate,
|
||||
column('name').varchar(255).notNull,
|
||||
column('workflowId').int.notNull,
|
||||
column('evaluationWorkflowId').int,
|
||||
column('annotationTagId').varchar(16),
|
||||
)
|
||||
.withIndexOn('workflowId')
|
||||
.withIndexOn('evaluationWorkflowId')
|
||||
.withForeignKey('workflowId', {
|
||||
tableName: 'workflow_entity',
|
||||
columnName: 'id',
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
.withForeignKey('evaluationWorkflowId', {
|
||||
tableName: 'workflow_entity',
|
||||
columnName: 'id',
|
||||
})
|
||||
.withForeignKey('annotationTagId', {
|
||||
tableName: 'annotation_tag_entity',
|
||||
columnName: 'id',
|
||||
}).withTimestamps;
|
||||
}
|
||||
|
||||
async down({ schemaBuilder: { dropTable } }: MigrationContext) {
|
||||
await dropTable(testEntityTableName);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue