-
-
Notifications
You must be signed in to change notification settings - Fork 495
/
GH4933.test.ts
49 lines (35 loc) · 1.02 KB
/
GH4933.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { MikroORM } from '@mikro-orm/postgresql';
import { Entity, PrimaryKey, ManyToOne, Enum, type Rel } from '@mikro-orm/core';
@Entity({ tableName: 'users', schema: 'example', discriminatorColumn: 'type', abstract: true })
class Base {
@PrimaryKey()
id!: string;
@Enum({ items: ['one', 'two'] })
type!: 'one' | 'two';
}
@Entity({ discriminatorValue: 'one' })
class One extends Base {}
@Entity({ discriminatorValue: 'two' })
class Two extends Base {}
@Entity({ tableName: 'relations' })
class Relation {
@PrimaryKey()
id!: string;
@ManyToOne(() => Two, { deleteRule: 'set null' })
appliedBy?: Rel<Two>;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [One, Two, Base, Relation],
dbName: '4933',
});
await orm.schema.ensureDatabase();
await orm.schema.dropSchema();
});
afterAll(() => orm.close(true));
test('GH #4933', async () => {
const sql = await orm.schema.getCreateSchemaSQL();
expect(sql).toMatchSnapshot();
await orm.schema.execute(sql);
});