@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.4
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/CHANGELOG.md +74 -0
- package/LICENSE +21 -0
- package/README.md +525 -2
- package/bin/platform.js +28 -0
- package/dist/baseline/deps.d.ts +32 -0
- package/dist/baseline/deps.d.ts.map +1 -0
- package/dist/baseline/deps.js +66 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +36 -0
- package/dist/baseline/errors.d.ts.map +1 -0
- package/dist/baseline/errors.js +23 -0
- package/dist/baseline/errors.js.map +1 -0
- package/dist/baseline/fs.d.ts +9 -0
- package/dist/baseline/fs.d.ts.map +1 -0
- package/dist/baseline/fs.js +39 -0
- package/dist/baseline/fs.js.map +1 -0
- package/dist/baseline/index.d.ts +8 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +24 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/mapping.d.ts +43 -0
- package/dist/baseline/mapping.d.ts.map +1 -0
- package/dist/baseline/mapping.js +80 -0
- package/dist/baseline/mapping.js.map +1 -0
- package/dist/baseline/normalise.d.ts +42 -0
- package/dist/baseline/normalise.d.ts.map +1 -0
- package/dist/baseline/normalise.js +133 -0
- package/dist/baseline/normalise.js.map +1 -0
- package/dist/baseline/plan.d.ts +66 -0
- package/dist/baseline/plan.d.ts.map +1 -0
- package/dist/baseline/plan.js +105 -0
- package/dist/baseline/plan.js.map +1 -0
- package/dist/baseline/report.d.ts +127 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +89 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +117 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +358 -0
- package/dist/baseline/run.js.map +1 -0
- package/dist/bin/db-commands.d.ts +31 -0
- package/dist/bin/db-commands.d.ts.map +1 -0
- package/dist/bin/db-commands.js +311 -0
- package/dist/bin/db-commands.js.map +1 -0
- package/dist/bin/fs-io.d.ts +7 -0
- package/dist/bin/fs-io.d.ts.map +1 -0
- package/dist/bin/fs-io.js +45 -0
- package/dist/bin/fs-io.js.map +1 -0
- package/dist/bin/platform.d.ts +21 -0
- package/dist/bin/platform.d.ts.map +1 -0
- package/dist/bin/platform.js +99 -0
- package/dist/bin/platform.js.map +1 -0
- package/dist/compose/api.d.ts +84 -0
- package/dist/compose/api.d.ts.map +1 -0
- package/dist/compose/api.js +101 -0
- package/dist/compose/api.js.map +1 -0
- package/dist/compose/compose.d.ts +51 -0
- package/dist/compose/compose.d.ts.map +1 -0
- package/dist/compose/compose.js +177 -0
- package/dist/compose/compose.js.map +1 -0
- package/dist/compose/diff.d.ts +7 -0
- package/dist/compose/diff.d.ts.map +1 -0
- package/dist/compose/diff.js +68 -0
- package/dist/compose/diff.js.map +1 -0
- package/dist/compose/errors.d.ts +31 -0
- package/dist/compose/errors.d.ts.map +1 -0
- package/dist/compose/errors.js +35 -0
- package/dist/compose/errors.js.map +1 -0
- package/dist/compose/index.d.ts +3 -0
- package/dist/compose/index.d.ts.map +1 -0
- package/dist/compose/index.js +11 -0
- package/dist/compose/index.js.map +1 -0
- package/dist/compose/parse.d.ts +65 -0
- package/dist/compose/parse.d.ts.map +1 -0
- package/dist/compose/parse.js +122 -0
- package/dist/compose/parse.js.map +1 -0
- package/dist/drift/app-objects.d.ts +107 -0
- package/dist/drift/app-objects.d.ts.map +1 -0
- package/dist/drift/app-objects.js +193 -0
- package/dist/drift/app-objects.js.map +1 -0
- package/dist/drift/db-conformance.d.ts +52 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +89 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +8 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +43 -0
- package/dist/drift/index.js.map +1 -0
- package/dist/drift/raw-sql-indexes.d.ts +106 -0
- package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
- package/dist/drift/raw-sql-indexes.js +113 -0
- package/dist/drift/raw-sql-indexes.js.map +1 -0
- package/dist/drift/raw-sql-tripwire.d.ts +191 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +422 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- package/dist/drift/rls-policies.d.ts +226 -0
- package/dist/drift/rls-policies.d.ts.map +1 -0
- package/dist/drift/rls-policies.js +317 -0
- package/dist/drift/rls-policies.js.map +1 -0
- package/dist/drift/run.d.ts +152 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +252 -0
- package/dist/drift/run.js.map +1 -0
- package/dist/drift/sql-expression.d.ts +27 -0
- package/dist/drift/sql-expression.d.ts.map +1 -0
- package/dist/drift/sql-expression.js +64 -0
- package/dist/drift/sql-expression.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/hash.d.ts +13 -0
- package/dist/lock/hash.d.ts.map +1 -0
- package/dist/lock/hash.js +19 -0
- package/dist/lock/hash.js.map +1 -0
- package/dist/lock/index.d.ts +5 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js +20 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/lock/lock.d.ts +154 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +151 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +68 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +96 -0
- package/dist/lock/manifest.js.map +1 -0
- package/dist/lock/semver.d.ts +10 -0
- package/dist/lock/semver.d.ts.map +1 -0
- package/dist/lock/semver.js +13 -0
- package/dist/lock/semver.js.map +1 -0
- package/dist/seed/index.d.ts +5 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +16 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/seed/input.d.ts +52 -0
- package/dist/seed/input.d.ts.map +1 -0
- package/dist/seed/input.js +77 -0
- package/dist/seed/input.js.map +1 -0
- package/dist/seed/seed-platform.d.ts +41 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +165 -0
- package/dist/seed/seed-platform.js.map +1 -0
- package/dist/seed/steps.d.ts +172 -0
- package/dist/seed/steps.d.ts.map +1 -0
- package/dist/seed/steps.js +136 -0
- package/dist/seed/steps.js.map +1 -0
- package/dist/seed/types.d.ts +287 -0
- package/dist/seed/types.d.ts.map +1 -0
- package/dist/seed/types.js +5 -0
- package/dist/seed/types.js.map +1 -0
- package/dist/sync/app-migrations.d.ts +52 -0
- package/dist/sync/app-migrations.d.ts.map +1 -0
- package/dist/sync/app-migrations.js +62 -0
- package/dist/sync/app-migrations.js.map +1 -0
- package/dist/sync/apply.d.ts +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +38 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +59 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +115 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +32 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +23 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +10 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +27 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/ledger.d.ts +65 -0
- package/dist/sync/ledger.d.ts.map +1 -0
- package/dist/sync/ledger.js +49 -0
- package/dist/sync/ledger.js.map +1 -0
- package/dist/sync/plan.d.ts +63 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +86 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +62 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +95 -0
- package/dist/sync/promote.js.map +1 -0
- package/dist/sync/timestamps.d.ts +41 -0
- package/dist/sync/timestamps.d.ts.map +1 -0
- package/dist/sync/timestamps.js +68 -0
- package/dist/sync/timestamps.js.map +1 -0
- package/dist/sync/version.d.ts +28 -0
- package/dist/sync/version.d.ts.map +1 -0
- package/dist/sync/version.js +66 -0
- package/dist/sync/version.js.map +1 -0
- package/migrations/0001_initial/migration.sql +297 -0
- package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
- package/migrations/0003_add_credentials/migration.sql +20 -0
- package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
- package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
- package/migrations/0006_add_notifications/migration.sql +22 -0
- package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
- package/migrations/0008_add_jobs/migration.sql +110 -0
- package/migrations/0009_add_worker_nodes/migration.sql +90 -0
- package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
- package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
- package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
- package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
- package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
- package/migrations/0015_add_job_claim_token/migration.sql +92 -0
- package/migrations/0016_add_ai_platform/migration.sql +108 -0
- package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
- package/migrations/0018_add_user_credentials/migration.sql +29 -0
- package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
- package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
- package/migrations/0021_add_job_trace_context/migration.sql +6 -0
- package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
- package/migrations/0023_add_organizations/migration.sql +142 -0
- package/migrations/0024_split_system_org_roles/migration.sql +131 -0
- package/migrations/0025_org_scoped_rls/migration.sql +215 -0
- package/migrations/0026_add_groups/migration.sql +165 -0
- package/migrations/0027_add_grants/migration.sql +117 -0
- package/migrations/0028_add_org_settings/migration.sql +49 -0
- package/migrations/0029_add_org_credentials/migration.sql +54 -0
- package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
- package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
- package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
- package/migrations/0033_add_android_app/migration.sql +60 -0
- package/migrations/0034_open_job_reason/migration.sql +16 -0
- package/migrations/0035_ai_usage_feature/migration.sql +37 -0
- package/migrations/0036_add_app_metadata/migration.sql +49 -0
- package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
- package/migrations/manifest.json +379 -0
- package/package.json +78 -4
- package/raw-sql-indexes.json +94 -0
- package/rls-policies.json +74 -0
- package/schema/ai.prisma +444 -0
- package/schema/android-app.prisma +47 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +170 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +439 -0
- package/schema/jobs.prisma +760 -0
- package/schema/notifications.prisma +649 -0
- package/schema/settings.prisma +60 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +84 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerDbSyncCommands = registerDbSyncCommands;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const index_js_1 = require("../baseline/index.js");
|
|
7
|
+
const index_js_2 = require("../drift/index.js");
|
|
8
|
+
const index_js_3 = require("../lock/index.js");
|
|
9
|
+
const index_js_4 = require("../sync/index.js");
|
|
10
|
+
const fs_io_js_1 = require("./fs-io.js");
|
|
11
|
+
function layout(ctx, options) {
|
|
12
|
+
const root = (0, node_path_1.resolve)(ctx.cwd, options.root ?? '.');
|
|
13
|
+
const packageDir = options.packageDir ? (0, node_path_1.resolve)(ctx.cwd, options.packageDir) : ctx.packageRoot;
|
|
14
|
+
const prismaDir = (0, node_path_1.join)(root, 'prisma');
|
|
15
|
+
return {
|
|
16
|
+
prismaDir,
|
|
17
|
+
migrationsDir: (0, node_path_1.join)(prismaDir, 'migrations'),
|
|
18
|
+
lockFile: (0, node_path_1.join)(prismaDir, 'platform.lock'),
|
|
19
|
+
packageDir,
|
|
20
|
+
manifestFile: (0, node_path_1.join)(packageDir, 'migrations', 'manifest.json'),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function loadManifest(l) {
|
|
24
|
+
const bytes = (0, fs_io_js_1.readBytes)(l.manifestFile);
|
|
25
|
+
if (!bytes)
|
|
26
|
+
return [];
|
|
27
|
+
return (0, index_js_3.parseManifest)(Buffer.from(bytes).toString('utf8'), l.manifestFile);
|
|
28
|
+
}
|
|
29
|
+
function loadLock(l) {
|
|
30
|
+
const bytes = (0, fs_io_js_1.readBytes)(l.lockFile);
|
|
31
|
+
return bytes ? (0, index_js_3.parseLock)(Buffer.from(bytes).toString('utf8'), l.lockFile) : undefined;
|
|
32
|
+
}
|
|
33
|
+
function packageVersionOf(l) {
|
|
34
|
+
const raw = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(l.packageDir, 'package.json'), 'utf8'));
|
|
35
|
+
return raw.version;
|
|
36
|
+
}
|
|
37
|
+
function writeText(file, text) {
|
|
38
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(file), { recursive: true });
|
|
39
|
+
(0, node_fs_1.writeFileSync)(file, text);
|
|
40
|
+
}
|
|
41
|
+
/** Runs a command body and turns a refusal into a printed message and exit code 1. */
|
|
42
|
+
async function guarded(ctx, body) {
|
|
43
|
+
try {
|
|
44
|
+
ctx.setExitCode(await body());
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
ctx.err(`platform db: ${error.message}`);
|
|
48
|
+
ctx.setExitCode(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function runCheck(ctx, options) {
|
|
52
|
+
const l = layout(ctx, options);
|
|
53
|
+
const manifest = loadManifest(l);
|
|
54
|
+
const lock = loadLock(l);
|
|
55
|
+
const readLocal = (dir) => (0, fs_io_js_1.readBytes)((0, node_path_1.join)(l.migrationsDir, dir, 'migration.sql'));
|
|
56
|
+
const readPackage = (dir) => (0, fs_io_js_1.readBytes)((0, node_path_1.join)(l.packageDir, 'migrations', dir, 'migration.sql'));
|
|
57
|
+
let offlineOk = true;
|
|
58
|
+
if (!lock) {
|
|
59
|
+
if (manifest.length === 0) {
|
|
60
|
+
ctx.out('platform db check: no platform.lock and no package migrations; nothing to check');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
ctx.err(`platform db check: ${l.lockFile} not found; run \`platform db sync\``);
|
|
64
|
+
offlineOk = false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const result = (0, index_js_4.checkLock)(manifest, lock, readLocal, readPackage, (0, fs_io_js_1.listMigrationDirs)(l.migrationsDir));
|
|
69
|
+
for (const problem of result.problems)
|
|
70
|
+
ctx.err(`${problem.code} ${problem.message}`);
|
|
71
|
+
if (result.ok) {
|
|
72
|
+
ctx.out(`platform db check: ok (${lock.migrations.length} installed platform migration(s))`);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
ctx.err(`platform db check: ${result.problems.length} problem(s)`);
|
|
76
|
+
offlineOk = false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!options.database)
|
|
80
|
+
return offlineOk ? 0 : 1;
|
|
81
|
+
// The ledger comparison runs even when the offline half failed, so one run reports everything.
|
|
82
|
+
return (async () => {
|
|
83
|
+
const url = ctx.env.DATABASE_URL;
|
|
84
|
+
if (!url) {
|
|
85
|
+
ctx.err('platform db check --database: DATABASE_URL is not set (the api scripts build it from POSTGRES_*)');
|
|
86
|
+
return 2;
|
|
87
|
+
}
|
|
88
|
+
const rows = await (0, index_js_2.readLedgerRows)(url, ctx.cwd);
|
|
89
|
+
const ledger = (0, index_js_4.checkLedger)((0, fs_io_js_1.listMigrationDirs)(l.migrationsDir), readLocal, rows);
|
|
90
|
+
for (const problem of ledger.problems)
|
|
91
|
+
ctx.err(`${problem.code} ${problem.message}`);
|
|
92
|
+
if (ledger.pending.length)
|
|
93
|
+
ctx.out(`platform db check --database: ${ledger.pending.length} migration(s) not applied yet (run prisma migrate deploy)`);
|
|
94
|
+
if (!ledger.ok) {
|
|
95
|
+
ctx.err(`platform db check --database: ${ledger.problems.length} problem(s)`);
|
|
96
|
+
return 1;
|
|
97
|
+
}
|
|
98
|
+
ctx.out(`platform db check --database: ok (${rows.length} ledger row(s) match the files)`);
|
|
99
|
+
return offlineOk ? 0 : 1;
|
|
100
|
+
})();
|
|
101
|
+
}
|
|
102
|
+
function runSync(ctx, options) {
|
|
103
|
+
if (options.check)
|
|
104
|
+
return runCheck(ctx, options);
|
|
105
|
+
const l = layout(ctx, options);
|
|
106
|
+
const manifest = loadManifest(l);
|
|
107
|
+
const version = packageVersionOf(l);
|
|
108
|
+
const lock = loadLock(l) ?? (0, index_js_3.emptyLock)(version);
|
|
109
|
+
const now = options.timestamp ? new Date(options.timestamp) : ctx.now();
|
|
110
|
+
if (Number.isNaN(now.getTime()))
|
|
111
|
+
throw new Error(`--timestamp "${options.timestamp}" is not a date`);
|
|
112
|
+
const plan = (0, index_js_4.planSync)(manifest, lock, (0, fs_io_js_1.listMigrationDirs)(l.migrationsDir), now, version);
|
|
113
|
+
if (plan.installs.length === 0) {
|
|
114
|
+
ctx.out('platform db sync: up to date; nothing to install');
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
for (const install of plan.installs)
|
|
118
|
+
ctx.out(`${options.dryRun ? 'would install' : 'install'} ${install.originId} -> ${install.localDir}`);
|
|
119
|
+
if (options.dryRun)
|
|
120
|
+
return 0;
|
|
121
|
+
const next = (0, index_js_4.applySync)(plan, {
|
|
122
|
+
readPackageFile: (dir) => {
|
|
123
|
+
const bytes = (0, fs_io_js_1.readBytes)((0, node_path_1.join)(l.packageDir, 'migrations', dir, 'migration.sql'));
|
|
124
|
+
if (!bytes)
|
|
125
|
+
throw new Error(`package file migrations/${dir}/migration.sql does not exist`);
|
|
126
|
+
return bytes;
|
|
127
|
+
},
|
|
128
|
+
writeLocalMigration: (dir, bytes) => (0, fs_io_js_1.writeLocalMigration)(l.migrationsDir, dir, bytes),
|
|
129
|
+
});
|
|
130
|
+
writeText(l.lockFile, (0, index_js_3.serializeLock)(next));
|
|
131
|
+
ctx.out(`platform db sync: installed ${plan.installs.length} migration(s); run \`prisma migrate deploy\` to apply`);
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
function runPromote(ctx, localDir, options) {
|
|
135
|
+
const l = layout(ctx, options);
|
|
136
|
+
const manifest = loadManifest(l);
|
|
137
|
+
const lock = loadLock(l) ?? (0, index_js_3.emptyLock)(packageVersionOf(l));
|
|
138
|
+
const requires = options.requires ? options.requires.split(',').map((s) => s.trim()).filter(Boolean) : [];
|
|
139
|
+
const touches = options.touches ? options.touches.split(',').map((s) => s.trim()).filter(Boolean) : [];
|
|
140
|
+
const result = (0, index_js_4.promote)(localDir, options.id, {
|
|
141
|
+
manifest,
|
|
142
|
+
lock,
|
|
143
|
+
readLocal: (dir) => (0, fs_io_js_1.readBytes)((0, node_path_1.join)(l.migrationsDir, dir, 'migration.sql')),
|
|
144
|
+
writePackageFile: (dir, bytes) => writeBytes((0, node_path_1.join)(l.packageDir, 'migrations', dir, 'migration.sql'), bytes),
|
|
145
|
+
since: options.since ?? (0, index_js_4.nextPlatformVersion)(packageVersionOf(l), manifest.map((entry) => entry.since)),
|
|
146
|
+
slice: options.slice ?? manifest[manifest.length - 1]?.slice ?? 'core',
|
|
147
|
+
requires,
|
|
148
|
+
touches,
|
|
149
|
+
rls: options.rls === true,
|
|
150
|
+
});
|
|
151
|
+
if (!result.changed) {
|
|
152
|
+
ctx.out(`platform db promote: ${result.entry.id} is already promoted from ${localDir}; nothing to do`);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
const locked = new Set(result.lock.migrations.map((entry) => entry.localDir));
|
|
156
|
+
const appMigrations = (0, fs_io_js_1.listMigrationDirs)(l.migrationsDir).filter((dir) => !locked.has(dir));
|
|
157
|
+
writeText(l.manifestFile, (0, index_js_3.serializeJson)(result.manifest));
|
|
158
|
+
writeText(l.lockFile, (0, index_js_3.serializeLock)({ ...result.lock, appMigrations }));
|
|
159
|
+
ctx.out(`platform db promote: ${localDir} -> platform:${result.entry.id} (since ${result.entry.since})`);
|
|
160
|
+
ctx.out('commit both trees: packages/platform-db/migrations/** and apps/*/prisma/platform.lock');
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
function writeBytes(file, bytes) {
|
|
164
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(file), { recursive: true });
|
|
165
|
+
(0, node_fs_1.writeFileSync)(file, bytes);
|
|
166
|
+
}
|
|
167
|
+
async function runDriftCommand(ctx, options) {
|
|
168
|
+
const l = layout(ctx, options);
|
|
169
|
+
const url = ctx.env.DATABASE_URL;
|
|
170
|
+
if (!url) {
|
|
171
|
+
ctx.err('platform db drift: DATABASE_URL is not set (the api scripts build it from POSTGRES_*)');
|
|
172
|
+
return 2;
|
|
173
|
+
}
|
|
174
|
+
const schemaFolder = (0, node_path_1.join)(l.prismaDir, 'schema');
|
|
175
|
+
const schema = options.schema
|
|
176
|
+
? (0, node_path_1.resolve)(ctx.cwd, options.schema)
|
|
177
|
+
: (0, node_fs_1.existsSync)(schemaFolder)
|
|
178
|
+
? schemaFolder
|
|
179
|
+
: (0, node_path_1.join)(l.prismaDir, 'schema.prisma');
|
|
180
|
+
const lock = loadLock(l);
|
|
181
|
+
const packageIndexesFile = (0, node_path_1.join)(l.packageDir, 'raw-sql-indexes.json');
|
|
182
|
+
const packageIndexes = (0, node_fs_1.existsSync)(packageIndexesFile) ? (0, index_js_2.readPackageRawSqlIndexes)(packageIndexesFile) : [];
|
|
183
|
+
const packagePoliciesFile = (0, node_path_1.join)(l.packageDir, 'rls-policies.json');
|
|
184
|
+
const packagePolicies = (0, node_fs_1.existsSync)(packagePoliciesFile) ? (0, index_js_2.readPackageRlsPolicies)(packagePoliciesFile) : [];
|
|
185
|
+
const result = await (0, index_js_2.runDrift)({
|
|
186
|
+
cwd: (0, node_path_1.resolve)(ctx.cwd, options.root ?? '.'),
|
|
187
|
+
migrations: l.migrationsDir,
|
|
188
|
+
schema,
|
|
189
|
+
databaseUrl: url,
|
|
190
|
+
shadowDatabaseUrl: options.shadowDatabaseUrl ?? ctx.env.SHADOW_DATABASE_URL,
|
|
191
|
+
rawSqlIndexes: [...packageIndexes, ...(lock?.rawSqlIndexes ?? [])],
|
|
192
|
+
rlsPolicies: [...packagePolicies, ...(lock?.rlsPolicies ?? [])],
|
|
193
|
+
});
|
|
194
|
+
if (result.schemaDiff) {
|
|
195
|
+
ctx.err('SCHEMA_DRIFT the schema has changes no migration creates; add a migration. The missing SQL is:');
|
|
196
|
+
ctx.err(result.schemaDiff);
|
|
197
|
+
}
|
|
198
|
+
for (const problem of result.indexProblems)
|
|
199
|
+
ctx.err(`${problem.code} ${problem.message}`);
|
|
200
|
+
for (const problem of result.policyProblems)
|
|
201
|
+
ctx.err(`${problem.code} ${problem.message}`);
|
|
202
|
+
if (!result.ok)
|
|
203
|
+
return 1;
|
|
204
|
+
ctx.out(`platform db drift: ok (the migrations equal the schema; ${packageIndexes.length + (lock?.rawSqlIndexes?.length ?? 0)} raw-SQL index(es) and ${packagePolicies.length + (lock?.rlsPolicies?.length ?? 0)} row-level-security policy(ies) present)`);
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
/** `platform db policies`: the row-level-security policies the app's migrations leave, as `platform.lock` `rlsPolicies` entries. */
|
|
208
|
+
function runPolicies(ctx, options) {
|
|
209
|
+
const l = layout(ctx, options);
|
|
210
|
+
const packagePoliciesFile = (0, node_path_1.join)(l.packageDir, 'rls-policies.json');
|
|
211
|
+
const packageKeys = new Set(((0, node_fs_1.existsSync)(packagePoliciesFile) ? (0, index_js_2.readPackageRlsPolicies)(packagePoliciesFile) : []).map((policy) => `${policy.table}\u0000${policy.name}`));
|
|
212
|
+
const scanned = (0, index_js_2.scanRlsPolicies)((0, index_js_2.readAppMigrations)(l.migrationsDir));
|
|
213
|
+
const entries = scanned.policies
|
|
214
|
+
.filter((policy) => !packageKeys.has(`${policy.table}\u0000${policy.name}`))
|
|
215
|
+
.map((policy) => ({
|
|
216
|
+
name: policy.name,
|
|
217
|
+
table: policy.table,
|
|
218
|
+
...(policy.using !== undefined ? { usingSha256: (0, index_js_2.sqlExpressionSha256)(policy.using) } : {}),
|
|
219
|
+
...(policy.check !== undefined ? { checkSha256: (0, index_js_2.sqlExpressionSha256)(policy.check) } : {}),
|
|
220
|
+
}));
|
|
221
|
+
ctx.out((0, index_js_3.serializeJson)({ rlsPolicies: entries }).trimEnd());
|
|
222
|
+
ctx.err(`platform db policies: ${entries.length} app polic${entries.length === 1 ? 'y' : 'ies'}; paste "rlsPolicies" into prisma/platform.lock`);
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
async function runBaselineCommand(ctx, options) {
|
|
226
|
+
const l = layout(ctx, options);
|
|
227
|
+
const root = (0, node_path_1.resolve)(ctx.cwd, options.root ?? '.');
|
|
228
|
+
if (options.apply && options.dryRun) {
|
|
229
|
+
ctx.err('platform db baseline: --apply and --dry-run exclude each other (a dry run is the default)');
|
|
230
|
+
return 2;
|
|
231
|
+
}
|
|
232
|
+
const url = ctx.env.DATABASE_URL;
|
|
233
|
+
if (!url) {
|
|
234
|
+
ctx.err('platform db baseline: DATABASE_URL is not set (the api scripts build it from POSTGRES_*; run `npm run db:baseline`)');
|
|
235
|
+
return 2;
|
|
236
|
+
}
|
|
237
|
+
const deps = (0, index_js_1.createBaselineDeps)({
|
|
238
|
+
root,
|
|
239
|
+
databaseUrl: url,
|
|
240
|
+
env: ctx.env,
|
|
241
|
+
shadowDatabaseUrl: options.shadowDatabaseUrl ?? ctx.env.SHADOW_DATABASE_URL,
|
|
242
|
+
prismaScript: options.prismaScript ? (0, node_path_1.resolve)(ctx.cwd, options.prismaScript) : undefined,
|
|
243
|
+
log: (line) => ctx.out(`platform db baseline: ${line}`),
|
|
244
|
+
now: ctx.now,
|
|
245
|
+
});
|
|
246
|
+
const report = await (0, index_js_1.runBaseline)({
|
|
247
|
+
appPrismaDir: l.prismaDir,
|
|
248
|
+
packageDir: l.packageDir,
|
|
249
|
+
...(options.map ? { mapFile: (0, node_path_1.resolve)(ctx.cwd, options.map) } : {}),
|
|
250
|
+
apply: options.apply === true,
|
|
251
|
+
forceRemap: options.forceRemap === true,
|
|
252
|
+
allowRls: options.allowRls === true,
|
|
253
|
+
...(options.through ? { through: options.through } : {}),
|
|
254
|
+
}, deps);
|
|
255
|
+
const clean = (0, index_js_1.isBaselineClean)(report);
|
|
256
|
+
for (const line of (0, index_js_1.renderReport)(report))
|
|
257
|
+
(clean ? ctx.out : ctx.err)(line);
|
|
258
|
+
return clean ? 0 : 1;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Registers `sync`, `check`, `promote`, `drift`, `policies` and `baseline` on the `platform db` command.
|
|
262
|
+
*
|
|
263
|
+
* @param db - The `db` subcommand of the `platform` program.
|
|
264
|
+
* @param ctx - Output sinks and environment.
|
|
265
|
+
* @stability experimental
|
|
266
|
+
*/
|
|
267
|
+
function registerDbSyncCommands(db, ctx) {
|
|
268
|
+
const common = (cmd) => cmd
|
|
269
|
+
.option('--root <dir>', "the app's directory holding prisma/ (default: the current directory)")
|
|
270
|
+
.option('--package-dir <dir>', 'the platform-db package directory (default: the installed package)');
|
|
271
|
+
common(db
|
|
272
|
+
.command('sync')
|
|
273
|
+
.description('install package migrations missing from prisma/platform.lock into the app history (byte copies)')
|
|
274
|
+
.option('--check', 'read-only: same as `platform db check`')
|
|
275
|
+
.option('--dry-run', 'print what would be installed and write nothing')
|
|
276
|
+
.option('--timestamp <iso>', 'the clock for the new directory names (tests)')
|
|
277
|
+
.option('--database', 'with --check: also compare _prisma_migrations')).action((options) => guarded(ctx, () => runSync(ctx, options)));
|
|
278
|
+
common(db
|
|
279
|
+
.command('check')
|
|
280
|
+
.description('verify the lock against the files and the package (read-only; exits 1 on any problem)')
|
|
281
|
+
.option('--database', 'also compare _prisma_migrations checksums with the files (needs DATABASE_URL)')).action((options) => guarded(ctx, () => runCheck(ctx, options)));
|
|
282
|
+
common(db
|
|
283
|
+
.command('promote <localDir>')
|
|
284
|
+
.description('copy an app migration into the package, add it to the manifest and the app lock (platform-internal)')
|
|
285
|
+
.requiredOption('--id <slug>', 'the package migration slug, e.g. add_orgs')
|
|
286
|
+
.option('--since <version>', 'the platform version that ships it (default: the next minor)')
|
|
287
|
+
.option('--slice <slice>', 'the owning slice (default: the previous migration\'s)')
|
|
288
|
+
.option('--requires <slices>', 'comma-separated slice ids that must come earlier')
|
|
289
|
+
.option('--touches <slices>', 'comma-separated slice ids whose tables the migration also changes')
|
|
290
|
+
.option('--rls', 'the migration enables row-level security on a table (a partial baseline stops before it until the app opts in)')).action((localDir, options) => guarded(ctx, () => runPromote(ctx, localDir, options)));
|
|
291
|
+
common(db
|
|
292
|
+
.command('drift')
|
|
293
|
+
.description('CI drift test: migrations replayed in a shadow database must equal the schema; raw-SQL indexes must exist')
|
|
294
|
+
.option('--schema <path>', 'the composed schema folder or file (default: prisma/schema, else prisma/schema.prisma)')
|
|
295
|
+
.option('--shadow-database-url <url>', 'an empty database to replay into (default: a throwaway one is created)')).action((options) => guarded(ctx, () => runDriftCommand(ctx, options)));
|
|
296
|
+
common(db
|
|
297
|
+
.command('policies')
|
|
298
|
+
.description("print the app's row-level-security policies, from its migration SQL, as platform.lock rlsPolicies entries (with expression hashes)")).action((options) => guarded(ctx, () => runPolicies(ctx, options)));
|
|
299
|
+
common(db
|
|
300
|
+
.command('baseline')
|
|
301
|
+
.description('adopt the package history in a database that already has its schema: map, diff, then migrate resolve --applied (dry run unless --apply)')
|
|
302
|
+
.option('--through <migration>', 'the package migration the database equals: 22, 0022 or platform:0022_slug (default: the newest)')
|
|
303
|
+
.option('--map <file>', 'JSON file mapping platform:NNNN_slug to a local directory, for migrations the automatic passes cannot match')
|
|
304
|
+
.option('--apply', 'write platform.lock, install missing migrations and run migrate resolve --applied (default: a dry run that changes nothing)')
|
|
305
|
+
.option('--dry-run', 'explicit form of the default')
|
|
306
|
+
.option('--allow-rls', 'proceed past a migration flagged rls (row-level security); the application role must already be NOSUPERUSER NOBYPASSRLS')
|
|
307
|
+
.option('--force-remap', 'allow --apply when platform.lock already has entries (they are recomputed from the files)')
|
|
308
|
+
.option('--shadow-database-url <url>', 'an empty database to replay the package history into (default: a throwaway one is created and dropped)')
|
|
309
|
+
.option('--prisma-script <file>', 'the script that runs Prisma with DATABASE_URL (default: <root>/scripts/prisma-env.js)')).action((options) => guarded(ctx, () => runBaselineCommand(ctx, options)));
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=db-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-commands.js","sourceRoot":"","sources":["../../src/bin/db-commands.ts"],"names":[],"mappings":";;AA4UA,wDA8DC;AA1YD,qCAA6E;AAC7E,yCAAmD;AAEnD,mDAAsG;AACtG,gDAAwK;AACxK,+CAA4I;AAC5I,+CAO0B;AAC1B,yCAA+E;AAqC/E,SAAS,MAAM,CAAC,GAAqB,EAAE,OAAsB;IAC3D,MAAM,IAAI,GAAG,IAAA,mBAAO,EAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,mBAAO,EAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC;IAC/F,MAAM,SAAS,GAAG,IAAA,gBAAI,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,CAAC;SACnB,WAAW,CAAC,yIAAyI,CAAC;SACtJ,MAAM,CAAC,uBAAuB,EAAE,iGAAiG,CAAC;SAClI,MAAM,CAAC,cAAc,EAAE,6GAA6G,CAAC;SACrI,MAAM,CAAC,SAAS,EAAE,6HAA6H,CAAC;SAChJ,MAAM,CAAC,WAAW,EAAE,8BAA8B,CAAC;SACnD,MAAM,CAAC,aAAa,EAAE,yHAAyH,CAAC;SAChJ,MAAM,CAAC,eAAe,EAAE,2FAA2F,CAAC;SACpH,MAAM,CAAC,6BAA6B,EAAE,wGAAwG,CAAC;SAC/I,MAAM,CAAC,wBAAwB,EAAE,uFAAuF,CAAC,CAC7H,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Reads a file's bytes; `undefined` when the path does not exist. */
|
|
2
|
+
export declare function readBytes(file: string): Uint8Array | undefined;
|
|
3
|
+
/** Directory names (files such as `migration_lock.toml` excluded) of an app's `prisma/migrations`. */
|
|
4
|
+
export declare function listMigrationDirs(migrationsDir: string): string[];
|
|
5
|
+
/** Creates `<migrationsDir>/<localDir>/migration.sql` with exactly `bytes`; refuses an existing directory. */
|
|
6
|
+
export declare function writeLocalMigration(migrationsDir: string, localDir: string, bytes: Uint8Array): void;
|
|
7
|
+
//# sourceMappingURL=fs-io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-io.d.ts","sourceRoot":"","sources":["../../src/bin/fs-io.ts"],"names":[],"mappings":"AAIA,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAQ9D;AAED,sGAAsG;AACtG,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAMjE;AAED,8GAA8G;AAC9G,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAYpG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readBytes = readBytes;
|
|
4
|
+
exports.listMigrationDirs = listMigrationDirs;
|
|
5
|
+
exports.writeLocalMigration = writeLocalMigration;
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const index_js_1 = require("../sync/index.js");
|
|
9
|
+
/** Reads a file's bytes; `undefined` when the path does not exist. */
|
|
10
|
+
function readBytes(file) {
|
|
11
|
+
try {
|
|
12
|
+
return (0, node_fs_1.readFileSync)(file);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
const code = error.code;
|
|
16
|
+
if (code === 'ENOENT' || code === 'ENOTDIR')
|
|
17
|
+
return undefined;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Directory names (files such as `migration_lock.toml` excluded) of an app's `prisma/migrations`. */
|
|
22
|
+
function listMigrationDirs(migrationsDir) {
|
|
23
|
+
if (!(0, node_fs_1.existsSync)(migrationsDir))
|
|
24
|
+
return [];
|
|
25
|
+
return (0, node_fs_1.readdirSync)(migrationsDir, { withFileTypes: true })
|
|
26
|
+
.filter((entry) => entry.isDirectory())
|
|
27
|
+
.map((entry) => entry.name)
|
|
28
|
+
.sort();
|
|
29
|
+
}
|
|
30
|
+
/** Creates `<migrationsDir>/<localDir>/migration.sql` with exactly `bytes`; refuses an existing directory. */
|
|
31
|
+
function writeLocalMigration(migrationsDir, localDir, bytes) {
|
|
32
|
+
(0, node_fs_1.mkdirSync)(migrationsDir, { recursive: true });
|
|
33
|
+
const dir = (0, node_path_1.join)(migrationsDir, localDir);
|
|
34
|
+
try {
|
|
35
|
+
(0, node_fs_1.mkdirSync)(dir);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === 'EEXIST') {
|
|
39
|
+
throw new index_js_1.SyncError('LOCAL_DIR_EXISTS', `prisma/migrations/${localDir} already exists; sync never rewrites an existing directory`);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'migration.sql'), bytes);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=fs-io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-io.js","sourceRoot":"","sources":["../../src/bin/fs-io.ts"],"names":[],"mappings":";;AAKA,8BAQC;AAGD,8CAMC;AAGD,kDAYC;AArCD,qCAA0F;AAC1F,yCAAiC;AACjC,+CAA6C;AAE7C,sEAAsE;AACtE,SAAgB,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,IAAA,sBAAY,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,CAAC;QACnD,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC9D,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,sGAAsG;AACtG,SAAgB,iBAAiB,CAAC,aAAqB;IACrD,IAAI,CAAC,IAAA,oBAAU,EAAC,aAAa,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1C,OAAO,IAAA,qBAAW,EAAC,aAAa,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SACvD,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACtC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,8GAA8G;AAC9G,SAAgB,mBAAmB,CAAC,aAAqB,EAAE,QAAgB,EAAE,KAAiB;IAC5F,IAAA,mBAAS,EAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAG,IAAA,gBAAI,EAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC;QACH,IAAA,mBAAS,EAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,oBAAS,CAAC,kBAAkB,EAAE,qBAAqB,QAAQ,4DAA4D,CAAC,CAAC;QACrI,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;IACD,IAAA,uBAAa,EAAC,IAAA,gBAAI,EAAC,GAAG,EAAE,eAAe,CAAC,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DbCommandContext } from './db-commands.js';
|
|
2
|
+
/**
|
|
3
|
+
* Where the command writes: injectable so tests capture output.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface CliIo {
|
|
8
|
+
out: (line: string) => void;
|
|
9
|
+
err: (line: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Runs the command.
|
|
13
|
+
*
|
|
14
|
+
* @param argv - Arguments after the command name (`['db', 'compose', '--check']`).
|
|
15
|
+
* @param io - Output sinks.
|
|
16
|
+
* @param overrides - Working directory, environment, clock and package root, for tests.
|
|
17
|
+
* @returns The process exit code.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function main(argv: string[], io?: CliIo, overrides?: Partial<Omit<DbCommandContext, 'out' | 'err' | 'setExitCode'>>): Promise<number>;
|
|
21
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/bin/platform.ts"],"names":[],"mappings":"AASA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGjF;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAiED;;;;;;;;GAQG;AACH,wBAAsB,IAAI,CACxB,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,GAAE,KAAkB,EACtB,SAAS,GAAE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,KAAK,GAAG,aAAa,CAAC,CAAM,GAC7E,OAAO,CAAC,MAAM,CAAC,CA4BjB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The `platform` command (bin/platform.js runs `main`): a subcommand router.
|
|
3
|
+
// `platform db compose` (./compose) and `platform db sync|check|promote|drift|baseline`
|
|
4
|
+
// (./db-commands) are `db` subcommands. `main` returns the exit code and takes
|
|
5
|
+
// its output sinks so tests drive it without process.exit.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.main = main;
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const commander_1 = require("commander");
|
|
10
|
+
const db_commands_js_1 = require("./db-commands.js");
|
|
11
|
+
const index_js_1 = require("../compose/index.js");
|
|
12
|
+
const DEFAULT_IO = {
|
|
13
|
+
out: (line) => process.stdout.write(`${line}\n`),
|
|
14
|
+
err: (line) => process.stderr.write(`${line}\n`),
|
|
15
|
+
};
|
|
16
|
+
function registerCompose(db, io, setExit) {
|
|
17
|
+
db.command('compose')
|
|
18
|
+
.description('Compose the platform fragments and the app fragments into the Prisma schema folder (committed, generated)')
|
|
19
|
+
.option('--check', 'write nothing; exit 1 when the generated folder differs from a fresh compose')
|
|
20
|
+
.option('--root <dir>', "the app's directory (default: the current directory)", process.cwd())
|
|
21
|
+
.option('--fragments <dir>', "the app's fragment folder, relative to --root", 'prisma/fragments')
|
|
22
|
+
.option('--out <dir>', 'the generated schema folder, relative to --root', 'prisma/schema')
|
|
23
|
+
.option('--platform-schema <dir>', "the platform fragments (default: the folder shipped in @marinoscar/platform-db)")
|
|
24
|
+
.action((flags) => {
|
|
25
|
+
const root = (0, node_path_1.resolve)(flags.root);
|
|
26
|
+
const at = (p) => ((0, node_path_1.isAbsolute)(p) ? p : (0, node_path_1.join)(root, p));
|
|
27
|
+
const opts = {
|
|
28
|
+
appFragmentsDir: at(flags.fragments),
|
|
29
|
+
outDir: at(flags.out),
|
|
30
|
+
...(flags.platformSchema ? { platformSchemaDir: at(flags.platformSchema) } : {}),
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
if (flags.check) {
|
|
34
|
+
const res = (0, index_js_1.checkComposedSchema)(opts);
|
|
35
|
+
if (res.upToDate) {
|
|
36
|
+
io.out(`${flags.out} is up to date`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
io.err(res.diff);
|
|
40
|
+
io.err(`\n${flags.out} is out of date: run "platform db compose" (npm run db:compose) and commit the result.`);
|
|
41
|
+
setExit(1);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const res = (0, index_js_1.writeComposedSchema)(opts);
|
|
45
|
+
for (const w of res.warnings)
|
|
46
|
+
io.err(`warning: ${w}`);
|
|
47
|
+
io.out(`composed ${res.files.length} files into ${flags.out}`);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e instanceof index_js_1.ComposeError) {
|
|
51
|
+
io.err(e.message);
|
|
52
|
+
setExit(2);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Runs the command.
|
|
61
|
+
*
|
|
62
|
+
* @param argv - Arguments after the command name (`['db', 'compose', '--check']`).
|
|
63
|
+
* @param io - Output sinks.
|
|
64
|
+
* @param overrides - Working directory, environment, clock and package root, for tests.
|
|
65
|
+
* @returns The process exit code.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
async function main(argv, io = DEFAULT_IO, overrides = {}) {
|
|
69
|
+
let exit = 0;
|
|
70
|
+
const setExit = (code) => {
|
|
71
|
+
exit = code;
|
|
72
|
+
};
|
|
73
|
+
const program = new commander_1.Command('platform')
|
|
74
|
+
.description('Tools of the @marinoscar/platform-* packages')
|
|
75
|
+
.exitOverride()
|
|
76
|
+
.configureOutput({ writeOut: (s) => io.out(s.replace(/\n$/, '')), writeErr: (s) => io.err(s.replace(/\n$/, '')) });
|
|
77
|
+
const db = program.command('db').description('Database schema, migrations and seeds').exitOverride();
|
|
78
|
+
registerCompose(db, io, setExit);
|
|
79
|
+
(0, db_commands_js_1.registerDbSyncCommands)(db, {
|
|
80
|
+
out: io.out,
|
|
81
|
+
err: io.err,
|
|
82
|
+
cwd: process.cwd(),
|
|
83
|
+
env: process.env,
|
|
84
|
+
now: () => new Date(),
|
|
85
|
+
packageRoot: (0, node_path_1.resolve)(__dirname, '..', '..'),
|
|
86
|
+
...overrides,
|
|
87
|
+
setExitCode: (code) => setExit(code),
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
await program.parseAsync(argv, { from: 'user' });
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
if (e instanceof commander_1.CommanderError)
|
|
94
|
+
return e.exitCode === 0 ? 0 : 2;
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
return exit;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @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C,IAAgB,CAAC;KACjD,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,0BAAc;YAAE,OAAO,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjE,MAAM,CAAC,CAAC;IACV,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the composer reads and writes.
|
|
3
|
+
*
|
|
4
|
+
* @stability experimental
|
|
5
|
+
*/
|
|
6
|
+
export interface ComposeOptions {
|
|
7
|
+
/** The package's own fragments (`base.prisma` and one file per slice). Default: the `schema/` folder shipped in this package. */
|
|
8
|
+
platformSchemaDir?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The app's fragment folder (for the reference app `apps/api/prisma/fragments`): its own models and the `extend model` blocks that add back-relations to a platform model.
|
|
11
|
+
* A missing folder means the app has no fragments. Only `*.prisma` files directly inside it are read.
|
|
12
|
+
*
|
|
13
|
+
* @extensionPoint option
|
|
14
|
+
*/
|
|
15
|
+
appFragmentsDir: string;
|
|
16
|
+
/** The generated folder Prisma reads (for the reference app `apps/api/prisma/schema`). */
|
|
17
|
+
outDir: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One generated schema file.
|
|
21
|
+
*
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export interface ComposedFile {
|
|
25
|
+
/** Where the file belongs: inside `outDir`, named `platform.<slice>.prisma` or `app.<fragment>.prisma`. */
|
|
26
|
+
path: string;
|
|
27
|
+
/** The full text, starting with the do-not-edit header. */
|
|
28
|
+
contents: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The generated schema files and anything worth telling the developer.
|
|
32
|
+
*
|
|
33
|
+
* @stability experimental
|
|
34
|
+
*/
|
|
35
|
+
export interface ComposeResult {
|
|
36
|
+
/** One entry per generated file. */
|
|
37
|
+
files: ComposedFile[];
|
|
38
|
+
/** Non-fatal observations (for example an app `base.prisma` replacing the package's). */
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Outcome of {@link checkComposedSchema}.
|
|
43
|
+
*
|
|
44
|
+
* @stability experimental
|
|
45
|
+
*/
|
|
46
|
+
export interface ComposeCheck {
|
|
47
|
+
/** True when every generated file on disk equals a fresh composition and no stale file exists. */
|
|
48
|
+
upToDate: boolean;
|
|
49
|
+
/** A readable listing of what differs; empty when `upToDate`. */
|
|
50
|
+
diff: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Composes the platform fragments and the app's fragments into the generated
|
|
54
|
+
* schema files. Reads the fragment folders; writes nothing.
|
|
55
|
+
*
|
|
56
|
+
* @param opts - Folders to read and the output folder to name.
|
|
57
|
+
* @returns The files that belong in `outDir` and any warnings.
|
|
58
|
+
* @throws `ComposeError` when a fragment breaks a rule (see the rule table in the database ADR).
|
|
59
|
+
* @stability experimental
|
|
60
|
+
*/
|
|
61
|
+
export declare function composeSchema(opts: ComposeOptions): ComposeResult;
|
|
62
|
+
/**
|
|
63
|
+
* Composes and writes the generated folder: creates it if missing, replaces
|
|
64
|
+
* changed files and deletes `*.prisma` files that no fragment produces any
|
|
65
|
+
* more. Other files in the folder are left alone.
|
|
66
|
+
*
|
|
67
|
+
* @param opts - Folders to read and the folder to write.
|
|
68
|
+
* @returns What was written.
|
|
69
|
+
* @throws `ComposeError` when a fragment breaks a rule; nothing is written then.
|
|
70
|
+
* @stability experimental
|
|
71
|
+
*/
|
|
72
|
+
export declare function writeComposedSchema(opts: ComposeOptions): ComposeResult;
|
|
73
|
+
/**
|
|
74
|
+
* Compares the generated folder with a fresh composition without writing
|
|
75
|
+
* anything (the `--check` mode CI runs, like `openapi:dump` plus a diff).
|
|
76
|
+
* Line endings are ignored so a Windows checkout with CRLF still passes.
|
|
77
|
+
*
|
|
78
|
+
* @param opts - Folders to read and the generated folder to compare.
|
|
79
|
+
* @returns Whether the folder is current, and what differs when it is not.
|
|
80
|
+
* @throws `ComposeError` when a fragment breaks a rule.
|
|
81
|
+
* @stability experimental
|
|
82
|
+
*/
|
|
83
|
+
export declare function checkComposedSchema(opts: ComposeOptions): ComposeCheck;
|
|
84
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/compose/api.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,iIAAiI;IACjI,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,2GAA2G;IAC3G,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,yFAAyF;IACzF,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,kGAAkG;IAClG,QAAQ,EAAE,OAAO,CAAC;IAClB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAeD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,CAUjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,aAAa,CAYvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,YAAY,CAmBtE"}
|