-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
chore: Create table and typeorm entity for tests (no-changelog) #11505
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't he |
||
|
||
@ManyToOne('WorkflowEntity', 'tests') | ||
workflow: WorkflowEntity; | ||
|
||
@RelationId((test: TestEntity) => test.evaluationWorkflow) | ||
evaluationWorkflowId: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well, shouldn't it be string? |
||
|
||
@ManyToOne('WorkflowEntity', 'evaluationTests') | ||
evaluationWorkflow: WorkflowEntity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have some documentation what this relation means? |
||
|
||
@OneToOne('AnnotationTagEntity', 'test') | ||
annotationTag: AnnotationTagEntity; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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').varchar(36).notNull, | ||
column('evaluationWorkflowId').varchar(36), | ||
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; | ||
Comment on lines
+22
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it intentional that these don't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two references are nullable, and we don't want to delete a test when an evaluation workflow or specific annotation tag being deleted. So the right setting should be |
||
} | ||
|
||
async down({ schemaBuilder: { dropTable } }: MigrationContext) { | ||
await dropTable(testEntityTableName); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test is very overloaded term. Could we use something more specific? E.g.
WorkflowTest
? Also could we add a short description for this entityThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what we should name this, but I'm certain that calling this
Test*
would be confusing for many people.Even
WorkflowTest
is overloaded, as it can already either refer to the special test type we havenodes-base
, as well as the test-workflows repo.