@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.11
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 +88 -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,32 @@
|
|
|
1
|
+
import type { BaselineDeps } from './run.js';
|
|
2
|
+
/**
|
|
3
|
+
* Inputs of {@link createBaselineDeps}.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface BaselineDepsOptions {
|
|
8
|
+
/** The app's directory: where `prisma.config.ts` and `scripts/prisma-env.js` live; the Prisma CLI runs here. */
|
|
9
|
+
root: string;
|
|
10
|
+
/** Connection string of the live database (the app's `DATABASE_URL`). */
|
|
11
|
+
databaseUrl: string;
|
|
12
|
+
/** The environment the Prisma CLI inherits. */
|
|
13
|
+
env: NodeJS.ProcessEnv;
|
|
14
|
+
/** A pre-created empty shadow database for the replay; when omitted a throwaway one is created next to the live one and dropped. */
|
|
15
|
+
shadowDatabaseUrl?: string | undefined;
|
|
16
|
+
/** The script that builds `DATABASE_URL` and runs Prisma (default: `<root>/scripts/prisma-env.js`, else the `prisma` package of the app). */
|
|
17
|
+
prismaScript?: string | undefined;
|
|
18
|
+
/** Logs one action or finding. */
|
|
19
|
+
log: (line: string) => void;
|
|
20
|
+
/** The clock. */
|
|
21
|
+
now: () => Date;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Builds the real {@link BaselineDeps}: reads through `pg`, and runs every Prisma
|
|
25
|
+
* CLI call through the app's `scripts/prisma-env.js` (never a bare `npx prisma`).
|
|
26
|
+
*
|
|
27
|
+
* @param options - See {@link BaselineDepsOptions}.
|
|
28
|
+
* @returns The dependencies for `runBaseline`.
|
|
29
|
+
* @stability experimental
|
|
30
|
+
*/
|
|
31
|
+
export declare function createBaselineDeps(options: BaselineDepsOptions): BaselineDeps;
|
|
32
|
+
//# sourceMappingURL=deps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.d.ts","sourceRoot":"","sources":["../../src/baseline/deps.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,gHAAgH;IAChH,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,oIAAoI;IACpI,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,6IAA6I;IAC7I,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kCAAkC;IAClC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,iBAAiB;IACjB,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAyD7E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBaselineDeps = createBaselineDeps;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const index_js_1 = require("../drift/index.js");
|
|
8
|
+
/**
|
|
9
|
+
* Builds the real {@link BaselineDeps}: reads through `pg`, and runs every Prisma
|
|
10
|
+
* CLI call through the app's `scripts/prisma-env.js` (never a bare `npx prisma`).
|
|
11
|
+
*
|
|
12
|
+
* @param options - See {@link BaselineDepsOptions}.
|
|
13
|
+
* @returns The dependencies for `runBaseline`.
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
function createBaselineDeps(options) {
|
|
17
|
+
const script = options.prismaScript ?? (0, node_path_1.join)(options.root, 'scripts', 'prisma-env.js');
|
|
18
|
+
function runPrisma(args, extraEnv = {}) {
|
|
19
|
+
const entry = (0, node_fs_1.existsSync)(script) ? script : (0, index_js_1.prismaCli)(options.root);
|
|
20
|
+
const result = (0, node_child_process_1.spawnSync)(process.execPath, [entry, ...args], {
|
|
21
|
+
cwd: options.root,
|
|
22
|
+
env: { ...options.env, DATABASE_URL: options.databaseUrl, ...extraEnv },
|
|
23
|
+
encoding: 'utf8',
|
|
24
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
25
|
+
});
|
|
26
|
+
if (result.error)
|
|
27
|
+
throw result.error;
|
|
28
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
log: options.log,
|
|
32
|
+
now: options.now,
|
|
33
|
+
async readLedger() {
|
|
34
|
+
const Client = (0, index_js_1.loadPg)(options.root);
|
|
35
|
+
const client = new Client({ connectionString: options.databaseUrl });
|
|
36
|
+
await client.connect();
|
|
37
|
+
try {
|
|
38
|
+
const present = await client.query("SELECT to_regclass('public._prisma_migrations') IS NOT NULL AS present");
|
|
39
|
+
if (!present.rows[0]?.present)
|
|
40
|
+
return undefined;
|
|
41
|
+
const { rows } = await client.query('SELECT migration_name, checksum, finished_at, rolled_back_at FROM _prisma_migrations ORDER BY started_at, migration_name');
|
|
42
|
+
return rows.map((row) => ({
|
|
43
|
+
migrationName: String(row.migration_name),
|
|
44
|
+
checksum: String(row.checksum),
|
|
45
|
+
finishedAt: row.finished_at ? new Date(row.finished_at) : null,
|
|
46
|
+
rolledBackAt: row.rolled_back_at ? new Date(row.rolled_back_at) : null,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await client.end();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
readIndexes: () => (0, index_js_1.readIndexRows)(options.databaseUrl, options.root),
|
|
54
|
+
readPolicies: () => (0, index_js_1.readPolicyRows)(options.databaseUrl, options.root),
|
|
55
|
+
readTableRls: () => (0, index_js_1.readTableRlsRows)(options.databaseUrl, options.root),
|
|
56
|
+
diffReplayToLive: (replayMigrationsDir) => (0, index_js_1.withShadowDatabase)({ cwd: options.root, databaseUrl: options.databaseUrl, shadowDatabaseUrl: options.shadowDatabaseUrl }, async (shadowUrl) => {
|
|
57
|
+
const result = runPrisma(['migrate', 'diff', '--from-migrations', replayMigrationsDir, '--to-config-datasource', '--script'], { SHADOW_DATABASE_URL: shadowUrl });
|
|
58
|
+
if (result.status !== 0) {
|
|
59
|
+
throw new Error(`prisma migrate diff failed (exit ${result.status}): ${(result.stderr || result.stdout).trim()}`);
|
|
60
|
+
}
|
|
61
|
+
return (0, index_js_1.stripBanner)(result.stdout);
|
|
62
|
+
}),
|
|
63
|
+
prisma: async (args) => runPrisma(args),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=deps.js.map
|
|
@@ -0,0 +1 @@
|
|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,CAAC;QACrE,YAAY,EAAE,GAAG,EAAE,CAAC,IAAA,2BAAgB,EAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC;QACvE,gBAAgB,EAAE,CAAC,mBAAmB,EAAE,EAAE,CACxC,IAAA,6BAAkB,EAChB,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,EACrG,KAAK,EAAE,SAAS,EAAE,EAAE;YAClB,MAAM,MAAM,GAAG,SAAS,CACtB,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,UAAU,CAAC,EACnG,EAAE,mBAAmB,EAAE,SAAS,EAAE,CACnC,CAAC;YACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACpH,CAAC;YACD,OAAO,IAAA,sBAAW,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC,CACF;QACH,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why `platform db baseline` refused or could not continue.
|
|
3
|
+
*
|
|
4
|
+
* - `THROUGH_UNKNOWN`: `--through` names no package migration.
|
|
5
|
+
* - `MAP_INVALID`: the `--map` file is not valid, or names a directory or entry that does not exist or is already matched.
|
|
6
|
+
* - `LEDGER_FAILED_ROW`: `_prisma_migrations` holds a failed or rolled-back row.
|
|
7
|
+
* - `LEDGER_ROW_MISSING`: a mapped directory has no finished row in `_prisma_migrations`.
|
|
8
|
+
* - `LEDGER_CHECKSUM_MISMATCH`: a mapped directory's file differs from the checksum the database recorded.
|
|
9
|
+
* - `DIFF_BLOCKING`: the live database differs from the package history in a statement no deviation declares.
|
|
10
|
+
* - `INDEX_MISSING`, `INDEX_DEFINITION_DIFFERS`: a raw-SQL index is missing or changed in the live database.
|
|
11
|
+
* - `RLS_OPT_IN_REQUIRED`: a migration above `--through` is flagged `rls` in the manifest and the app has not opted in with `--allow-rls`.
|
|
12
|
+
* - `POLICY_MISSING`, `POLICY_UNLISTED`, `RLS_NOT_ENABLED`, `RLS_NOT_FORCED`, `RLS_FORCED_WITHOUT_POLICY`: the live row-level security does not match the policies the history up to `--through` creates.
|
|
13
|
+
* - `LOCK_NOT_EMPTY`: `platform.lock` already has entries and `--force-remap` was not given.
|
|
14
|
+
* - `PLACEMENT_IMPOSSIBLE`: a migration to resolve cannot be named so that the history keeps package order.
|
|
15
|
+
* - `PACKAGE_FILE_MISMATCH`: a package file does not match its manifest hash.
|
|
16
|
+
* - `RESOLVE_FAILED`: `prisma migrate resolve --applied` failed.
|
|
17
|
+
* - `VERIFY_FAILED`: a check after the apply failed.
|
|
18
|
+
*
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
export type BaselineErrorCode = 'THROUGH_UNKNOWN' | 'MAP_INVALID' | 'LEDGER_FAILED_ROW' | 'LEDGER_ROW_MISSING' | 'LEDGER_CHECKSUM_MISMATCH' | 'DIFF_BLOCKING' | 'INDEX_MISSING' | 'INDEX_DEFINITION_DIFFERS' | 'RLS_OPT_IN_REQUIRED' | 'POLICY_MISSING' | 'POLICY_UNLISTED' | 'RLS_NOT_ENABLED' | 'RLS_NOT_FORCED' | 'RLS_FORCED_WITHOUT_POLICY' | 'LOCK_NOT_EMPTY' | 'PLACEMENT_IMPOSSIBLE' | 'PACKAGE_FILE_MISMATCH' | 'RESOLVE_FAILED' | 'VERIFY_FAILED';
|
|
22
|
+
/**
|
|
23
|
+
* A refusal of `platform db baseline`, with a stable code.
|
|
24
|
+
*
|
|
25
|
+
* @stability experimental
|
|
26
|
+
*/
|
|
27
|
+
export declare class BaselineError extends Error {
|
|
28
|
+
/** The class of refusal. */
|
|
29
|
+
readonly code: BaselineErrorCode;
|
|
30
|
+
/**
|
|
31
|
+
* @param code - The class of refusal.
|
|
32
|
+
* @param message - What is wrong and how to fix it.
|
|
33
|
+
*/
|
|
34
|
+
constructor(code: BaselineErrorCode, message: string);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/baseline/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,aAAa,GACb,mBAAmB,GACnB,oBAAoB,GACpB,0BAA0B,GAC1B,eAAe,GACf,eAAe,GACf,0BAA0B,GAC1B,qBAAqB,GACrB,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,2BAA2B,GAC3B,gBAAgB,GAChB,sBAAsB,GACtB,uBAAuB,GACvB,gBAAgB,GAChB,eAAe,CAAC;AAEpB;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,4BAA4B;IAC5B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAEjC;;;OAGG;gBACS,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM;CAKrD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaselineError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A refusal of `platform db baseline`, with a stable code.
|
|
6
|
+
*
|
|
7
|
+
* @stability experimental
|
|
8
|
+
*/
|
|
9
|
+
class BaselineError extends Error {
|
|
10
|
+
/** The class of refusal. */
|
|
11
|
+
code;
|
|
12
|
+
/**
|
|
13
|
+
* @param code - The class of refusal.
|
|
14
|
+
* @param message - What is wrong and how to fix it.
|
|
15
|
+
*/
|
|
16
|
+
constructor(code, message) {
|
|
17
|
+
super(`${code}: ${message}`);
|
|
18
|
+
this.name = 'BaselineError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.BaselineError = BaselineError;
|
|
23
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/baseline/errors.ts"],"names":[],"mappings":";;;AAyCA;;;;GAIG;AACH,MAAa,aAAc,SAAQ,KAAK;IACtC,4BAA4B;IACnB,IAAI,CAAoB;IAEjC;;;OAGG;IACH,YAAY,IAAuB,EAAE,OAAe;QAClD,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAbD,sCAaC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Every directory name under `prisma/migrations` (sorted), whether or not it holds a `migration.sql`. */
|
|
2
|
+
export declare function listDirs(migrationsDir: string): string[];
|
|
3
|
+
/** Directory name to `migration.sql` bytes for every directory that has one. */
|
|
4
|
+
export declare function readLocalMigrations(migrationsDir: string): Map<string, Buffer>;
|
|
5
|
+
/** Creates `<migrationsDir>/<localDir>/migration.sql` with exactly `bytes`; refuses an existing directory. */
|
|
6
|
+
export declare function installMigration(migrationsDir: string, localDir: string, bytes: Uint8Array): void;
|
|
7
|
+
/** Removes a directory the baseline itself created (a failed resolve); nothing else is ever removed. */
|
|
8
|
+
export declare function removeInstalled(migrationsDir: string, localDir: string): void;
|
|
9
|
+
//# sourceMappingURL=fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/baseline/fs.ts"],"names":[],"mappings":"AAGA,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAMxD;AAED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAO9E;AAED,8GAA8G;AAC9G,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAKjG;AAED,wGAAwG;AACxG,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAE7E"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listDirs = listDirs;
|
|
4
|
+
exports.readLocalMigrations = readLocalMigrations;
|
|
5
|
+
exports.installMigration = installMigration;
|
|
6
|
+
exports.removeInstalled = removeInstalled;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
/** Every directory name under `prisma/migrations` (sorted), whether or not it holds a `migration.sql`. */
|
|
10
|
+
function listDirs(migrationsDir) {
|
|
11
|
+
if (!(0, node_fs_1.existsSync)(migrationsDir))
|
|
12
|
+
return [];
|
|
13
|
+
return (0, node_fs_1.readdirSync)(migrationsDir, { withFileTypes: true })
|
|
14
|
+
.filter((entry) => entry.isDirectory())
|
|
15
|
+
.map((entry) => entry.name)
|
|
16
|
+
.sort();
|
|
17
|
+
}
|
|
18
|
+
/** Directory name to `migration.sql` bytes for every directory that has one. */
|
|
19
|
+
function readLocalMigrations(migrationsDir) {
|
|
20
|
+
const out = new Map();
|
|
21
|
+
for (const dir of listDirs(migrationsDir)) {
|
|
22
|
+
const file = (0, node_path_1.join)(migrationsDir, dir, 'migration.sql');
|
|
23
|
+
if ((0, node_fs_1.existsSync)(file))
|
|
24
|
+
out.set(dir, (0, node_fs_1.readFileSync)(file));
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
/** Creates `<migrationsDir>/<localDir>/migration.sql` with exactly `bytes`; refuses an existing directory. */
|
|
29
|
+
function installMigration(migrationsDir, localDir, bytes) {
|
|
30
|
+
(0, node_fs_1.mkdirSync)(migrationsDir, { recursive: true });
|
|
31
|
+
const dir = (0, node_path_1.join)(migrationsDir, localDir);
|
|
32
|
+
(0, node_fs_1.mkdirSync)(dir); // throws EEXIST: the baseline never writes into an existing directory
|
|
33
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'migration.sql'), bytes);
|
|
34
|
+
}
|
|
35
|
+
/** Removes a directory the baseline itself created (a failed resolve); nothing else is ever removed. */
|
|
36
|
+
function removeInstalled(migrationsDir, localDir) {
|
|
37
|
+
(0, node_fs_1.rmSync)((0, node_path_1.join)(migrationsDir, localDir), { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../src/baseline/fs.ts"],"names":[],"mappings":";;AAIA,4BAMC;AAGD,kDAOC;AAGD,4CAKC;AAGD,0CAEC;AAjCD,qCAAkG;AAClG,yCAAiC;AAEjC,0GAA0G;AAC1G,SAAgB,QAAQ,CAAC,aAAqB;IAC5C,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,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ErrorCode } from './errors.js';
|
|
3
|
+
export { proposeMapping, type MatchKind, type MatchedMigration } from './mapping.js';
|
|
4
|
+
export { normaliseSql, normalisedSha256, normaliseStatement, splitStatements } from './normalise.js';
|
|
5
|
+
export { planBaseline, type PlannedAction, type PlannedEntry } from './plan.js';
|
|
6
|
+
export { isBaselineClean, renderReport, type BaselineDiff, type BaselineInstallItem, type BaselineLedgerState, type BaselineRefusal, type BaselineReport, type BaselineResolveItem, type BaselineVerification, } from './report.js';
|
|
7
|
+
export { readOperatorMap, resolveThrough, runBaseline, type BaselineDeps, type BaselineOptions, type PrismaResult, } from './run.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/baseline/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrG,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EACL,eAAe,EACf,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,YAAY,GAClB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runBaseline = exports.resolveThrough = exports.readOperatorMap = exports.renderReport = exports.isBaselineClean = exports.planBaseline = exports.splitStatements = exports.normaliseStatement = exports.normalisedSha256 = exports.normaliseSql = exports.proposeMapping = exports.BaselineError = exports.createBaselineDeps = void 0;
|
|
4
|
+
var deps_js_1 = require("./deps.js");
|
|
5
|
+
Object.defineProperty(exports, "createBaselineDeps", { enumerable: true, get: function () { return deps_js_1.createBaselineDeps; } });
|
|
6
|
+
var errors_js_1 = require("./errors.js");
|
|
7
|
+
Object.defineProperty(exports, "BaselineError", { enumerable: true, get: function () { return errors_js_1.BaselineError; } });
|
|
8
|
+
var mapping_js_1 = require("./mapping.js");
|
|
9
|
+
Object.defineProperty(exports, "proposeMapping", { enumerable: true, get: function () { return mapping_js_1.proposeMapping; } });
|
|
10
|
+
var normalise_js_1 = require("./normalise.js");
|
|
11
|
+
Object.defineProperty(exports, "normaliseSql", { enumerable: true, get: function () { return normalise_js_1.normaliseSql; } });
|
|
12
|
+
Object.defineProperty(exports, "normalisedSha256", { enumerable: true, get: function () { return normalise_js_1.normalisedSha256; } });
|
|
13
|
+
Object.defineProperty(exports, "normaliseStatement", { enumerable: true, get: function () { return normalise_js_1.normaliseStatement; } });
|
|
14
|
+
Object.defineProperty(exports, "splitStatements", { enumerable: true, get: function () { return normalise_js_1.splitStatements; } });
|
|
15
|
+
var plan_js_1 = require("./plan.js");
|
|
16
|
+
Object.defineProperty(exports, "planBaseline", { enumerable: true, get: function () { return plan_js_1.planBaseline; } });
|
|
17
|
+
var report_js_1 = require("./report.js");
|
|
18
|
+
Object.defineProperty(exports, "isBaselineClean", { enumerable: true, get: function () { return report_js_1.isBaselineClean; } });
|
|
19
|
+
Object.defineProperty(exports, "renderReport", { enumerable: true, get: function () { return report_js_1.renderReport; } });
|
|
20
|
+
var run_js_1 = require("./run.js");
|
|
21
|
+
Object.defineProperty(exports, "readOperatorMap", { enumerable: true, get: function () { return run_js_1.readOperatorMap; } });
|
|
22
|
+
Object.defineProperty(exports, "resolveThrough", { enumerable: true, get: function () { return run_js_1.resolveThrough; } });
|
|
23
|
+
Object.defineProperty(exports, "runBaseline", { enumerable: true, get: function () { return run_js_1.runBaseline; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/baseline/index.ts"],"names":[],"mappings":";;;AAAA,qCAAyE;AAAhE,6GAAA,kBAAkB,OAAA;AAC3B,yCAAoE;AAA3D,0GAAA,aAAa,OAAA;AACtB,2CAAqF;AAA5E,4GAAA,cAAc,OAAA;AACvB,+CAAqG;AAA5F,4GAAA,YAAY,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAAE,+GAAA,eAAe,OAAA;AAC5E,qCAAgF;AAAvE,uGAAA,YAAY,OAAA;AACrB,yCAUqB;AATnB,4GAAA,eAAe,OAAA;AACf,yGAAA,YAAY,OAAA;AASd,mCAOkB;AANhB,yGAAA,eAAe,OAAA;AACf,wGAAA,cAAc,OAAA;AACd,qGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ManifestEntry } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* How a package migration was matched to a local directory.
|
|
4
|
+
*
|
|
5
|
+
* - `sha256`: the bytes are identical (a directory rename is irrelevant).
|
|
6
|
+
* - `normalised`: identical once comments and whitespace are stripped; the lock records `localSha256`.
|
|
7
|
+
* - `operator-map`: named by the operator in `--map`; the lock records `localSha256` when the bytes differ.
|
|
8
|
+
*
|
|
9
|
+
* @stability experimental
|
|
10
|
+
*/
|
|
11
|
+
export type MatchKind = 'sha256' | 'normalised' | 'operator-map';
|
|
12
|
+
/**
|
|
13
|
+
* A package migration matched to an existing local directory.
|
|
14
|
+
*
|
|
15
|
+
* @stability experimental
|
|
16
|
+
*/
|
|
17
|
+
export interface MatchedMigration {
|
|
18
|
+
/** `platform:NNNN_slug`. */
|
|
19
|
+
originId: string;
|
|
20
|
+
/** The app's directory. */
|
|
21
|
+
localDir: string;
|
|
22
|
+
/** How it was matched; a reviewer checks every match that is not `sha256`. */
|
|
23
|
+
kind: MatchKind;
|
|
24
|
+
/** SHA-256 of the app's file, present when it differs from the package's. */
|
|
25
|
+
localSha256?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Proposes the mapping from package migrations to the app's directories (step B1).
|
|
29
|
+
*
|
|
30
|
+
* Per package migration, in order: an exact SHA-256 of `migration.sql`, then
|
|
31
|
+
* the same after stripping comments and whitespace, then the operator's
|
|
32
|
+
* `--map`. A directory matches at most one migration. Pure.
|
|
33
|
+
*
|
|
34
|
+
* @param manifest - The package history, in order.
|
|
35
|
+
* @param localDirs - Directory name to `migration.sql` bytes, for every directory of the app's `prisma/migrations`.
|
|
36
|
+
* @param packageFile - Reads the package's `migration.sql` for a manifest entry (the normalised pass compares against it).
|
|
37
|
+
* @param map - Operator overrides, `platform:NNNN_slug` (or `NNNN_slug`) to a local directory name. An override replaces the automatic match of its own entry; a directory that already matches another migration exactly is refused.
|
|
38
|
+
* @returns One entry per matched package migration, in package order.
|
|
39
|
+
* @throws BaselineError `MAP_INVALID` when `map` names an unknown entry or directory, or a directory that another migration already matched.
|
|
40
|
+
* @stability experimental
|
|
41
|
+
*/
|
|
42
|
+
export declare function proposeMapping(manifest: readonly ManifestEntry[], localDirs: ReadonlyMap<string, Uint8Array>, packageFile: (entry: ManifestEntry) => Uint8Array, map?: Readonly<Record<string, string>>): MatchedMigration[];
|
|
43
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/baseline/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAI7E;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,cAAc,CAAC;AAEjE;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,IAAI,EAAE,SAAS,CAAC;IAChB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAC1C,WAAW,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,UAAU,EACjD,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GACzC,gBAAgB,EAAE,CAsDpB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proposeMapping = proposeMapping;
|
|
4
|
+
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const normalise_js_1 = require("./normalise.js");
|
|
7
|
+
/**
|
|
8
|
+
* Proposes the mapping from package migrations to the app's directories (step B1).
|
|
9
|
+
*
|
|
10
|
+
* Per package migration, in order: an exact SHA-256 of `migration.sql`, then
|
|
11
|
+
* the same after stripping comments and whitespace, then the operator's
|
|
12
|
+
* `--map`. A directory matches at most one migration. Pure.
|
|
13
|
+
*
|
|
14
|
+
* @param manifest - The package history, in order.
|
|
15
|
+
* @param localDirs - Directory name to `migration.sql` bytes, for every directory of the app's `prisma/migrations`.
|
|
16
|
+
* @param packageFile - Reads the package's `migration.sql` for a manifest entry (the normalised pass compares against it).
|
|
17
|
+
* @param map - Operator overrides, `platform:NNNN_slug` (or `NNNN_slug`) to a local directory name. An override replaces the automatic match of its own entry; a directory that already matches another migration exactly is refused.
|
|
18
|
+
* @returns One entry per matched package migration, in package order.
|
|
19
|
+
* @throws BaselineError `MAP_INVALID` when `map` names an unknown entry or directory, or a directory that another migration already matched.
|
|
20
|
+
* @stability experimental
|
|
21
|
+
*/
|
|
22
|
+
function proposeMapping(manifest, localDirs, packageFile, map = {}) {
|
|
23
|
+
const operator = new Map();
|
|
24
|
+
const known = new Set(manifest.map(index_js_1.originIdOf));
|
|
25
|
+
for (const [key, dir] of Object.entries(map)) {
|
|
26
|
+
const id = key.startsWith('platform:') ? key : `platform:${key}`;
|
|
27
|
+
if (!known.has(id))
|
|
28
|
+
throw new errors_js_1.BaselineError('MAP_INVALID', `--map names ${key}, which is not in the package manifest`);
|
|
29
|
+
if (!localDirs.has(dir))
|
|
30
|
+
throw new errors_js_1.BaselineError('MAP_INVALID', `--map maps ${key} to ${dir}, which is not a directory with a migration.sql under prisma/migrations`);
|
|
31
|
+
operator.set(id, dir);
|
|
32
|
+
}
|
|
33
|
+
const localSha = new Map();
|
|
34
|
+
const localNormalised = new Map();
|
|
35
|
+
for (const [dir, bytes] of localDirs) {
|
|
36
|
+
localSha.set(dir, (0, index_js_1.sha256Hex)(bytes));
|
|
37
|
+
localNormalised.set(dir, (0, normalise_js_1.normalisedSha256)(bytes));
|
|
38
|
+
}
|
|
39
|
+
const used = new Set();
|
|
40
|
+
const byEntry = new Map();
|
|
41
|
+
const take = (entry, dir, kind) => {
|
|
42
|
+
used.add(dir);
|
|
43
|
+
const local = localSha.get(dir);
|
|
44
|
+
byEntry.set((0, index_js_1.originIdOf)(entry), {
|
|
45
|
+
originId: (0, index_js_1.originIdOf)(entry),
|
|
46
|
+
localDir: dir,
|
|
47
|
+
kind,
|
|
48
|
+
...(local === entry.sha256 ? {} : { localSha256: local }),
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
// Pass 1, exact bytes. Directories are tried in name order so the result is deterministic.
|
|
52
|
+
const sortedDirs = [...localDirs.keys()].sort();
|
|
53
|
+
for (const entry of manifest) {
|
|
54
|
+
const dir = sortedDirs.find((d) => !used.has(d) && localSha.get(d) === entry.sha256 && operator.get((0, index_js_1.originIdOf)(entry)) === undefined);
|
|
55
|
+
if (dir)
|
|
56
|
+
take(entry, dir, 'sha256');
|
|
57
|
+
}
|
|
58
|
+
// Pass 2, comments and whitespace stripped.
|
|
59
|
+
for (const entry of manifest) {
|
|
60
|
+
if (byEntry.has((0, index_js_1.originIdOf)(entry)) || operator.has((0, index_js_1.originIdOf)(entry)))
|
|
61
|
+
continue;
|
|
62
|
+
const want = (0, normalise_js_1.normalisedSha256)(packageFile(entry));
|
|
63
|
+
const dir = sortedDirs.find((d) => !used.has(d) && localNormalised.get(d) === want);
|
|
64
|
+
if (dir)
|
|
65
|
+
take(entry, dir, 'normalised');
|
|
66
|
+
}
|
|
67
|
+
// Pass 3, the operator. An explicit mapping always wins over a guess.
|
|
68
|
+
for (const entry of manifest) {
|
|
69
|
+
const dir = operator.get((0, index_js_1.originIdOf)(entry));
|
|
70
|
+
if (dir === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
if (used.has(dir)) {
|
|
73
|
+
const holder = [...byEntry.values()].find((m) => m.localDir === dir);
|
|
74
|
+
throw new errors_js_1.BaselineError('MAP_INVALID', `--map maps ${(0, index_js_1.originIdOf)(entry)} to ${dir}, which already matches ${holder?.originId ?? 'another migration'}`);
|
|
75
|
+
}
|
|
76
|
+
take(entry, dir, 'operator-map');
|
|
77
|
+
}
|
|
78
|
+
return manifest.flatMap((entry) => byEntry.get((0, index_js_1.originIdOf)(entry)) ?? []);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../src/base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,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAA,qBAAU,EAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalises migration SQL for matching a fork that edited comments or
|
|
3
|
+
* whitespace: strips `--` line comments and block comments, collapses runs of
|
|
4
|
+
* whitespace (dropping it next to `(`, `)`, `,` and `;`) and lower-cases everything outside string literals and quoted
|
|
5
|
+
* identifiers (so keywords compare equal while `"User"` stays distinct from
|
|
6
|
+
* `"user"`).
|
|
7
|
+
*
|
|
8
|
+
* The result is only ever compared with another normalised text; it is never
|
|
9
|
+
* written anywhere, because Prisma checksums the raw bytes.
|
|
10
|
+
*
|
|
11
|
+
* @param sql - The text of a `migration.sql`.
|
|
12
|
+
* @returns The normalised text.
|
|
13
|
+
* @stability experimental
|
|
14
|
+
*/
|
|
15
|
+
export declare function normaliseSql(sql: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* SHA-256 of {@link normaliseSql}, the fingerprint the second matching pass compares.
|
|
18
|
+
*
|
|
19
|
+
* @param bytes - The raw `migration.sql` bytes.
|
|
20
|
+
* @returns 64 lower-case hex characters.
|
|
21
|
+
* @stability experimental
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalisedSha256(bytes: Uint8Array): string;
|
|
24
|
+
/**
|
|
25
|
+
* Normalises one statement of `prisma migrate diff` output for comparison with
|
|
26
|
+
* a `deviations[].expectDiff` entry: removes `"public".` and collapses whitespace.
|
|
27
|
+
*
|
|
28
|
+
* @param statement - A statement.
|
|
29
|
+
* @returns The normalised statement.
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
export declare function normaliseStatement(statement: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Splits the SQL `prisma migrate diff --script` prints into statements:
|
|
35
|
+
* comment headings are dropped and each statement keeps its trailing `;`.
|
|
36
|
+
*
|
|
37
|
+
* @param script - The script text, banner lines already removed.
|
|
38
|
+
* @returns The statements; empty for an empty migration.
|
|
39
|
+
* @stability experimental
|
|
40
|
+
*/
|
|
41
|
+
export declare function splitStatements(script: string): string[];
|
|
42
|
+
//# sourceMappingURL=normalise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalise.d.ts","sourceRoot":"","sources":["../../src/baseline/normalise.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA6DhD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normaliseSql = normaliseSql;
|
|
4
|
+
exports.normalisedSha256 = normalisedSha256;
|
|
5
|
+
exports.normaliseStatement = normaliseStatement;
|
|
6
|
+
exports.splitStatements = splitStatements;
|
|
7
|
+
const index_js_1 = require("../lock/index.js");
|
|
8
|
+
/**
|
|
9
|
+
* Normalises migration SQL for matching a fork that edited comments or
|
|
10
|
+
* whitespace: strips `--` line comments and block comments, collapses runs of
|
|
11
|
+
* whitespace (dropping it next to `(`, `)`, `,` and `;`) and lower-cases everything outside string literals and quoted
|
|
12
|
+
* identifiers (so keywords compare equal while `"User"` stays distinct from
|
|
13
|
+
* `"user"`).
|
|
14
|
+
*
|
|
15
|
+
* The result is only ever compared with another normalised text; it is never
|
|
16
|
+
* written anywhere, because Prisma checksums the raw bytes.
|
|
17
|
+
*
|
|
18
|
+
* @param sql - The text of a `migration.sql`.
|
|
19
|
+
* @returns The normalised text.
|
|
20
|
+
* @stability experimental
|
|
21
|
+
*/
|
|
22
|
+
function normaliseSql(sql) {
|
|
23
|
+
let out = '';
|
|
24
|
+
let pendingSpace = false;
|
|
25
|
+
const emit = (token) => {
|
|
26
|
+
// One space between tokens, none next to punctuation: `(\n "id"` and `("id"` are the same text.
|
|
27
|
+
if (pendingSpace && out !== '' && !/[(),;]$/.test(out) && !/^[(),;]/.test(token))
|
|
28
|
+
out += ' ';
|
|
29
|
+
pendingSpace = false;
|
|
30
|
+
out += token;
|
|
31
|
+
};
|
|
32
|
+
let i = 0;
|
|
33
|
+
const n = sql.length;
|
|
34
|
+
while (i < n) {
|
|
35
|
+
const c = sql[i];
|
|
36
|
+
const next = sql[i + 1];
|
|
37
|
+
if (c === '-' && next === '-') {
|
|
38
|
+
while (i < n && sql[i] !== '\n')
|
|
39
|
+
i += 1;
|
|
40
|
+
pendingSpace = true;
|
|
41
|
+
}
|
|
42
|
+
else if (c === '/' && next === '*') {
|
|
43
|
+
let depth = 1;
|
|
44
|
+
i += 2;
|
|
45
|
+
while (i < n && depth > 0) {
|
|
46
|
+
if (sql[i] === '/' && sql[i + 1] === '*') {
|
|
47
|
+
depth += 1;
|
|
48
|
+
i += 2;
|
|
49
|
+
}
|
|
50
|
+
else if (sql[i] === '*' && sql[i + 1] === '/') {
|
|
51
|
+
depth -= 1;
|
|
52
|
+
i += 2;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
i += 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
pendingSpace = true;
|
|
59
|
+
}
|
|
60
|
+
else if (c === "'" || c === '"') {
|
|
61
|
+
// A literal or a quoted identifier: copied verbatim, doubled quotes are escapes.
|
|
62
|
+
let j = i + 1;
|
|
63
|
+
while (j < n) {
|
|
64
|
+
if (sql[j] === c) {
|
|
65
|
+
if (sql[j + 1] === c)
|
|
66
|
+
j += 2;
|
|
67
|
+
else
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
j += 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
emit(sql.slice(i, j + 1));
|
|
75
|
+
i = j + 1;
|
|
76
|
+
}
|
|
77
|
+
else if (c === '$' && /^\$[A-Za-z_]*\$/.test(sql.slice(i, i + 64))) {
|
|
78
|
+
// A dollar-quoted body (a DO block, a function): verbatim up to the matching tag.
|
|
79
|
+
const tag = /^\$[A-Za-z_]*\$/.exec(sql.slice(i, i + 64))[0];
|
|
80
|
+
const end = sql.indexOf(tag, i + tag.length);
|
|
81
|
+
const stop = end === -1 ? n : end + tag.length;
|
|
82
|
+
emit(sql.slice(i, stop));
|
|
83
|
+
i = stop;
|
|
84
|
+
}
|
|
85
|
+
else if (/\s/.test(c)) {
|
|
86
|
+
pendingSpace = true;
|
|
87
|
+
i += 1;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
emit(c.toLowerCase());
|
|
91
|
+
i += 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* SHA-256 of {@link normaliseSql}, the fingerprint the second matching pass compares.
|
|
98
|
+
*
|
|
99
|
+
* @param bytes - The raw `migration.sql` bytes.
|
|
100
|
+
* @returns 64 lower-case hex characters.
|
|
101
|
+
* @stability experimental
|
|
102
|
+
*/
|
|
103
|
+
function normalisedSha256(bytes) {
|
|
104
|
+
return (0, index_js_1.sha256Hex)(normaliseSql(Buffer.from(bytes).toString('utf8')));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Normalises one statement of `prisma migrate diff` output for comparison with
|
|
108
|
+
* a `deviations[].expectDiff` entry: removes `"public".` and collapses whitespace.
|
|
109
|
+
*
|
|
110
|
+
* @param statement - A statement.
|
|
111
|
+
* @returns The normalised statement.
|
|
112
|
+
* @stability experimental
|
|
113
|
+
*/
|
|
114
|
+
function normaliseStatement(statement) {
|
|
115
|
+
return statement.replace(/"public"\./g, '').replace(/\s+/g, ' ').trim();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Splits the SQL `prisma migrate diff --script` prints into statements:
|
|
119
|
+
* comment headings are dropped and each statement keeps its trailing `;`.
|
|
120
|
+
*
|
|
121
|
+
* @param script - The script text, banner lines already removed.
|
|
122
|
+
* @returns The statements; empty for an empty migration.
|
|
123
|
+
* @stability experimental
|
|
124
|
+
*/
|
|
125
|
+
function splitStatements(script) {
|
|
126
|
+
const cleaned = script.replace(/^\s*-- This is an empty migration\.\s*$/m, '');
|
|
127
|
+
return cleaned
|
|
128
|
+
.split(/;[ \t]*\r?\n/)
|
|
129
|
+
.map((chunk) => chunk.replace(/^(\s*--[^\n]*\n)+/g, '').trim())
|
|
130
|
+
.filter((chunk) => chunk !== '' && !/^--[^\n]*$/.test(chunk))
|
|
131
|
+
.map((chunk) => (chunk.endsWith(';') ? chunk : `${chunk};`));
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=normalise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalise.js","sourceRoot":"","sources":["../../src/baseline/normalise.ts"],"names":[],"mappings":";;AAgBA,oCA6DC;AASD,4CAEC;AAUD,gDAEC;AAUD,0CAOC;AArHD,+CAA6C;AAE7C;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAAC,GAAW;IACtC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,MAAM,IAAI,GAAG,CAAC,KAAa,EAAQ,EAAE;QACnC,iGAAiG;QACjG,IAAI,YAAY,IAAI,GAAG,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,GAAG,IAAI,GAAG,CAAC;QAC7F,YAAY,GAAG,KAAK,CAAC;QACrB,GAAG,IAAI,KAAK,C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