@primate/core 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/private/App.d.ts +21 -0
- package/lib/private/app/Facade.server.d.ts +22 -0
- package/lib/private/build/client/index.js +5 -0
- package/lib/private/build/server/index.js +4 -0
- package/lib/private/build/server/plugin/migrations.d.ts +4 -0
- package/lib/private/build/server/plugin/migrations.js +37 -0
- package/lib/private/config/schema.d.ts +3 -0
- package/lib/private/config/schema.js +1 -0
- package/lib/private/db/migrate/autoapply.d.ts +7 -0
- package/lib/private/db/migrate/autoapply.js +35 -0
- package/package.json +2 -2
package/lib/private/App.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export default class App {
|
|
|
85
85
|
migrations: {
|
|
86
86
|
table: string;
|
|
87
87
|
db: import("./db/DB.js").default<unknown>;
|
|
88
|
+
autoapply: boolean;
|
|
88
89
|
} | undefined;
|
|
89
90
|
};
|
|
90
91
|
env: {
|
|
@@ -120,6 +121,7 @@ export default class App {
|
|
|
120
121
|
migrations: {
|
|
121
122
|
table: string;
|
|
122
123
|
db: import("./db/DB.js").default<unknown>;
|
|
124
|
+
autoapply: boolean;
|
|
123
125
|
} | undefined;
|
|
124
126
|
};
|
|
125
127
|
env: {
|
|
@@ -155,6 +157,7 @@ export default class App {
|
|
|
155
157
|
migrations: {
|
|
156
158
|
table: string;
|
|
157
159
|
db: import("./db/DB.js").default<unknown>;
|
|
160
|
+
autoapply: boolean;
|
|
158
161
|
} | undefined;
|
|
159
162
|
};
|
|
160
163
|
env: {
|
|
@@ -190,6 +193,7 @@ export default class App {
|
|
|
190
193
|
migrations: {
|
|
191
194
|
table: string;
|
|
192
195
|
db: import("./db/DB.js").default<unknown>;
|
|
196
|
+
autoapply: boolean;
|
|
193
197
|
} | undefined;
|
|
194
198
|
};
|
|
195
199
|
env: {
|
|
@@ -225,6 +229,7 @@ export default class App {
|
|
|
225
229
|
migrations: {
|
|
226
230
|
table: string;
|
|
227
231
|
db: import("./db/DB.js").default<unknown>;
|
|
232
|
+
autoapply: boolean;
|
|
228
233
|
} | undefined;
|
|
229
234
|
};
|
|
230
235
|
env: {
|
|
@@ -260,6 +265,7 @@ export default class App {
|
|
|
260
265
|
migrations: {
|
|
261
266
|
table: string;
|
|
262
267
|
db: import("./db/DB.js").default<unknown>;
|
|
268
|
+
autoapply: boolean;
|
|
263
269
|
} | undefined;
|
|
264
270
|
};
|
|
265
271
|
env: {
|
|
@@ -295,6 +301,7 @@ export default class App {
|
|
|
295
301
|
migrations: {
|
|
296
302
|
table: string;
|
|
297
303
|
db: import("./db/DB.js").default<unknown>;
|
|
304
|
+
autoapply: boolean;
|
|
298
305
|
} | undefined;
|
|
299
306
|
};
|
|
300
307
|
env: {
|
|
@@ -330,6 +337,7 @@ export default class App {
|
|
|
330
337
|
migrations: {
|
|
331
338
|
table: string;
|
|
332
339
|
db: import("./db/DB.js").default<unknown>;
|
|
340
|
+
autoapply: boolean;
|
|
333
341
|
} | undefined;
|
|
334
342
|
};
|
|
335
343
|
env: {
|
|
@@ -365,6 +373,7 @@ export default class App {
|
|
|
365
373
|
migrations: {
|
|
366
374
|
table: string;
|
|
367
375
|
db: import("./db/DB.js").default<unknown>;
|
|
376
|
+
autoapply: boolean;
|
|
368
377
|
} | undefined;
|
|
369
378
|
};
|
|
370
379
|
env: {
|
|
@@ -400,6 +409,7 @@ export default class App {
|
|
|
400
409
|
migrations: {
|
|
401
410
|
table: string;
|
|
402
411
|
db: import("./db/DB.js").default<unknown>;
|
|
412
|
+
autoapply: boolean;
|
|
403
413
|
} | undefined;
|
|
404
414
|
};
|
|
405
415
|
env: {
|
|
@@ -435,6 +445,7 @@ export default class App {
|
|
|
435
445
|
migrations: {
|
|
436
446
|
table: string;
|
|
437
447
|
db: import("./db/DB.js").default<unknown>;
|
|
448
|
+
autoapply: boolean;
|
|
438
449
|
} | undefined;
|
|
439
450
|
};
|
|
440
451
|
env: {
|
|
@@ -470,6 +481,7 @@ export default class App {
|
|
|
470
481
|
migrations: {
|
|
471
482
|
table: string;
|
|
472
483
|
db: import("./db/DB.js").default<unknown>;
|
|
484
|
+
autoapply: boolean;
|
|
473
485
|
} | undefined;
|
|
474
486
|
};
|
|
475
487
|
env: {
|
|
@@ -505,6 +517,7 @@ export default class App {
|
|
|
505
517
|
migrations: {
|
|
506
518
|
table: string;
|
|
507
519
|
db: import("./db/DB.js").default<unknown>;
|
|
520
|
+
autoapply: boolean;
|
|
508
521
|
} | undefined;
|
|
509
522
|
};
|
|
510
523
|
env: {
|
|
@@ -540,6 +553,7 @@ export default class App {
|
|
|
540
553
|
migrations: {
|
|
541
554
|
table: string;
|
|
542
555
|
db: import("./db/DB.js").default<unknown>;
|
|
556
|
+
autoapply: boolean;
|
|
543
557
|
} | undefined;
|
|
544
558
|
};
|
|
545
559
|
env: {
|
|
@@ -575,6 +589,7 @@ export default class App {
|
|
|
575
589
|
migrations: {
|
|
576
590
|
table: string;
|
|
577
591
|
db: import("./db/DB.js").default<unknown>;
|
|
592
|
+
autoapply: boolean;
|
|
578
593
|
} | undefined;
|
|
579
594
|
};
|
|
580
595
|
env: {
|
|
@@ -610,6 +625,7 @@ export default class App {
|
|
|
610
625
|
migrations: {
|
|
611
626
|
table: string;
|
|
612
627
|
db: import("./db/DB.js").default<unknown>;
|
|
628
|
+
autoapply: boolean;
|
|
613
629
|
} | undefined;
|
|
614
630
|
};
|
|
615
631
|
env: {
|
|
@@ -645,6 +661,7 @@ export default class App {
|
|
|
645
661
|
migrations: {
|
|
646
662
|
table: string;
|
|
647
663
|
db: import("./db/DB.js").default<unknown>;
|
|
664
|
+
autoapply: boolean;
|
|
648
665
|
} | undefined;
|
|
649
666
|
};
|
|
650
667
|
env: {
|
|
@@ -680,6 +697,7 @@ export default class App {
|
|
|
680
697
|
migrations: {
|
|
681
698
|
table: string;
|
|
682
699
|
db: import("./db/DB.js").default<unknown>;
|
|
700
|
+
autoapply: boolean;
|
|
683
701
|
} | undefined;
|
|
684
702
|
};
|
|
685
703
|
env: {
|
|
@@ -715,6 +733,7 @@ export default class App {
|
|
|
715
733
|
migrations: {
|
|
716
734
|
table: string;
|
|
717
735
|
db: import("./db/DB.js").default<unknown>;
|
|
736
|
+
autoapply: boolean;
|
|
718
737
|
} | undefined;
|
|
719
738
|
};
|
|
720
739
|
env: {
|
|
@@ -750,6 +769,7 @@ export default class App {
|
|
|
750
769
|
migrations: {
|
|
751
770
|
table: string;
|
|
752
771
|
db: import("./db/DB.js").default<unknown>;
|
|
772
|
+
autoapply: boolean;
|
|
753
773
|
} | undefined;
|
|
754
774
|
};
|
|
755
775
|
env: {
|
|
@@ -785,6 +805,7 @@ export default class App {
|
|
|
785
805
|
migrations: {
|
|
786
806
|
table: string;
|
|
787
807
|
db: import("./db/DB.js").default<unknown>;
|
|
808
|
+
autoapply: boolean;
|
|
788
809
|
} | undefined;
|
|
789
810
|
};
|
|
790
811
|
env: {
|
|
@@ -36,6 +36,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
36
36
|
migrations: {
|
|
37
37
|
table: string;
|
|
38
38
|
db: import("../db/DB.js").default<unknown>;
|
|
39
|
+
autoapply: boolean;
|
|
39
40
|
} | undefined;
|
|
40
41
|
};
|
|
41
42
|
env: {
|
|
@@ -73,6 +74,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
73
74
|
migrations: {
|
|
74
75
|
table: string;
|
|
75
76
|
db: import("../db/DB.js").default<unknown>;
|
|
77
|
+
autoapply: boolean;
|
|
76
78
|
} | undefined;
|
|
77
79
|
};
|
|
78
80
|
env: {
|
|
@@ -108,6 +110,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
108
110
|
migrations: {
|
|
109
111
|
table: string;
|
|
110
112
|
db: import("../db/DB.js").default<unknown>;
|
|
113
|
+
autoapply: boolean;
|
|
111
114
|
} | undefined;
|
|
112
115
|
};
|
|
113
116
|
env: {
|
|
@@ -143,6 +146,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
143
146
|
migrations: {
|
|
144
147
|
table: string;
|
|
145
148
|
db: import("../db/DB.js").default<unknown>;
|
|
149
|
+
autoapply: boolean;
|
|
146
150
|
} | undefined;
|
|
147
151
|
};
|
|
148
152
|
env: {
|
|
@@ -178,6 +182,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
178
182
|
migrations: {
|
|
179
183
|
table: string;
|
|
180
184
|
db: import("../db/DB.js").default<unknown>;
|
|
185
|
+
autoapply: boolean;
|
|
181
186
|
} | undefined;
|
|
182
187
|
};
|
|
183
188
|
env: {
|
|
@@ -213,6 +218,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
213
218
|
migrations: {
|
|
214
219
|
table: string;
|
|
215
220
|
db: import("../db/DB.js").default<unknown>;
|
|
221
|
+
autoapply: boolean;
|
|
216
222
|
} | undefined;
|
|
217
223
|
};
|
|
218
224
|
env: {
|
|
@@ -248,6 +254,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
248
254
|
migrations: {
|
|
249
255
|
table: string;
|
|
250
256
|
db: import("../db/DB.js").default<unknown>;
|
|
257
|
+
autoapply: boolean;
|
|
251
258
|
} | undefined;
|
|
252
259
|
};
|
|
253
260
|
env: {
|
|
@@ -283,6 +290,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
283
290
|
migrations: {
|
|
284
291
|
table: string;
|
|
285
292
|
db: import("../db/DB.js").default<unknown>;
|
|
293
|
+
autoapply: boolean;
|
|
286
294
|
} | undefined;
|
|
287
295
|
};
|
|
288
296
|
env: {
|
|
@@ -318,6 +326,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
318
326
|
migrations: {
|
|
319
327
|
table: string;
|
|
320
328
|
db: import("../db/DB.js").default<unknown>;
|
|
329
|
+
autoapply: boolean;
|
|
321
330
|
} | undefined;
|
|
322
331
|
};
|
|
323
332
|
env: {
|
|
@@ -353,6 +362,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
353
362
|
migrations: {
|
|
354
363
|
table: string;
|
|
355
364
|
db: import("../db/DB.js").default<unknown>;
|
|
365
|
+
autoapply: boolean;
|
|
356
366
|
} | undefined;
|
|
357
367
|
};
|
|
358
368
|
env: {
|
|
@@ -388,6 +398,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
388
398
|
migrations: {
|
|
389
399
|
table: string;
|
|
390
400
|
db: import("../db/DB.js").default<unknown>;
|
|
401
|
+
autoapply: boolean;
|
|
391
402
|
} | undefined;
|
|
392
403
|
};
|
|
393
404
|
env: {
|
|
@@ -423,6 +434,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
423
434
|
migrations: {
|
|
424
435
|
table: string;
|
|
425
436
|
db: import("../db/DB.js").default<unknown>;
|
|
437
|
+
autoapply: boolean;
|
|
426
438
|
} | undefined;
|
|
427
439
|
};
|
|
428
440
|
env: {
|
|
@@ -458,6 +470,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
458
470
|
migrations: {
|
|
459
471
|
table: string;
|
|
460
472
|
db: import("../db/DB.js").default<unknown>;
|
|
473
|
+
autoapply: boolean;
|
|
461
474
|
} | undefined;
|
|
462
475
|
};
|
|
463
476
|
env: {
|
|
@@ -493,6 +506,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
493
506
|
migrations: {
|
|
494
507
|
table: string;
|
|
495
508
|
db: import("../db/DB.js").default<unknown>;
|
|
509
|
+
autoapply: boolean;
|
|
496
510
|
} | undefined;
|
|
497
511
|
};
|
|
498
512
|
env: {
|
|
@@ -528,6 +542,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
528
542
|
migrations: {
|
|
529
543
|
table: string;
|
|
530
544
|
db: import("../db/DB.js").default<unknown>;
|
|
545
|
+
autoapply: boolean;
|
|
531
546
|
} | undefined;
|
|
532
547
|
};
|
|
533
548
|
env: {
|
|
@@ -563,6 +578,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
563
578
|
migrations: {
|
|
564
579
|
table: string;
|
|
565
580
|
db: import("../db/DB.js").default<unknown>;
|
|
581
|
+
autoapply: boolean;
|
|
566
582
|
} | undefined;
|
|
567
583
|
};
|
|
568
584
|
env: {
|
|
@@ -598,6 +614,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
598
614
|
migrations: {
|
|
599
615
|
table: string;
|
|
600
616
|
db: import("../db/DB.js").default<unknown>;
|
|
617
|
+
autoapply: boolean;
|
|
601
618
|
} | undefined;
|
|
602
619
|
};
|
|
603
620
|
env: {
|
|
@@ -633,6 +650,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
633
650
|
migrations: {
|
|
634
651
|
table: string;
|
|
635
652
|
db: import("../db/DB.js").default<unknown>;
|
|
653
|
+
autoapply: boolean;
|
|
636
654
|
} | undefined;
|
|
637
655
|
};
|
|
638
656
|
env: {
|
|
@@ -668,6 +686,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
668
686
|
migrations: {
|
|
669
687
|
table: string;
|
|
670
688
|
db: import("../db/DB.js").default<unknown>;
|
|
689
|
+
autoapply: boolean;
|
|
671
690
|
} | undefined;
|
|
672
691
|
};
|
|
673
692
|
env: {
|
|
@@ -703,6 +722,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
703
722
|
migrations: {
|
|
704
723
|
table: string;
|
|
705
724
|
db: import("../db/DB.js").default<unknown>;
|
|
725
|
+
autoapply: boolean;
|
|
706
726
|
} | undefined;
|
|
707
727
|
};
|
|
708
728
|
env: {
|
|
@@ -738,6 +758,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
738
758
|
migrations: {
|
|
739
759
|
table: string;
|
|
740
760
|
db: import("../db/DB.js").default<unknown>;
|
|
761
|
+
autoapply: boolean;
|
|
741
762
|
} | undefined;
|
|
742
763
|
};
|
|
743
764
|
env: {
|
|
@@ -773,6 +794,7 @@ export default class AppFacade<T extends EnvSchema = EnvSchema, I extends I18NCo
|
|
|
773
794
|
migrations: {
|
|
774
795
|
table: string;
|
|
775
796
|
db: import("../db/DB.js").default<unknown>;
|
|
797
|
+
autoapply: boolean;
|
|
776
798
|
} | undefined;
|
|
777
799
|
};
|
|
778
800
|
env: {
|
|
@@ -12,12 +12,15 @@ import location from "#location";
|
|
|
12
12
|
import { CodeError } from "@rcompat/error";
|
|
13
13
|
import * as esbuild from "esbuild";
|
|
14
14
|
const write_bootstrap = async (app) => {
|
|
15
|
+
const migrate_auto = app.config("db.migrations")?.autoapply === true;
|
|
15
16
|
const build_start_script = `
|
|
16
17
|
import serve from "primate/serve";
|
|
17
18
|
import views from "app:views";
|
|
18
19
|
import routes from "app:routes";
|
|
19
20
|
import pages from "app:pages";
|
|
20
21
|
import assets from "app:assets";
|
|
22
|
+
${migrate_auto ? `import migrations from "app:migrations";` : ""}
|
|
23
|
+
${migrate_auto ? `import autoapply from "app:migrations/autoapply";` : ""}
|
|
21
24
|
import s_config from "primate/symbol/config";
|
|
22
25
|
${app.session_active ? `
|
|
23
26
|
import session from "app:config:session";
|
|
@@ -27,6 +30,8 @@ const write_bootstrap = async (app) => {
|
|
|
27
30
|
`}
|
|
28
31
|
import facade from "$:app";
|
|
29
32
|
|
|
33
|
+
${migrate_auto ? `await autoapply(facade, migrations);` : ""}
|
|
34
|
+
|
|
30
35
|
const app = await serve(import.meta.url, {
|
|
31
36
|
assets,
|
|
32
37
|
facade,
|
|
@@ -2,6 +2,7 @@ import plugin_assets from "#build/server/plugin/assets";
|
|
|
2
2
|
import plugin_config from "#build/server/plugin/config";
|
|
3
3
|
import plugin_frontend from "#build/server/plugin/frontend";
|
|
4
4
|
import plugin_live_reload from "#build/server/plugin/live-reload";
|
|
5
|
+
import plugin_migrations from "#build/server/plugin/migrations";
|
|
5
6
|
import plugin_native_addons from "#build/server/plugin/native-addons";
|
|
6
7
|
import plugin_node_imports from "#build/server/plugin/node-imports";
|
|
7
8
|
import plugin_requires from "#build/server/plugin/requires";
|
|
@@ -28,6 +29,9 @@ export default async function build_server(app) {
|
|
|
28
29
|
app.plugin("server", plugin_roots(app));
|
|
29
30
|
app.plugin("server", plugin_views(app));
|
|
30
31
|
app.plugin("server", plugin_assets(app));
|
|
32
|
+
if (app.config("db.migrations")?.autoapply === true) {
|
|
33
|
+
app.plugin("server", plugin_migrations(app));
|
|
34
|
+
}
|
|
31
35
|
app.plugin("server", plugin_native_addons(app));
|
|
32
36
|
app.plugin("server", plugin_requires(app));
|
|
33
37
|
app.plugin("server", plugin_config(app));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default function plugin_server_migrations(app) {
|
|
2
|
+
return {
|
|
3
|
+
name: "primate/server/migrations",
|
|
4
|
+
setup(build) {
|
|
5
|
+
build.onResolve({ filter: /^app:migrations$/ }, () => {
|
|
6
|
+
return { path: "migrations-virtual", namespace: "primate-migrations" };
|
|
7
|
+
});
|
|
8
|
+
build.onResolve({ filter: /^app:migrations\/autoapply$/ }, () => {
|
|
9
|
+
return { path: "migrations-autoapply", namespace: "primate-migrations" };
|
|
10
|
+
});
|
|
11
|
+
build.onLoad({ filter: /^migrations-autoapply$/, namespace: "primate-migrations" }, () => {
|
|
12
|
+
return {
|
|
13
|
+
contents: `export { default } from "#db/migrate/autoapply";`,
|
|
14
|
+
loader: "js",
|
|
15
|
+
resolveDir: import.meta.dirname,
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
build.onLoad({ filter: /^migrations-virtual$/, namespace: "primate-migrations" }, async () => {
|
|
19
|
+
const dir = app.root.join("migrations");
|
|
20
|
+
const files = await dir.exists()
|
|
21
|
+
? await dir.files({ filter: /\d+-.*\.[jt]s$/ })
|
|
22
|
+
: [];
|
|
23
|
+
const migrations = files
|
|
24
|
+
.map(file => ({ file, n: parseInt(file.name.split("-")[0]) }))
|
|
25
|
+
.toSorted((a, b) => a.n - b.n);
|
|
26
|
+
const imports = migrations.map(({ file }, i) => `import migration${i} from ${JSON.stringify(file.path)};`).join("\n");
|
|
27
|
+
const entries = migrations.map(({ file, n }, i) => `[${n}, ${JSON.stringify(file.name)}, migration${i}]`).join(",\n");
|
|
28
|
+
return {
|
|
29
|
+
contents: `${imports}\nexport default [${entries}];`,
|
|
30
|
+
loader: "js",
|
|
31
|
+
resolveDir: app.root.path,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -27,9 +27,11 @@ declare const _default: ObjectType<import("pema").NormalizeSchemaObject<{
|
|
|
27
27
|
migrations: import("pema").OptionalType<ObjectType<{
|
|
28
28
|
table: import("pema").StringType;
|
|
29
29
|
db: import("pema").PureType<DB<unknown>, "PureType">;
|
|
30
|
+
autoapply: import("pema").DefaultType<import("pema").BooleanType<undefined>, false>;
|
|
30
31
|
}, undefined, {
|
|
31
32
|
table: string;
|
|
32
33
|
db: DB<unknown>;
|
|
34
|
+
autoapply: boolean;
|
|
33
35
|
}>>;
|
|
34
36
|
};
|
|
35
37
|
readonly env: {
|
|
@@ -68,6 +70,7 @@ declare const _default: ObjectType<import("pema").NormalizeSchemaObject<{
|
|
|
68
70
|
migrations: {
|
|
69
71
|
table: string;
|
|
70
72
|
db: DB<unknown>;
|
|
73
|
+
autoapply: boolean;
|
|
71
74
|
} | undefined;
|
|
72
75
|
};
|
|
73
76
|
env: {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type AppFacade from "#app/Facade";
|
|
2
|
+
import type DB from "#db/DB";
|
|
3
|
+
type Migration = (db: DB) => unknown | Promise<unknown>;
|
|
4
|
+
type MigrationEntry = [number, string, Migration];
|
|
5
|
+
export default function autoapply(facade: AppFacade, migrations: MigrationEntry[]): Promise<void>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=autoapply.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import store from "#store";
|
|
3
|
+
import key from "#store/key";
|
|
4
|
+
import cli from "@rcompat/cli";
|
|
5
|
+
import p from "pema";
|
|
6
|
+
export default async function autoapply(facade, migrations) {
|
|
7
|
+
const migrations_config = facade.config("db.migrations");
|
|
8
|
+
if (migrations_config == undefined)
|
|
9
|
+
throw E.config_missing("db.migrations");
|
|
10
|
+
const { table, db } = migrations_config;
|
|
11
|
+
const Migration = store({
|
|
12
|
+
table,
|
|
13
|
+
db,
|
|
14
|
+
schema: {
|
|
15
|
+
id: key.primary(p.u16, { generate: false }),
|
|
16
|
+
applied: p.date,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
await Migration.create();
|
|
20
|
+
const last = await Migration.find({ limit: 1, sort: { id: "desc" } });
|
|
21
|
+
const last_id = last.length === 0 ? 0 : last[0].id;
|
|
22
|
+
const pending = migrations.filter(([id]) => id > last_id);
|
|
23
|
+
if (pending.length === 0) {
|
|
24
|
+
cli.print("No pending migrations.\n");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const [id, name, migration] of pending) {
|
|
28
|
+
await migration(Migration.db);
|
|
29
|
+
await Migration.insert({ id, applied: new Date() });
|
|
30
|
+
cli.print(`Applied migration ${cli.fg.bold(name)}.\n`);
|
|
31
|
+
}
|
|
32
|
+
const plural = pending.length === 1 ? "" : "s";
|
|
33
|
+
cli.print(`Done. Applied ${pending.length} migration${plural}.\n`);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=autoapply.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@rcompat/symbol": "^0.2.0",
|
|
36
36
|
"@rcompat/type": "^0.17.0",
|
|
37
37
|
"esbuild": "^0.28.0",
|
|
38
|
-
"pema": "^0.8.
|
|
38
|
+
"pema": "^0.8.3"
|
|
39
39
|
},
|
|
40
40
|
"imports": {
|
|
41
41
|
"#i18n/config": {
|