diff --git a/packages/cli/src/databases/entities/test-entity.ts b/packages/cli/src/databases/entities/test-entity.ts new file mode 100644 index 0000000000..8d66b6a9e6 --- /dev/null +++ b/packages/cli/src/databases/entities/test-entity.ts @@ -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; +} diff --git a/packages/cli/src/databases/migrations/common/1730386903556-CreateTestEntityTable.ts b/packages/cli/src/databases/migrations/common/1730386903556-CreateTestEntityTable.ts new file mode 100644 index 0000000000..233dc1c3e7 --- /dev/null +++ b/packages/cli/src/databases/migrations/common/1730386903556-CreateTestEntityTable.ts @@ -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); + } +}