@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.3
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 +40 -0
- package/LICENSE +21 -0
- package/README.md +382 -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 +64 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +34 -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 +125 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +85 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +106 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +339 -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 +276 -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/db-conformance.d.ts +49 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +65 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +5 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +26 -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 +150 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +394 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- package/dist/drift/run.d.ts +128 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +201 -0
- package/dist/drift/run.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 +117 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +140 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +60 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +95 -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 +4 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +10 -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 +28 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +133 -0
- package/dist/seed/seed-platform.js.map +1 -0
- package/dist/seed/types.d.ts +277 -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/apply.d.ts +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +37 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +56 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +108 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +31 -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 +9 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +25 -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 +61 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +79 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +58 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +93 -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/manifest.json +240 -0
- package/package.json +75 -4
- package/raw-sql-indexes.json +49 -0
- package/schema/ai.prisma +387 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +108 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +407 -0
- package/schema/jobs.prisma +731 -0
- package/schema/notifications.prisma +610 -0
- package/schema/settings.prisma +35 -0
- package/schema/storage.prisma +57 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A deliberately small, line-oriented reader for `prisma format`-shaped schema
|
|
3
|
+
// text. It is NOT a Prisma parser (no Prisma-internal dependency: those APIs
|
|
4
|
+
// are unstable). It relies on two properties `prisma format` guarantees and
|
|
5
|
+
// that every fragment must keep; the composer rejects a file that breaks them:
|
|
6
|
+
// 1. a block header is `<kind> <Name> {` on ONE line, at column 0;
|
|
7
|
+
// 2. a block ends with `}` alone on a line, at column 0.
|
|
8
|
+
// Comments and blank lines between blocks are kept as the NEXT block's
|
|
9
|
+
// "leading" text, so a banner or a doc comment travels with its model.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.parseBlocks = parseBlocks;
|
|
12
|
+
exports.isExtensible = isExtensible;
|
|
13
|
+
exports.parseBody = parseBody;
|
|
14
|
+
exports.renderBlock = renderBlock;
|
|
15
|
+
const errors_js_1 = require("./errors.js");
|
|
16
|
+
const KINDS = 'model|enum|type|view|generator|datasource';
|
|
17
|
+
const HEADER = new RegExp(`^(?:(extend)\\s+)?(${KINDS})\\s+([A-Za-z_]\\w*)\\s*\\{\\s*$`);
|
|
18
|
+
const LOOSE_HEADER = new RegExp(`^\\s*(?:extend\\s+)?(?:${KINDS})\\s+\\w+\\s*(?:\\{.*)?$`);
|
|
19
|
+
const FIELD = /^\s*([A-Za-z_]\w*)\s+([A-Za-z_]\w*)(?:\([^)]*\))?(?:\[\])?\??(\s.*)?$/;
|
|
20
|
+
/**
|
|
21
|
+
* Splits one fragment into top-level blocks.
|
|
22
|
+
*
|
|
23
|
+
* @param src - File contents.
|
|
24
|
+
* @param file - Path to name in errors.
|
|
25
|
+
* @returns The blocks in file order and the text after the last block.
|
|
26
|
+
* @throws {@link ComposeError} `MALFORMED` for a header or footer that is not `prisma format` shaped.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
function parseBlocks(src, file) {
|
|
30
|
+
const lines = src.replace(/\r\n/g, '\n').split('\n');
|
|
31
|
+
const blocks = [];
|
|
32
|
+
let acc = [];
|
|
33
|
+
let cur = null;
|
|
34
|
+
lines.forEach((text, i) => {
|
|
35
|
+
const lineNo = i + 1;
|
|
36
|
+
if (!cur) {
|
|
37
|
+
const m = HEADER.exec(text);
|
|
38
|
+
if (m) {
|
|
39
|
+
cur = {
|
|
40
|
+
extend: m[1] === 'extend',
|
|
41
|
+
kind: m[2],
|
|
42
|
+
name: m[3],
|
|
43
|
+
leading: acc.join('\n'),
|
|
44
|
+
lines: [text],
|
|
45
|
+
line: lineNo,
|
|
46
|
+
};
|
|
47
|
+
acc = [];
|
|
48
|
+
}
|
|
49
|
+
else if (LOOSE_HEADER.test(text)) {
|
|
50
|
+
throw new errors_js_1.ComposeError('MALFORMED', file, lineNo, `a block header must be "<kind> <Name> {" on one line at column 0 (prisma format shape), got: ${text.trim()}`);
|
|
51
|
+
}
|
|
52
|
+
else if (text.trim() === '}') {
|
|
53
|
+
throw new errors_js_1.ComposeError('MALFORMED', file, lineNo, 'a "}" with no open block');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
acc.push(text);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
cur.lines.push(text);
|
|
61
|
+
if (text === '}') {
|
|
62
|
+
blocks.push(cur);
|
|
63
|
+
cur = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (cur) {
|
|
68
|
+
const open = cur;
|
|
69
|
+
throw new errors_js_1.ComposeError('MALFORMED', file, open.line, `block "${open.name}" is not closed by a "}" alone at column 0`);
|
|
70
|
+
}
|
|
71
|
+
return { blocks, trailing: acc.join('\n') };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Is the block marked `// @extensible` in the comment run directly above it?
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
function isExtensible(block) {
|
|
79
|
+
const above = block.leading.split('\n');
|
|
80
|
+
for (let i = above.length - 1; i >= 0; i--) {
|
|
81
|
+
const text = above[i].trim();
|
|
82
|
+
if (text === '')
|
|
83
|
+
break;
|
|
84
|
+
if (/^\/\/\s*@extensible\b/.test(text))
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The fields and block attributes of a model body.
|
|
91
|
+
*
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
function parseBody(block, file) {
|
|
95
|
+
const fields = [];
|
|
96
|
+
const attrs = [];
|
|
97
|
+
block.lines.slice(1, -1).forEach((raw, i) => {
|
|
98
|
+
const line = block.line + 1 + i;
|
|
99
|
+
const t = raw.trim();
|
|
100
|
+
if (t === '' || t.startsWith('//'))
|
|
101
|
+
return;
|
|
102
|
+
if (t.startsWith('@@')) {
|
|
103
|
+
attrs.push({ raw, line });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const m = FIELD.exec(raw);
|
|
107
|
+
if (!m) {
|
|
108
|
+
throw new errors_js_1.ComposeError('MALFORMED', file, line, `cannot read a field in ${block.name}: ${t}`);
|
|
109
|
+
}
|
|
110
|
+
fields.push({ name: m[1], type: m[2], attrs: m[3] ?? '', raw, line });
|
|
111
|
+
});
|
|
112
|
+
return { fields, attrs };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The block as text, with its leading comments.
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
function renderBlock(block) {
|
|
120
|
+
return `${block.leading ? `${block.leading}\n` : ''}${block.lines.join('\n')}`;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/compose/parse.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,+EAA+E;AAC/E,qEAAqE;AACrE,2DAA2D;AAC3D,uEAAuE;AACvE,uEAAuE;;AAgDvE,kCAiDC;AAOD,oCAQC;AAOD,8BAkBC;AAOD,kCAEC;AAhJD,2CAA2C;AAgC3C,MAAM,KAAK,GAAG,2CAA2C,CAAC;AAC1D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,KAAK,kCAAkC,CAAC,CAAC;AACzF,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,0BAA0B,KAAK,0BAA0B,CAAC,CAAC;AAC3F,MAAM,KAAK,GAAG,uEAAuE,CAAC;A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CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of a test runner {@link runDbConformance} needs; Jest and Vitest
|
|
3
|
+
* (`globals: true`) both fit, and neither is imported here.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface DbConformanceTestApi {
|
|
8
|
+
/** Registers a group of tests. */
|
|
9
|
+
describe(name: string, fn: () => void): void;
|
|
10
|
+
/** Registers one test; a thrown error fails it. */
|
|
11
|
+
it(name: string, fn: () => void): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* What an app passes to {@link runDbConformance}.
|
|
15
|
+
*
|
|
16
|
+
* @stability experimental
|
|
17
|
+
*/
|
|
18
|
+
export interface DbConformanceOptions {
|
|
19
|
+
/** The app directory that holds `prisma/` (`prisma/platform.lock`, `prisma/migrations`). */
|
|
20
|
+
appRoot: string;
|
|
21
|
+
/** The `@marinoscar/platform-db` package directory; default: the one this code runs from. */
|
|
22
|
+
packageDir?: string;
|
|
23
|
+
/** Defaults to the globals `describe` and `it` (Jest, or Vitest with `globals: true`). */
|
|
24
|
+
testApi?: DbConformanceTestApi;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Registers the `db` conformance suite: the invariants of the platform's data
|
|
28
|
+
* layer that an app proves in its own CI, offline (no database needed).
|
|
29
|
+
*
|
|
30
|
+
* - **raw-SQL index tripwire**: every partial or expression index the package's migrations create is listed in `RAW_SQL_INDEXES`, every listed one exists, and no schema fragment tries to "fix" one with `@@unique`/`@@index` (see {@link assertRawSqlIndexes}).
|
|
31
|
+
* - **platform.lock**: the app's installed migrations are byte-identical to the package's, every package migration is installed, and nothing is edited (see {@link checkLock}).
|
|
32
|
+
*
|
|
33
|
+
* Call it at the top level of a spec file. It is the data-layer counterpart of
|
|
34
|
+
* `runPlatformConformance()` in `@marinoscar/platform-api/testing`, which scans
|
|
35
|
+
* TypeScript source roots and so cannot run a check over SQL and Prisma files.
|
|
36
|
+
*
|
|
37
|
+
* @param options - See {@link DbConformanceOptions}.
|
|
38
|
+
* @throws Error when no test API is available.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // apps/api/test/prisma/platform-db-conformance.spec.ts
|
|
43
|
+
* runDbConformance({ appRoot: join(__dirname, '..', '..') });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @stability experimental
|
|
47
|
+
*/
|
|
48
|
+
export declare function runDbConformance(options: DbConformanceOptions): void;
|
|
49
|
+
//# sourceMappingURL=db-conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-conformance.d.ts","sourceRoot":"","sources":["../../src/drift/db-conformance.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC7C,mDAAmD;IACnD,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CACxC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,4FAA4F;IAC5F,OAAO,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAUD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CA+BpE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDbConformance = runDbConformance;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const index_js_1 = require("../lock/index.js");
|
|
7
|
+
const index_js_2 = require("../sync/index.js");
|
|
8
|
+
const raw_sql_tripwire_js_1 = require("./raw-sql-tripwire.js");
|
|
9
|
+
function globalTestApi() {
|
|
10
|
+
const g = globalThis;
|
|
11
|
+
if (typeof g.describe !== 'function' || typeof g.it !== 'function') {
|
|
12
|
+
throw new Error('runDbConformance: no global describe/it. Run it under Jest, under Vitest with `globals: true`, or pass `testApi`.');
|
|
13
|
+
}
|
|
14
|
+
return { describe: g.describe, it: g.it };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Registers the `db` conformance suite: the invariants of the platform's data
|
|
18
|
+
* layer that an app proves in its own CI, offline (no database needed).
|
|
19
|
+
*
|
|
20
|
+
* - **raw-SQL index tripwire**: every partial or expression index the package's migrations create is listed in `RAW_SQL_INDEXES`, every listed one exists, and no schema fragment tries to "fix" one with `@@unique`/`@@index` (see {@link assertRawSqlIndexes}).
|
|
21
|
+
* - **platform.lock**: the app's installed migrations are byte-identical to the package's, every package migration is installed, and nothing is edited (see {@link checkLock}).
|
|
22
|
+
*
|
|
23
|
+
* Call it at the top level of a spec file. It is the data-layer counterpart of
|
|
24
|
+
* `runPlatformConformance()` in `@marinoscar/platform-api/testing`, which scans
|
|
25
|
+
* TypeScript source roots and so cannot run a check over SQL and Prisma files.
|
|
26
|
+
*
|
|
27
|
+
* @param options - See {@link DbConformanceOptions}.
|
|
28
|
+
* @throws Error when no test API is available.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // apps/api/test/prisma/platform-db-conformance.spec.ts
|
|
33
|
+
* runDbConformance({ appRoot: join(__dirname, '..', '..') });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @stability experimental
|
|
37
|
+
*/
|
|
38
|
+
function runDbConformance(options) {
|
|
39
|
+
const api = options.testApi ?? globalTestApi();
|
|
40
|
+
const appRoot = (0, node_path_1.resolve)(options.appRoot);
|
|
41
|
+
// `src/drift` and `dist/drift` are both two levels below the package root.
|
|
42
|
+
const packageDir = (0, node_path_1.resolve)(options.packageDir ?? (0, node_path_1.join)(__dirname, '..', '..'));
|
|
43
|
+
const migrationsDir = (0, node_path_1.join)(packageDir, 'migrations');
|
|
44
|
+
const manifest = () => {
|
|
45
|
+
const file = (0, node_path_1.join)(migrationsDir, 'manifest.json');
|
|
46
|
+
return (0, index_js_1.parseManifest)((0, node_fs_1.readFileSync)(file, 'utf8'), file);
|
|
47
|
+
};
|
|
48
|
+
api.describe('platform-db conformance', () => {
|
|
49
|
+
api.it('raw-sql-indexes: every raw-SQL index is listed, present in the migrations, and not redeclared in a fragment', () => {
|
|
50
|
+
(0, raw_sql_tripwire_js_1.assertRawSqlIndexes)({ manifest: manifest(), migrationsDir, fragmentsDir: (0, node_path_1.join)(packageDir, 'schema') });
|
|
51
|
+
});
|
|
52
|
+
api.it('platform.lock: installed migrations are byte-identical to the package, none missing or edited', () => {
|
|
53
|
+
const lockFile = (0, node_path_1.join)(appRoot, 'prisma', 'platform.lock');
|
|
54
|
+
if (!(0, node_fs_1.existsSync)(lockFile))
|
|
55
|
+
throw new Error(`${lockFile} does not exist; run \`platform db sync\``);
|
|
56
|
+
const lock = (0, index_js_1.parseLock)((0, node_fs_1.readFileSync)(lockFile, 'utf8'), lockFile);
|
|
57
|
+
const read = (file) => ((0, node_fs_1.existsSync)(file) ? (0, node_fs_1.readFileSync)(file) : undefined);
|
|
58
|
+
const installed = (0, node_path_1.join)(appRoot, 'prisma', 'migrations');
|
|
59
|
+
const result = (0, index_js_2.checkLock)(manifest(), lock, (dir) => read((0, node_path_1.join)(installed, dir, 'migration.sql')), (dir) => read((0, node_path_1.join)(migrationsDir, dir, 'migration.sql')));
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
throw new Error(`platform.lock check failed:\n${result.problems.map((p) => ` ${p.code} ${p.message}`).join('\n')}`);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
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zD,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxI,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { RAW_SQL_INDEXES, checkRawSqlIndexes, isRawSqlIndex, normaliseIndexDefinition, readPackageRawSqlIndexes, type IndexRow, type PackageRawSqlIndex, type RawIndexProblem, type RawIndexProblemCode, } from './raw-sql-indexes.js';
|
|
2
|
+
export { loadPg, prismaCli, readIndexRows, readLedgerRows, runDrift, schemaDiff, stripBanner, withShadowDatabase, type DriftOptions, type DriftResult, type PgClient, } from './run.js';
|
|
3
|
+
export { assertRawSqlIndexes, checkRawSqlIndexSources, scanFragmentIndexes, scanRawSqlIndexes, type AssertRawSqlIndexesOptions, type FragmentIndex, type ScannedIndex, type TripwireInput, type TripwireProblem, type TripwireProblemCode, } from './raw-sql-tripwire.js';
|
|
4
|
+
export { runDbConformance, type DbConformanceOptions, type DbConformanceTestApi, } from './db-conformance.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/drift/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,MAAM,EACN,SAAS,EACT,aAAa,EACb,cAAc,EACd,QAAQ,EACR,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runDbConformance = exports.scanRawSqlIndexes = exports.scanFragmentIndexes = exports.checkRawSqlIndexSources = exports.assertRawSqlIndexes = exports.withShadowDatabase = exports.stripBanner = exports.schemaDiff = exports.runDrift = exports.readLedgerRows = exports.readIndexRows = exports.prismaCli = exports.loadPg = exports.readPackageRawSqlIndexes = exports.normaliseIndexDefinition = exports.isRawSqlIndex = exports.checkRawSqlIndexes = exports.RAW_SQL_INDEXES = void 0;
|
|
4
|
+
var raw_sql_indexes_js_1 = require("./raw-sql-indexes.js");
|
|
5
|
+
Object.defineProperty(exports, "RAW_SQL_INDEXES", { enumerable: true, get: function () { return raw_sql_indexes_js_1.RAW_SQL_INDEXES; } });
|
|
6
|
+
Object.defineProperty(exports, "checkRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_indexes_js_1.checkRawSqlIndexes; } });
|
|
7
|
+
Object.defineProperty(exports, "isRawSqlIndex", { enumerable: true, get: function () { return raw_sql_indexes_js_1.isRawSqlIndex; } });
|
|
8
|
+
Object.defineProperty(exports, "normaliseIndexDefinition", { enumerable: true, get: function () { return raw_sql_indexes_js_1.normaliseIndexDefinition; } });
|
|
9
|
+
Object.defineProperty(exports, "readPackageRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_indexes_js_1.readPackageRawSqlIndexes; } });
|
|
10
|
+
var run_js_1 = require("./run.js");
|
|
11
|
+
Object.defineProperty(exports, "loadPg", { enumerable: true, get: function () { return run_js_1.loadPg; } });
|
|
12
|
+
Object.defineProperty(exports, "prismaCli", { enumerable: true, get: function () { return run_js_1.prismaCli; } });
|
|
13
|
+
Object.defineProperty(exports, "readIndexRows", { enumerable: true, get: function () { return run_js_1.readIndexRows; } });
|
|
14
|
+
Object.defineProperty(exports, "readLedgerRows", { enumerable: true, get: function () { return run_js_1.readLedgerRows; } });
|
|
15
|
+
Object.defineProperty(exports, "runDrift", { enumerable: true, get: function () { return run_js_1.runDrift; } });
|
|
16
|
+
Object.defineProperty(exports, "schemaDiff", { enumerable: true, get: function () { return run_js_1.schemaDiff; } });
|
|
17
|
+
Object.defineProperty(exports, "stripBanner", { enumerable: true, get: function () { return run_js_1.stripBanner; } });
|
|
18
|
+
Object.defineProperty(exports, "withShadowDatabase", { enumerable: true, get: function () { return run_js_1.withShadowDatabase; } });
|
|
19
|
+
var raw_sql_tripwire_js_1 = require("./raw-sql-tripwire.js");
|
|
20
|
+
Object.defineProperty(exports, "assertRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.assertRawSqlIndexes; } });
|
|
21
|
+
Object.defineProperty(exports, "checkRawSqlIndexSources", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.checkRawSqlIndexSources; } });
|
|
22
|
+
Object.defineProperty(exports, "scanFragmentIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.scanFragmentIndexes; } });
|
|
23
|
+
Object.defineProperty(exports, "scanRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.scanRawSqlIndexes; } });
|
|
24
|
+
var db_conformance_js_1 = require("./db-conformance.js");
|
|
25
|
+
Object.defineProperty(exports, "runDbConformance", { enumerable: true, get: function () { return db_conformance_js_1.runDbConformance; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/drift/index.ts"],"names":[],"mappings":";;;AAAA,2DAU8B;AAT5B,qHAAA,eAAe,OAAA;AACf,wHAAA,kBAAkB,OAAA;AAClB,mHAAA,aAAa,OAAA;AACb,8HAAA,wBAAwB,OAAA;AACxB,8HAAA,wBAAwB,OAAA;AAM1B,mCAYkB;AAXhB,gGAAA,MAAM,OAAA;AACN,mGAAA,SAAS,OAAA;AACT,uGAAA,aAAa,OAAA;AACb,wGAAA,cAAc,OAAA;AACd,kGAAA,QAAQ,OAAA;AACR,oGAAA,UAAU,OAAA;AACV,qGAAA,WAAW,OAAA;AACX,4GAAA,kBAAkB,OAAA;AAKpB,6DAW+B;AAV7B,0HAAA,mBAAmB,OAAA;AACnB,8HAAA,uBAAuB,OAAA;AACvB,0HAAA,mBAAmB,OAAA;AACnB,wHAAA,iBAAiB,OAAA;AAQnB,yDAI6B;AAH3B,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { RawSqlIndex } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A raw-SQL index the package ships, with why it exists.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface PackageRawSqlIndex extends RawSqlIndex {
|
|
8
|
+
/** The table the index is on (the database name, not the Prisma model). */
|
|
9
|
+
table: string;
|
|
10
|
+
/** Whether it is a unique index. */
|
|
11
|
+
unique: boolean;
|
|
12
|
+
/** One line: why Prisma cannot express it and what it enforces. */
|
|
13
|
+
reason: string;
|
|
14
|
+
/** The repository document that explains the invariant, relative to the repository root. */
|
|
15
|
+
doc: string;
|
|
16
|
+
/** The platform migration id (`NNNN_slug`) that first creates it. */
|
|
17
|
+
createdIn: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A row of `pg_indexes`: an index name and its `indexdef`.
|
|
21
|
+
*
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export interface IndexRow {
|
|
25
|
+
/** The index name. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** `pg_indexes.indexdef`. */
|
|
28
|
+
definition: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads the package's `raw-sql-indexes.json`: partial and expression indexes
|
|
32
|
+
* that exist only in migration SQL because Prisma cannot express them.
|
|
33
|
+
*
|
|
34
|
+
* @param file - Path of the JSON file.
|
|
35
|
+
* @returns The indexes, in file order.
|
|
36
|
+
* @throws Error when the file is not valid.
|
|
37
|
+
* @stability experimental
|
|
38
|
+
*/
|
|
39
|
+
export declare function readPackageRawSqlIndexes(file: string): PackageRawSqlIndex[];
|
|
40
|
+
/**
|
|
41
|
+
* The package's raw-SQL indexes: partial and expression indexes that exist
|
|
42
|
+
* only in migration SQL because Prisma's schema language cannot express them.
|
|
43
|
+
* They are intentional schema drift: never "fixed" with `@@unique`, never
|
|
44
|
+
* replaced by a `findFirst` pre-check. The list is read from the shipped
|
|
45
|
+
* `raw-sql-indexes.json`, the single source of truth that `platform db drift`
|
|
46
|
+
* asserts against `pg_indexes` and that {@link assertRawSqlIndexes} checks
|
|
47
|
+
* against the migrations and the schema fragments.
|
|
48
|
+
*
|
|
49
|
+
* @stability experimental
|
|
50
|
+
*/
|
|
51
|
+
export declare const RAW_SQL_INDEXES: ReadonlyArray<PackageRawSqlIndex>;
|
|
52
|
+
/**
|
|
53
|
+
* The class of a raw-SQL index failure.
|
|
54
|
+
*
|
|
55
|
+
* - `INDEX_MISSING`: the index is not in `pg_indexes`.
|
|
56
|
+
* - `INDEX_DEFINITION_DIFFERS`: the index exists with another definition (for example a unique index re-created without its `WHERE` clause).
|
|
57
|
+
*
|
|
58
|
+
* @stability experimental
|
|
59
|
+
*/
|
|
60
|
+
export type RawIndexProblemCode = 'INDEX_MISSING' | 'INDEX_DEFINITION_DIFFERS';
|
|
61
|
+
/**
|
|
62
|
+
* One raw-SQL index that is missing or changed.
|
|
63
|
+
*
|
|
64
|
+
* @stability experimental
|
|
65
|
+
*/
|
|
66
|
+
export interface RawIndexProblem {
|
|
67
|
+
/** The class of failure. */
|
|
68
|
+
code: RawIndexProblemCode;
|
|
69
|
+
/** The index name. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** A one-line explanation. */
|
|
72
|
+
message: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Collapses whitespace so a definition compares equal across formatting.
|
|
76
|
+
*
|
|
77
|
+
* @param definition - `pg_indexes.indexdef`.
|
|
78
|
+
* @returns The definition with runs of whitespace as one space, trimmed.
|
|
79
|
+
* @stability experimental
|
|
80
|
+
*/
|
|
81
|
+
export declare function normaliseIndexDefinition(definition: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The positive assertion of the drift test: every expected raw-SQL index
|
|
84
|
+
* exists in the database with the recorded definition. `prisma migrate diff`
|
|
85
|
+
* ignores partial and expression indexes in both directions, so a dropped or
|
|
86
|
+
* weakened one is invisible to it; this is what catches that. It is an
|
|
87
|
+
* assertion, not a filter over diff output.
|
|
88
|
+
*
|
|
89
|
+
* @param expected - The package's list plus the app's (`platform.lock` `rawSqlIndexes`).
|
|
90
|
+
* @param live - `name` and `indexdef` rows of `pg_indexes`.
|
|
91
|
+
* @returns Every missing or changed index.
|
|
92
|
+
* @stability experimental
|
|
93
|
+
*/
|
|
94
|
+
export declare function checkRawSqlIndexes(expected: readonly RawSqlIndex[], live: readonly IndexRow[]): RawIndexProblem[];
|
|
95
|
+
/**
|
|
96
|
+
* Whether an `indexdef` is a raw-SQL index: partial (` WHERE `) or keyed on an
|
|
97
|
+
* expression (a parenthesised or function key). Used by the tripwire that
|
|
98
|
+
* derives the list from the catalogue so an unlisted raw-SQL index fails the
|
|
99
|
+
* build.
|
|
100
|
+
*
|
|
101
|
+
* @param definition - `pg_indexes.indexdef`.
|
|
102
|
+
* @returns True for a partial or expression index.
|
|
103
|
+
* @stability experimental
|
|
104
|
+
*/
|
|
105
|
+
export declare function isRawSqlIndex(definition: string): boolean;
|
|
106
|
+
//# sourceMappingURL=raw-sql-indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-sql-indexes.d.ts","sourceRoot":"","sources":["../../src/drift/raw-sql-indexes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAgBpD;;;;GAIG;AACH,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,GAAG,EAAE,MAAM,CAAC;IACZ,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAY3E;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,kBAAkB,CAG7D,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG,0BAA0B,CAAC;AAE/E;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,IAAI,EAAE,SAAS,QAAQ,EAAE,GACxB,eAAe,EAAE,CAgBnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RAW_SQL_INDEXES = void 0;
|
|
4
|
+
exports.readPackageRawSqlIndexes = readPackageRawSqlIndexes;
|
|
5
|
+
exports.normaliseIndexDefinition = normaliseIndexDefinition;
|
|
6
|
+
exports.checkRawSqlIndexes = checkRawSqlIndexes;
|
|
7
|
+
exports.isRawSqlIndex = isRawSqlIndex;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const packageIndexSchema = zod_1.z
|
|
12
|
+
.object({
|
|
13
|
+
name: zod_1.z.string().min(1),
|
|
14
|
+
table: zod_1.z.string().min(1),
|
|
15
|
+
unique: zod_1.z.boolean(),
|
|
16
|
+
definition: zod_1.z.string().min(1),
|
|
17
|
+
reason: zod_1.z.string().min(1),
|
|
18
|
+
doc: zod_1.z.string().min(1),
|
|
19
|
+
createdIn: zod_1.z.string().regex(/^\d{4}_[a-z0-9][a-z0-9_]*$/, 'expected a platform migration id, NNNN_slug'),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const packageListSchema = zod_1.z.object({ indexes: zod_1.z.array(packageIndexSchema) }).strict();
|
|
23
|
+
/**
|
|
24
|
+
* Reads the package's `raw-sql-indexes.json`: partial and expression indexes
|
|
25
|
+
* that exist only in migration SQL because Prisma cannot express them.
|
|
26
|
+
*
|
|
27
|
+
* @param file - Path of the JSON file.
|
|
28
|
+
* @returns The indexes, in file order.
|
|
29
|
+
* @throws Error when the file is not valid.
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
function readPackageRawSqlIndexes(file) {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new Error(`${file} is not valid JSON: ${error.message}`);
|
|
39
|
+
}
|
|
40
|
+
const parsed = packageListSchema.safeParse(raw);
|
|
41
|
+
if (!parsed.success) {
|
|
42
|
+
throw new Error(`${file} is invalid: ${parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ')}`);
|
|
43
|
+
}
|
|
44
|
+
return parsed.data.indexes;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The package's raw-SQL indexes: partial and expression indexes that exist
|
|
48
|
+
* only in migration SQL because Prisma's schema language cannot express them.
|
|
49
|
+
* They are intentional schema drift: never "fixed" with `@@unique`, never
|
|
50
|
+
* replaced by a `findFirst` pre-check. The list is read from the shipped
|
|
51
|
+
* `raw-sql-indexes.json`, the single source of truth that `platform db drift`
|
|
52
|
+
* asserts against `pg_indexes` and that {@link assertRawSqlIndexes} checks
|
|
53
|
+
* against the migrations and the schema fragments.
|
|
54
|
+
*
|
|
55
|
+
* @stability experimental
|
|
56
|
+
*/
|
|
57
|
+
exports.RAW_SQL_INDEXES = Object.freeze(
|
|
58
|
+
// `src/drift` and `dist/drift` are both two levels below the package root.
|
|
59
|
+
readPackageRawSqlIndexes((0, node_path_1.join)(__dirname, '..', '..', 'raw-sql-indexes.json')).map((index) => Object.freeze(index)));
|
|
60
|
+
/**
|
|
61
|
+
* Collapses whitespace so a definition compares equal across formatting.
|
|
62
|
+
*
|
|
63
|
+
* @param definition - `pg_indexes.indexdef`.
|
|
64
|
+
* @returns The definition with runs of whitespace as one space, trimmed.
|
|
65
|
+
* @stability experimental
|
|
66
|
+
*/
|
|
67
|
+
function normaliseIndexDefinition(definition) {
|
|
68
|
+
return definition.replace(/\s+/g, ' ').trim();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The positive assertion of the drift test: every expected raw-SQL index
|
|
72
|
+
* exists in the database with the recorded definition. `prisma migrate diff`
|
|
73
|
+
* ignores partial and expression indexes in both directions, so a dropped or
|
|
74
|
+
* weakened one is invisible to it; this is what catches that. It is an
|
|
75
|
+
* assertion, not a filter over diff output.
|
|
76
|
+
*
|
|
77
|
+
* @param expected - The package's list plus the app's (`platform.lock` `rawSqlIndexes`).
|
|
78
|
+
* @param live - `name` and `indexdef` rows of `pg_indexes`.
|
|
79
|
+
* @returns Every missing or changed index.
|
|
80
|
+
* @stability experimental
|
|
81
|
+
*/
|
|
82
|
+
function checkRawSqlIndexes(expected, live) {
|
|
83
|
+
const byName = new Map(live.map((row) => [row.name, row.definition]));
|
|
84
|
+
const problems = [];
|
|
85
|
+
for (const index of expected) {
|
|
86
|
+
const actual = byName.get(index.name);
|
|
87
|
+
if (actual === undefined) {
|
|
88
|
+
problems.push({ code: 'INDEX_MISSING', name: index.name, message: `${index.name}: not in pg_indexes` });
|
|
89
|
+
}
|
|
90
|
+
else if (normaliseIndexDefinition(actual) !== normaliseIndexDefinition(index.definition)) {
|
|
91
|
+
problems.push({
|
|
92
|
+
code: 'INDEX_DEFINITION_DIFFERS',
|
|
93
|
+
name: index.name,
|
|
94
|
+
message: `${index.name}: the live definition differs\n expected: ${normaliseIndexDefinition(index.definition)}\n actual: ${normaliseIndexDefinition(actual)}`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return problems;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Whether an `indexdef` is a raw-SQL index: partial (` WHERE `) or keyed on an
|
|
102
|
+
* expression (a parenthesised or function key). Used by the tripwire that
|
|
103
|
+
* derives the list from the catalogue so an unlisted raw-SQL index fails the
|
|
104
|
+
* build.
|
|
105
|
+
*
|
|
106
|
+
* @param definition - `pg_indexes.indexdef`.
|
|
107
|
+
* @returns True for a partial or expression index.
|
|
108
|
+
* @stability experimental
|
|
109
|
+
*/
|
|
110
|
+
function isRawSqlIndex(definition) {
|
|
111
|
+
return / WHERE /.test(definition) || / USING \w+ \([^()]*\(/.test(definition);
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=raw-sql-indexes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-sql-indexes.js","sourceRoot":"","sources":["../../src/drift/raw-sql-indexes.ts"],"names":[],"mappings":";;;AA0DA,4DAYC;AAiDD,4DAEC;AAcD,gDAmBC;AAYD,sCAEC;AAxKD,qCAAuC;AACvC,yCAAiC;AACjC,6BAAwB;AAGxB,MAAM,kBAAkB,GAAG,OAAC;KACzB,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,OAAC,CAAC,OAAO,EAAE;IACnB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,4BAA4B,EAAE,6CAA6C,CAAC;CACzG,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;AAgCtF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