-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
GH4919.test.ts
66 lines (48 loc) · 1.28 KB
/
GH4919.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { MikroORM } from '@mikro-orm/postgresql';
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
@Entity({ tableName: 'user' })
class User0 {
@PrimaryKey()
id!: number;
@Property()
deliveredAt!: Date;
}
@Entity({ tableName: 'user' })
class User1 {
@PrimaryKey()
id!: number;
@Property()
completedAt!: Date;
@Property()
canceledAt!: Date;
@Property()
arrivedAt!: Date;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [User0],
dbName: 'mikro_orm_test_gh_4919',
});
await orm.schema.ensureDatabase();
await orm.schema.dropSchema();
});
afterAll(() => orm.close(true));
test('GH #4919', async () => {
const testMigration = async (e1: any, e2: any, snap: string) => {
if (e2) {
orm.getMetadata().reset(e1.name);
await orm.discoverEntity(e2);
}
const diff = await orm.schema.getUpdateSchemaMigrationSQL({ wrap: false });
expect(diff).toMatchSnapshot(snap);
await orm.schema.execute(diff.up);
return diff.down;
};
const down: string[] = [];
down.push(await testMigration(User0, undefined, '0. create schema'));
down.push(await testMigration(User0, User1, '1. rename column'));
for (const sql of down.reverse()) {
await orm.schema.execute(sql);
}
});