-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
Migrator.postgres.test.ts.snap
779 lines (666 loc) · 64.9 KB
/
Migrator.postgres.test.ts.snap
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Migrator (postgres) generate initial migration: initial-migration-dump 1`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('create schema if not exists "custom";');
this.addSql('create table "custom"."book_tag2" ("id" bigserial primary key, "name" varchar(50) not null);');
this.addSql('create table "custom"."foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3));');
this.addSql('create table "custom"."foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "name with space" varchar(255) null, "baz_id" int null, "foo_bar_id" int null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object_property" jsonb null);');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id");');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id");');
this.addSql('create table "custom"."foo_param2" ("bar_id" int not null, "baz_id" int not null, "value" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3), constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"));');
this.addSql('create table "custom"."publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in (\\'local\\', \\'global\\')) not null, "type2" text check ("type2" in (\\'LOCAL\\', \\'GLOBAL\\')) not null, "enum1" smallint null, "enum2" smallint null, "enum3" smallint null, "enum4" text check ("enum4" in (\\'a\\', \\'b\\', \\'c\\')) null, "enum5" text check ("enum5" in (\\'a\\')) null);');
this.addSql('create table "custom"."author2" ("id" serial primary key, "created_at" timestamptz(3) not null default current_timestamp(3), "updated_at" timestamptz(3) not null default current_timestamp(3), "name" varchar(255) not null, "email" varchar(255) not null, "age" int null default null, "terms_accepted" boolean not null default false, "optional" boolean null, "identities" text[] null, "born" date null, "born_time" time(0) null, "favourite_book_uuid_pk" uuid null, "favourite_author_id" int null);');
this.addSql('create index "custom_email_index_name" on "custom"."author2" ("email");');
this.addSql('alter table "custom"."author2" add constraint "custom_email_unique_name" unique ("email");');
this.addSql('create index "author2_terms_accepted_index" on "custom"."author2" ("terms_accepted");');
this.addSql('create index "author2_born_index" on "custom"."author2" ("born");');
this.addSql('create index "born_time_idx" on "custom"."author2" ("born_time");');
this.addSql('create index "custom_idx_name_123" on "custom"."author2" ("name");');
this.addSql('create index "author2_name_age_index" on "custom"."author2" ("name", "age");');
this.addSql('alter table "custom"."author2" add constraint "author2_name_email_unique" unique ("name", "email");');
this.addSql('create table "custom"."book2" ("uuid_pk" uuid not null, "created_at" timestamptz(3) not null default current_timestamp(3), "title" varchar(255) null default \\'\\', "perex" text null, "price" numeric(8,2) null, "double" double precision null, "meta" jsonb null, "author_id" int not null, "publisher_id" int null, constraint "book2_pkey" primary key ("uuid_pk"));');
this.addSql('create index "book2_title_index" on "custom"."book2" using gin(to_tsvector(\\'simple\\', "title"));');
this.addSql('create table "custom"."book2_tags" ("order" serial primary key, "book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null);');
this.addSql('create table "custom"."book_to_tag_unordered" ("book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null, constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"));');
this.addSql('create table "custom"."author2_following" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author2_following_pkey" primary key ("author2_1_id", "author2_2_id"));');
this.addSql('create table "custom"."author_to_friend" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author_to_friend_pkey" primary key ("author2_1_id", "author2_2_id"));');
this.addSql('create table "custom"."address2" ("author_id" int not null, "value" varchar(255) not null, constraint "address2_pkey" primary key ("author_id"));');
this.addSql('comment on table "custom"."address2" is \\'This is address table\\';');
this.addSql('comment on column "custom"."address2"."value" is \\'This is address property\\';');
this.addSql('create table "custom"."test2" ("id" serial primary key, "name" varchar(255) null, "book_uuid_pk" uuid null, "parent_id" int null, "version" int not null default 1);');
this.addSql('alter table "custom"."test2" add constraint "test2_book_uuid_pk_unique" unique ("book_uuid_pk");');
this.addSql('create table "custom"."publisher2_tests" ("id" serial primary key, "publisher2_id" int not null, "test2_id" int not null);');
this.addSql('create table "custom"."configuration2" ("property" varchar(255) not null, "test_id" int not null, "value" varchar(255) not null, constraint "configuration2_pkey" primary key ("property", "test_id"));');
this.addSql('create table "custom"."test2_bars" ("test2_id" int not null, "foo_bar2_id" int not null, constraint "test2_bars_pkey" primary key ("test2_id", "foo_bar2_id"));');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "custom"."foo_bar2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "custom"."foo_bar2" ("id") on update cascade;');
this.addSql('alter table "custom"."foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade;');
this.addSql('alter table "custom"."author2" add constraint "author2_favourite_book_uuid_pk_foreign" foreign key ("favourite_book_uuid_pk") references "custom"."book2" ("uuid_pk") on update no action on delete cascade;');
this.addSql('alter table "custom"."author2" add constraint "author2_favourite_author_id_foreign" foreign key ("favourite_author_id") references "custom"."author2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."book2" add constraint "book2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id");');
this.addSql('alter table "custom"."book2" add constraint "book2_publisher_id_foreign" foreign key ("publisher_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."address2" add constraint "address2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."test2" add constraint "test2_book_uuid_pk_foreign" foreign key ("book_uuid_pk") references "custom"."book2" ("uuid_pk") on delete set null;');
this.addSql('alter table "custom"."test2" add constraint "test2_parent_id_foreign" foreign key ("parent_id") references "custom"."test2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."configuration2" add constraint "configuration2_test_id_foreign" foreign key ("test_id") references "custom"."test2" ("id") on update cascade;');
this.addSql('alter table "custom"."test2_bars" add constraint "test2_bars_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."test2_bars" add constraint "test2_bars_foo_bar2_id_foreign" foreign key ("foo_bar2_id") references "custom"."foo_bar2" ("id") on update cascade on delete cascade;');
}
}
",
"diff": {
"down": [],
"up": [
"create schema if not exists "custom";",
"",
"create table "custom"."book_tag2" ("id" bigserial primary key, "name" varchar(50) not null);",
"",
"create table "custom"."foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3));",
"",
"create table "custom"."foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "name with space" varchar(255) null, "baz_id" int null, "foo_bar_id" int null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object_property" jsonb null);",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id");",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id");",
"",
"create table "custom"."foo_param2" ("bar_id" int not null, "baz_id" int not null, "value" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3), constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"));",
"",
"create table "custom"."publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in ('local', 'global')) not null, "type2" text check ("type2" in ('LOCAL', 'GLOBAL')) not null, "enum1" smallint null, "enum2" smallint null, "enum3" smallint null, "enum4" text check ("enum4" in ('a', 'b', 'c')) null, "enum5" text check ("enum5" in ('a')) null);",
"",
"create table "custom"."author2" ("id" serial primary key, "created_at" timestamptz(3) not null default current_timestamp(3), "updated_at" timestamptz(3) not null default current_timestamp(3), "name" varchar(255) not null, "email" varchar(255) not null, "age" int null default null, "terms_accepted" boolean not null default false, "optional" boolean null, "identities" text[] null, "born" date null, "born_time" time(0) null, "favourite_book_uuid_pk" uuid null, "favourite_author_id" int null);",
"create index "custom_email_index_name" on "custom"."author2" ("email");",
"alter table "custom"."author2" add constraint "custom_email_unique_name" unique ("email");",
"create index "author2_terms_accepted_index" on "custom"."author2" ("terms_accepted");",
"create index "author2_born_index" on "custom"."author2" ("born");",
"create index "born_time_idx" on "custom"."author2" ("born_time");",
"create index "custom_idx_name_123" on "custom"."author2" ("name");",
"create index "author2_name_age_index" on "custom"."author2" ("name", "age");",
"alter table "custom"."author2" add constraint "author2_name_email_unique" unique ("name", "email");",
"",
"create table "custom"."book2" ("uuid_pk" uuid not null, "created_at" timestamptz(3) not null default current_timestamp(3), "title" varchar(255) null default '', "perex" text null, "price" numeric(8,2) null, "double" double precision null, "meta" jsonb null, "author_id" int not null, "publisher_id" int null, constraint "book2_pkey" primary key ("uuid_pk"));",
"create index "book2_title_index" on "custom"."book2" using gin(to_tsvector('simple', "title"));",
"",
"create table "custom"."book2_tags" ("order" serial primary key, "book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null);",
"",
"create table "custom"."book_to_tag_unordered" ("book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null, constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"));",
"",
"create table "custom"."author2_following" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author2_following_pkey" primary key ("author2_1_id", "author2_2_id"));",
"",
"create table "custom"."author_to_friend" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author_to_friend_pkey" primary key ("author2_1_id", "author2_2_id"));",
"",
"create table "custom"."address2" ("author_id" int not null, "value" varchar(255) not null, constraint "address2_pkey" primary key ("author_id"));",
"comment on table "custom"."address2" is 'This is address table';",
"comment on column "custom"."address2"."value" is 'This is address property';",
"",
"create table "custom"."test2" ("id" serial primary key, "name" varchar(255) null, "book_uuid_pk" uuid null, "parent_id" int null, "version" int not null default 1);",
"alter table "custom"."test2" add constraint "test2_book_uuid_pk_unique" unique ("book_uuid_pk");",
"",
"create table "custom"."publisher2_tests" ("id" serial primary key, "publisher2_id" int not null, "test2_id" int not null);",
"",
"create table "custom"."configuration2" ("property" varchar(255) not null, "test_id" int not null, "value" varchar(255) not null, constraint "configuration2_pkey" primary key ("property", "test_id"));",
"",
"create table "custom"."test2_bars" ("test2_id" int not null, "foo_bar2_id" int not null, constraint "test2_bars_pkey" primary key ("test2_id", "foo_bar2_id"));",
"",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade on delete set null;",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "custom"."foo_bar2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "custom"."foo_bar2" ("id") on update cascade;",
"alter table "custom"."foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade;",
"",
"alter table "custom"."author2" add constraint "author2_favourite_book_uuid_pk_foreign" foreign key ("favourite_book_uuid_pk") references "custom"."book2" ("uuid_pk") on update no action on delete cascade;",
"alter table "custom"."author2" add constraint "author2_favourite_author_id_foreign" foreign key ("favourite_author_id") references "custom"."author2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."book2" add constraint "book2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id");",
"alter table "custom"."book2" add constraint "book2_publisher_id_foreign" foreign key ("publisher_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;",
"alter table "custom"."book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;",
"alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"alter table "custom"."author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."address2" add constraint "address2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."test2" add constraint "test2_book_uuid_pk_foreign" foreign key ("book_uuid_pk") references "custom"."book2" ("uuid_pk") on delete set null;",
"alter table "custom"."test2" add constraint "test2_parent_id_foreign" foreign key ("parent_id") references "custom"."test2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;",
"alter table "custom"."publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."configuration2" add constraint "configuration2_test_id_foreign" foreign key ("test_id") references "custom"."test2" ("id") on update cascade;",
"",
"alter table "custom"."test2_bars" add constraint "test2_bars_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;",
"alter table "custom"."test2_bars" add constraint "test2_bars_foo_bar2_id_foreign" foreign key ("foo_bar2_id") references "custom"."foo_bar2" ("id") on update cascade on delete cascade;",
],
},
"fileName": "Migration20191013214813.ts",
}
`;
exports[`Migrator (postgres) generate initial migration: initial-migration-dump 2`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('create schema if not exists "custom";');
this.addSql('create table "custom"."book_tag2" ("id" bigserial primary key, "name" varchar(50) not null);');
this.addSql('create table "custom"."foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3));');
this.addSql('create table "custom"."foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "name with space" varchar(255) null, "baz_id" int null, "foo_bar_id" int null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object_property" jsonb null);');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id");');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id");');
this.addSql('create table "custom"."foo_param2" ("bar_id" int not null, "baz_id" int not null, "value" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3), constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"));');
this.addSql('create table "custom"."publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in (\\'local\\', \\'global\\')) not null, "type2" text check ("type2" in (\\'LOCAL\\', \\'GLOBAL\\')) not null, "enum1" smallint null, "enum2" smallint null, "enum3" smallint null, "enum4" text check ("enum4" in (\\'a\\', \\'b\\', \\'c\\')) null, "enum5" text check ("enum5" in (\\'a\\')) null);');
this.addSql('create table "custom"."author2" ("id" serial primary key, "created_at" timestamptz(3) not null default current_timestamp(3), "updated_at" timestamptz(3) not null default current_timestamp(3), "name" varchar(255) not null, "email" varchar(255) not null, "age" int null default null, "terms_accepted" boolean not null default false, "optional" boolean null, "identities" text[] null, "born" date null, "born_time" time(0) null, "favourite_book_uuid_pk" uuid null, "favourite_author_id" int null);');
this.addSql('create index "custom_email_index_name" on "custom"."author2" ("email");');
this.addSql('alter table "custom"."author2" add constraint "custom_email_unique_name" unique ("email");');
this.addSql('create index "author2_terms_accepted_index" on "custom"."author2" ("terms_accepted");');
this.addSql('create index "author2_born_index" on "custom"."author2" ("born");');
this.addSql('create index "born_time_idx" on "custom"."author2" ("born_time");');
this.addSql('create index "custom_idx_name_123" on "custom"."author2" ("name");');
this.addSql('create index "author2_name_age_index" on "custom"."author2" ("name", "age");');
this.addSql('alter table "custom"."author2" add constraint "author2_name_email_unique" unique ("name", "email");');
this.addSql('create table "custom"."book2" ("uuid_pk" uuid not null, "created_at" timestamptz(3) not null default current_timestamp(3), "title" varchar(255) null default \\'\\', "perex" text null, "price" numeric(8,2) null, "double" double precision null, "meta" jsonb null, "author_id" int not null, "publisher_id" int null, constraint "book2_pkey" primary key ("uuid_pk"));');
this.addSql('create index "book2_title_index" on "custom"."book2" using gin(to_tsvector(\\'simple\\', "title"));');
this.addSql('create table "custom"."book2_tags" ("order" serial primary key, "book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null);');
this.addSql('create table "custom"."book_to_tag_unordered" ("book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null, constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"));');
this.addSql('create table "custom"."author2_following" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author2_following_pkey" primary key ("author2_1_id", "author2_2_id"));');
this.addSql('create table "custom"."author_to_friend" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author_to_friend_pkey" primary key ("author2_1_id", "author2_2_id"));');
this.addSql('create table "custom"."address2" ("author_id" int not null, "value" varchar(255) not null, constraint "address2_pkey" primary key ("author_id"));');
this.addSql('comment on table "custom"."address2" is \\'This is address table\\';');
this.addSql('comment on column "custom"."address2"."value" is \\'This is address property\\';');
this.addSql('create table "custom"."test2" ("id" serial primary key, "name" varchar(255) null, "book_uuid_pk" uuid null, "parent_id" int null, "version" int not null default 1);');
this.addSql('alter table "custom"."test2" add constraint "test2_book_uuid_pk_unique" unique ("book_uuid_pk");');
this.addSql('create table "custom"."publisher2_tests" ("id" serial primary key, "publisher2_id" int not null, "test2_id" int not null);');
this.addSql('create table "custom"."configuration2" ("property" varchar(255) not null, "test_id" int not null, "value" varchar(255) not null, constraint "configuration2_pkey" primary key ("property", "test_id"));');
this.addSql('create table "custom"."test2_bars" ("test2_id" int not null, "foo_bar2_id" int not null, constraint "test2_bars_pkey" primary key ("test2_id", "foo_bar2_id"));');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "custom"."foo_bar2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "custom"."foo_bar2" ("id") on update cascade;');
this.addSql('alter table "custom"."foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade;');
this.addSql('alter table "custom"."author2" add constraint "author2_favourite_book_uuid_pk_foreign" foreign key ("favourite_book_uuid_pk") references "custom"."book2" ("uuid_pk") on update no action on delete cascade;');
this.addSql('alter table "custom"."author2" add constraint "author2_favourite_author_id_foreign" foreign key ("favourite_author_id") references "custom"."author2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."book2" add constraint "book2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id");');
this.addSql('alter table "custom"."book2" add constraint "book2_publisher_id_foreign" foreign key ("publisher_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;');
this.addSql('alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."address2" add constraint "address2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."test2" add constraint "test2_book_uuid_pk_foreign" foreign key ("book_uuid_pk") references "custom"."book2" ("uuid_pk") on delete set null;');
this.addSql('alter table "custom"."test2" add constraint "test2_parent_id_foreign" foreign key ("parent_id") references "custom"."test2" ("id") on update cascade on delete set null;');
this.addSql('alter table "custom"."publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."configuration2" add constraint "configuration2_test_id_foreign" foreign key ("test_id") references "custom"."test2" ("id") on update cascade;');
this.addSql('alter table "custom"."test2_bars" add constraint "test2_bars_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;');
this.addSql('alter table "custom"."test2_bars" add constraint "test2_bars_foo_bar2_id_foreign" foreign key ("foo_bar2_id") references "custom"."foo_bar2" ("id") on update cascade on delete cascade;');
}
}
",
"diff": {
"down": [],
"up": [
"create schema if not exists "custom";",
"",
"create table "custom"."book_tag2" ("id" bigserial primary key, "name" varchar(50) not null);",
"",
"create table "custom"."foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3));",
"",
"create table "custom"."foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "name with space" varchar(255) null, "baz_id" int null, "foo_bar_id" int null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object_property" jsonb null);",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id");",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id");",
"",
"create table "custom"."foo_param2" ("bar_id" int not null, "baz_id" int not null, "value" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3), constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"));",
"",
"create table "custom"."publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in ('local', 'global')) not null, "type2" text check ("type2" in ('LOCAL', 'GLOBAL')) not null, "enum1" smallint null, "enum2" smallint null, "enum3" smallint null, "enum4" text check ("enum4" in ('a', 'b', 'c')) null, "enum5" text check ("enum5" in ('a')) null);",
"",
"create table "custom"."author2" ("id" serial primary key, "created_at" timestamptz(3) not null default current_timestamp(3), "updated_at" timestamptz(3) not null default current_timestamp(3), "name" varchar(255) not null, "email" varchar(255) not null, "age" int null default null, "terms_accepted" boolean not null default false, "optional" boolean null, "identities" text[] null, "born" date null, "born_time" time(0) null, "favourite_book_uuid_pk" uuid null, "favourite_author_id" int null);",
"create index "custom_email_index_name" on "custom"."author2" ("email");",
"alter table "custom"."author2" add constraint "custom_email_unique_name" unique ("email");",
"create index "author2_terms_accepted_index" on "custom"."author2" ("terms_accepted");",
"create index "author2_born_index" on "custom"."author2" ("born");",
"create index "born_time_idx" on "custom"."author2" ("born_time");",
"create index "custom_idx_name_123" on "custom"."author2" ("name");",
"create index "author2_name_age_index" on "custom"."author2" ("name", "age");",
"alter table "custom"."author2" add constraint "author2_name_email_unique" unique ("name", "email");",
"",
"create table "custom"."book2" ("uuid_pk" uuid not null, "created_at" timestamptz(3) not null default current_timestamp(3), "title" varchar(255) null default '', "perex" text null, "price" numeric(8,2) null, "double" double precision null, "meta" jsonb null, "author_id" int not null, "publisher_id" int null, constraint "book2_pkey" primary key ("uuid_pk"));",
"create index "book2_title_index" on "custom"."book2" using gin(to_tsvector('simple', "title"));",
"",
"create table "custom"."book2_tags" ("order" serial primary key, "book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null);",
"",
"create table "custom"."book_to_tag_unordered" ("book2_uuid_pk" uuid not null, "book_tag2_id" bigint not null, constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"));",
"",
"create table "custom"."author2_following" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author2_following_pkey" primary key ("author2_1_id", "author2_2_id"));",
"",
"create table "custom"."author_to_friend" ("author2_1_id" int not null, "author2_2_id" int not null, constraint "author_to_friend_pkey" primary key ("author2_1_id", "author2_2_id"));",
"",
"create table "custom"."address2" ("author_id" int not null, "value" varchar(255) not null, constraint "address2_pkey" primary key ("author_id"));",
"comment on table "custom"."address2" is 'This is address table';",
"comment on column "custom"."address2"."value" is 'This is address property';",
"",
"create table "custom"."test2" ("id" serial primary key, "name" varchar(255) null, "book_uuid_pk" uuid null, "parent_id" int null, "version" int not null default 1);",
"alter table "custom"."test2" add constraint "test2_book_uuid_pk_unique" unique ("book_uuid_pk");",
"",
"create table "custom"."publisher2_tests" ("id" serial primary key, "publisher2_id" int not null, "test2_id" int not null);",
"",
"create table "custom"."configuration2" ("property" varchar(255) not null, "test_id" int not null, "value" varchar(255) not null, constraint "configuration2_pkey" primary key ("property", "test_id"));",
"",
"create table "custom"."test2_bars" ("test2_id" int not null, "foo_bar2_id" int not null, constraint "test2_bars_pkey" primary key ("test2_id", "foo_bar2_id"));",
"",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade on delete set null;",
"alter table "custom"."foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "custom"."foo_bar2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "custom"."foo_bar2" ("id") on update cascade;",
"alter table "custom"."foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "custom"."foo_baz2" ("id") on update cascade;",
"",
"alter table "custom"."author2" add constraint "author2_favourite_book_uuid_pk_foreign" foreign key ("favourite_book_uuid_pk") references "custom"."book2" ("uuid_pk") on update no action on delete cascade;",
"alter table "custom"."author2" add constraint "author2_favourite_author_id_foreign" foreign key ("favourite_author_id") references "custom"."author2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."book2" add constraint "book2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id");",
"alter table "custom"."book2" add constraint "book2_publisher_id_foreign" foreign key ("publisher_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;",
"alter table "custom"."book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "custom"."book2" ("uuid_pk") on update cascade on delete cascade;",
"alter table "custom"."book_to_tag_unordered" add constraint "book_to_tag_unordered_book_tag2_id_foreign" foreign key ("book_tag2_id") references "custom"."book_tag2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"alter table "custom"."author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"alter table "custom"."author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."address2" add constraint "address2_author_id_foreign" foreign key ("author_id") references "custom"."author2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."test2" add constraint "test2_book_uuid_pk_foreign" foreign key ("book_uuid_pk") references "custom"."book2" ("uuid_pk") on delete set null;",
"alter table "custom"."test2" add constraint "test2_parent_id_foreign" foreign key ("parent_id") references "custom"."test2" ("id") on update cascade on delete set null;",
"",
"alter table "custom"."publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "custom"."publisher2" ("id") on update cascade on delete cascade;",
"alter table "custom"."publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;",
"",
"alter table "custom"."configuration2" add constraint "configuration2_test_id_foreign" foreign key ("test_id") references "custom"."test2" ("id") on update cascade;",
"",
"alter table "custom"."test2_bars" add constraint "test2_bars_test2_id_foreign" foreign key ("test2_id") references "custom"."test2" ("id") on update cascade on delete cascade;",
"alter table "custom"."test2_bars" add constraint "test2_bars_foo_bar2_id_foreign" foreign key ("foo_bar2_id") references "custom"."foo_bar2" ("id") on update cascade on delete cascade;",
],
},
"fileName": "Migration20191013214813.ts",
}
`;
exports[`Migrator (postgres) generate js schema migration: migration-js-dump 1`] = `
{
"code": "'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const { Migration } = require('@mikro-orm/migrations');
class Migration20191013214813 extends Migration {
async up() {
this.addSql('alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);');
this.addSql('alter table "custom"."book2" drop column "foo";');
this.addSql('alter table "custom"."test2" drop column "path";');
}
async down() {
this.addSql('alter table "custom"."book2" add column "foo" varchar null default \\'lol\\';');
this.addSql('alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);');
this.addSql('alter table "custom"."test2" add column "path" polygon null default null;');
}
}
exports.Migration20191013214813 = Migration20191013214813;
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "Migration20191013214813.js",
}
`;
exports[`Migrator (postgres) generate migration with custom migrator: migration-ts-dump 1`] = `
{
"code": "// this file was generated via custom migration generator
import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('alter table
"custom"."book2"
alter column
"double" type double precision using ("double" :: double precision);');
this.addSql('alter table
"custom"."book2" drop column "foo";');
this.addSql('alter table
"custom"."test2" drop column "path";');
}
async down(): Promise<void> {
this.addSql('alter table
"custom"."book2"
add
column "foo" varchar null default \\'lol\\';');
this.addSql('alter table
"custom"."book2"
alter column
"double" type numeric using ("double" :: numeric);');
this.addSql('alter table
"custom"."test2"
add
column "path" polygon null default null;');
}
}
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "Migration20191013214813.ts",
}
`;
exports[`Migrator (postgres) generate migration with custom name with name option: migration-dump 1`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);');
this.addSql('alter table "custom"."book2" drop column "foo";');
this.addSql('alter table "custom"."test2" drop column "path";');
}
async down(): Promise<void> {
this.addSql('alter table "custom"."book2" add column "foo" varchar null default \\'lol\\';');
this.addSql('alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);');
this.addSql('alter table "custom"."test2" add column "path" polygon null default null;');
}
}
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "migration20191013214813_custom_name.ts",
}
`;
exports[`Migrator (postgres) generate migration with custom name: migration-dump 1`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);');
this.addSql('alter table "custom"."book2" drop column "foo";');
this.addSql('alter table "custom"."test2" drop column "path";');
}
async down(): Promise<void> {
this.addSql('alter table "custom"."book2" add column "foo" varchar null default \\'lol\\';');
this.addSql('alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);');
this.addSql('alter table "custom"."test2" add column "path" polygon null default null;');
}
}
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "migration-20191013214813.ts",
}
`;
exports[`Migrator (postgres) generate migration with snapshot: migration-snapshot-dump-1 1`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);');
this.addSql('alter table "custom"."book2" drop column "foo";');
this.addSql('alter table "custom"."test2" drop column "path";');
}
async down(): Promise<void> {
this.addSql('alter table "custom"."book2" add column "foo" varchar null default \\'lol\\';');
this.addSql('alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);');
this.addSql('alter table "custom"."test2" add column "path" polygon null default null;');
}
}
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "Migration20191013214813.ts",
}
`;
exports[`Migrator (postgres) generate migration with snapshot: migration-snapshot-dump-2 1`] = `
{
"code": "",
"diff": {
"down": [],
"up": [],
},
"fileName": "",
}
`;
exports[`Migrator (postgres) generate schema migration: migration-dump 1`] = `
{
"code": "import { Migration } from '@mikro-orm/migrations';
export class Migration20191013214813 extends Migration {
async up(): Promise<void> {
this.addSql('alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);');
this.addSql('alter table "custom"."book2" drop column "foo";');
this.addSql('alter table "custom"."test2" drop column "path";');
}
async down(): Promise<void> {
this.addSql('alter table "custom"."book2" add column "foo" varchar null default \\'lol\\';');
this.addSql('alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);');
this.addSql('alter table "custom"."test2" add column "path" polygon null default null;');
}
}
",
"diff": {
"down": [
"alter table "custom"."book2" add column "foo" varchar null default 'lol';",
"alter table "custom"."book2" alter column "double" type numeric using ("double"::numeric);",
"",
"alter table "custom"."test2" add column "path" polygon null default null;",
],
"up": [
"alter table "custom"."book2" alter column "double" type double precision using ("double"::double precision);",
"alter table "custom"."book2" drop column "foo";",
"",
"alter table "custom"."test2" drop column "path";",
],
},
"fileName": "Migration20191013214813.ts",
}
`;
exports[`Migrator (postgres) up/down params [all or nothing disabled]: all-or-nothing-disabled 1`] = `
[
"select 1 from pg_database where datname = 'mikro_orm_test_migrations'",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select schema_name from information_schema.schemata where "schema_name" not like 'pg_%' and "schema_name" not like 'crdb_%' and "schema_name" not like '_timescaledb_%' and "schema_name" not in ('information_schema', 'tiger', 'topology') order by schema_name",
"create table "custom"."mikro_orm_migrations" ("id" serial primary key, "name" varchar(255), "executed_at" timestamptz default current_timestamp)",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"select 1",
"commit",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"commit",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"select 1",
"commit",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"commit",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"select 1",
"commit",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"begin",
"commit",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
]
`;
exports[`Migrator (postgres) up/down params [all or nothing enabled]: all-or-nothing 1`] = `
[
"select 1 from pg_database where datname = 'mikro_orm_test_migrations'",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select schema_name from information_schema.schemata where "schema_name" not like 'pg_%' and "schema_name" not like 'crdb_%' and "schema_name" not like '_timescaledb_%' and "schema_name" not in ('information_schema', 'tiger', 'topology') order by schema_name",
"create table "custom"."mikro_orm_migrations" ("id" serial primary key, "name" varchar(255), "executed_at" timestamptz default current_timestamp)",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"select 1",
"release savepointtrx\\d+",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"release savepointtrx\\d+",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"select 1",
"release savepointtrx\\d+",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"release savepointtrx\\d+",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"select 1",
"release savepointtrx\\d+",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"commit",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"begin",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx\\d+",
"release savepointtrx\\d+",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"commit",
]
`;
exports[`Migrator (postgres) up/down with explicit transaction: explicit-tx 1`] = `
[
"begin",
"select 1 from pg_database where datname = 'mikro_orm_test_migrations'",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select schema_name from information_schema.schemata where "schema_name" not like 'pg_%' and "schema_name" not like 'crdb_%' and "schema_name" not like '_timescaledb_%' and "schema_name" not in ('information_schema', 'tiger', 'topology') order by schema_name",
"create table "custom"."mikro_orm_migrations" ("id" serial primary key, "name" varchar(255), "executed_at" timestamptz default current_timestamp)",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx_xx",
"select 1",
"release savepointtrx_xx",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"savepointtrx_xx",
"select 1",
"release savepointtrx_xx",
"insert into "custom"."mikro_orm_migrations" ("name") values ($1)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx_xx",
"release savepointtrx_xx",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"savepointtrx_xx",
"release savepointtrx_xx",
"delete from "custom"."mikro_orm_migrations" where "name" in ($1, $2)",
"select table_name, table_schema as schema_name, (select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.oid = (select ('"' || table_schema || '"."' || table_name || '"')::regclass::oid) and c.relname = table_name) as table_comment from information_schema.tables where "table_schema" not like 'pg_%' and "table_schema" not like 'crdb_%' and "table_schema" not like '_timescaledb_%' and "table_schema" not in ('information_schema', 'tiger', 'topology') and table_name != 'geometry_columns' and table_name != 'spatial_ref_sys' and table_type != 'VIEW' order by table_name",
"select * from "custom"."mikro_orm_migrations" order by "id" asc",
"commit",
]
`;