@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,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scanRlsPolicies = exports.readPackageRlsPolicies = exports.checkRlsPolicySources = exports.checkRlsPolicies = exports.assertRlsPolicies = exports.RLS_POLICIES = exports.runDbConformance = exports.scanRawSqlIndexes = exports.scanFragmentIndexes = exports.checkRawSqlIndexSources = exports.scanAllIndexes = exports.assertRawSqlIndexes = exports.sqlExpressionSha256 = exports.normaliseSqlExpression = exports.readAppMigrations = exports.checkAppSchemaObjects = exports.assertAppSchemaObjects = exports.withShadowDatabase = exports.stripBanner = exports.schemaDiff = exports.runDrift = exports.readTableRlsRows = exports.readPolicyRows = 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, "readPolicyRows", { enumerable: true, get: function () { return run_js_1.readPolicyRows; } });
|
|
16
|
+
Object.defineProperty(exports, "readTableRlsRows", { enumerable: true, get: function () { return run_js_1.readTableRlsRows; } });
|
|
17
|
+
Object.defineProperty(exports, "runDrift", { enumerable: true, get: function () { return run_js_1.runDrift; } });
|
|
18
|
+
Object.defineProperty(exports, "schemaDiff", { enumerable: true, get: function () { return run_js_1.schemaDiff; } });
|
|
19
|
+
Object.defineProperty(exports, "stripBanner", { enumerable: true, get: function () { return run_js_1.stripBanner; } });
|
|
20
|
+
Object.defineProperty(exports, "withShadowDatabase", { enumerable: true, get: function () { return run_js_1.withShadowDatabase; } });
|
|
21
|
+
var app_objects_js_1 = require("./app-objects.js");
|
|
22
|
+
Object.defineProperty(exports, "assertAppSchemaObjects", { enumerable: true, get: function () { return app_objects_js_1.assertAppSchemaObjects; } });
|
|
23
|
+
Object.defineProperty(exports, "checkAppSchemaObjects", { enumerable: true, get: function () { return app_objects_js_1.checkAppSchemaObjects; } });
|
|
24
|
+
Object.defineProperty(exports, "readAppMigrations", { enumerable: true, get: function () { return app_objects_js_1.readAppMigrations; } });
|
|
25
|
+
var sql_expression_js_1 = require("./sql-expression.js");
|
|
26
|
+
Object.defineProperty(exports, "normaliseSqlExpression", { enumerable: true, get: function () { return sql_expression_js_1.normaliseSqlExpression; } });
|
|
27
|
+
Object.defineProperty(exports, "sqlExpressionSha256", { enumerable: true, get: function () { return sql_expression_js_1.sqlExpressionSha256; } });
|
|
28
|
+
var raw_sql_tripwire_js_1 = require("./raw-sql-tripwire.js");
|
|
29
|
+
Object.defineProperty(exports, "assertRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.assertRawSqlIndexes; } });
|
|
30
|
+
Object.defineProperty(exports, "scanAllIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.scanAllIndexes; } });
|
|
31
|
+
Object.defineProperty(exports, "checkRawSqlIndexSources", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.checkRawSqlIndexSources; } });
|
|
32
|
+
Object.defineProperty(exports, "scanFragmentIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.scanFragmentIndexes; } });
|
|
33
|
+
Object.defineProperty(exports, "scanRawSqlIndexes", { enumerable: true, get: function () { return raw_sql_tripwire_js_1.scanRawSqlIndexes; } });
|
|
34
|
+
var db_conformance_js_1 = require("./db-conformance.js");
|
|
35
|
+
Object.defineProperty(exports, "runDbConformance", { enumerable: true, get: function () { return db_conformance_js_1.runDbConformance; } });
|
|
36
|
+
var rls_policies_js_1 = require("./rls-policies.js");
|
|
37
|
+
Object.defineProperty(exports, "RLS_POLICIES", { enumerable: true, get: function () { return rls_policies_js_1.RLS_POLICIES; } });
|
|
38
|
+
Object.defineProperty(exports, "assertRlsPolicies", { enumerable: true, get: function () { return rls_policies_js_1.assertRlsPolicies; } });
|
|
39
|
+
Object.defineProperty(exports, "checkRlsPolicies", { enumerable: true, get: function () { return rls_policies_js_1.checkRlsPolicies; } });
|
|
40
|
+
Object.defineProperty(exports, "checkRlsPolicySources", { enumerable: true, get: function () { return rls_policies_js_1.checkRlsPolicySources; } });
|
|
41
|
+
Object.defineProperty(exports, "readPackageRlsPolicies", { enumerable: true, get: function () { return rls_policies_js_1.readPackageRlsPolicies; } });
|
|
42
|
+
Object.defineProperty(exports, "scanRlsPolicies", { enumerable: true, get: function () { return rls_policies_js_1.scanRlsPolicies; } });
|
|
43
|
+
//# 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,mCAckB;AAbhB,gGAAA,MAAM,OAAA;AACN,mGAAA,SAAS,OAAA;AACT,uGAAA,aAAa,OAAA;AACb,wGAAA,cAAc,OAAA;AACd,wGAAA,cAAc,OAAA;AACd,0GAAA,gBAAgB,OAAA;AAChB,kGAAA,QAAQ,OAAA;AACR,oGAAA,UAAU,OAAA;AACV,qGAAA,WAAW,OAAA;AACX,4GAAA,kBAAkB,OAAA;AAKpB,mDAQ0B;AAPxB,wHAAA,sBAAsB,OAAA;AACtB,uHAAA,qBAAqB,OAAA;AACrB,mHAAA,iBAAiB,OAAA;AAMnB,yDAAkF;AAAzE,2HAAA,sBAAsB,OAAA;AAAE,wHAAA,mBAAmB,OAAA;AACpD,6DAa+B;AAZ7B,0HAAA,mBAAmB,OAAA;AACnB,qHAAA,cAAc,OAAA;AACd,8HAAA,uBAAuB,OAAA;AACvB,0HAAA,mBAAmB,OAAA;AACnB,wHAAA,iBAAiB,OAAA;AASnB,yDAI6B;AAH3B,qHAAA,gBAAgB,OAAA;AAIlB,qDAmB2B;AAlBzB,+GAAA,YAAY,OAAA;AACZ,oHAAA,iBAAiB,OAAA;AACjB,mHAAA,gBAAgB,OAAA;AAChB,wHAAA,qBAAqB,OAAA;AACrB,yHAAA,sBAAsB,OAAA;AACtB,kHAAA,eAAe,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","source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AAC,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;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CAAC,IAAY;IACnD,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,sBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK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AC;IACtE,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC;QAC1G,CAAC;aAAM,IAAI,wBAAwB,CAAC,MAAM,CAAC,KAAK,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3F,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,0BAA0B;gBAChC,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,8CAA8C,wBAAwB,CAAC,KAAK,CAAC,UAAU,CAAC,iBAAiB,wBAAwB,CAAC,MAAM,CAAC,EAAE;aAClK,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAC,UAAkB;IAC9C,OAAO,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,uBAAuB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { ManifestEntry } from '../lock/index.js';
|
|
2
|
+
import { type PackageRawSqlIndex } from './raw-sql-indexes.js';
|
|
3
|
+
/**
|
|
4
|
+
* A raw-SQL index found by reading migration SQL: partial (`WHERE`) or keyed
|
|
5
|
+
* on an expression, which Prisma's schema language cannot express.
|
|
6
|
+
*
|
|
7
|
+
* @stability experimental
|
|
8
|
+
*/
|
|
9
|
+
export interface ScannedIndex {
|
|
10
|
+
/** The index name. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** The table, unquoted and without a schema. */
|
|
13
|
+
table: string;
|
|
14
|
+
/** Whether it is a unique index. */
|
|
15
|
+
unique: boolean;
|
|
16
|
+
/** The key columns in order, or `null` when any key element is an expression. */
|
|
17
|
+
columns: string[] | null;
|
|
18
|
+
/** The migration id that first creates an index of this name. */
|
|
19
|
+
createdIn: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The class of a tripwire failure.
|
|
23
|
+
*
|
|
24
|
+
* - `UNLISTED_RAW_INDEX`: a migration creates a partial or expression index that `RAW_SQL_INDEXES` does not list.
|
|
25
|
+
* - `LISTED_INDEX_NOT_FOUND`: a listed index is not created (or is dropped) by the migrations, or is no longer partial or expression.
|
|
26
|
+
* - `LISTED_INDEX_MISMATCH`: the listed table, uniqueness or `createdIn` disagrees with the migrations.
|
|
27
|
+
* - `FRAGMENT_DECLARES_RAW_INDEX`: a schema fragment declares `@@unique`, `@@index` or `@unique` under a listed index's name or on its key columns.
|
|
28
|
+
*
|
|
29
|
+
* @stability experimental
|
|
30
|
+
*/
|
|
31
|
+
export type TripwireProblemCode = 'UNLISTED_RAW_INDEX' | 'LISTED_INDEX_NOT_FOUND' | 'LISTED_INDEX_MISMATCH' | 'FRAGMENT_DECLARES_RAW_INDEX';
|
|
32
|
+
/**
|
|
33
|
+
* One tripwire failure.
|
|
34
|
+
*
|
|
35
|
+
* @stability experimental
|
|
36
|
+
*/
|
|
37
|
+
export interface TripwireProblem {
|
|
38
|
+
/** The class of failure. */
|
|
39
|
+
code: TripwireProblemCode;
|
|
40
|
+
/** The index name. */
|
|
41
|
+
name: string;
|
|
42
|
+
/** A one-line explanation naming the migration or fragment and the fix. */
|
|
43
|
+
message: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Removes `--` and block comments and splits on top-level semicolons; quotes
|
|
47
|
+
* are respected. Shared with the policy tripwire.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function splitSqlStatements(sql: string): string[];
|
|
52
|
+
/**
|
|
53
|
+
* The text inside the parenthesis opened at `open`, and what follows its closing one.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function balanced(text: string, open: number): {
|
|
58
|
+
inner: string;
|
|
59
|
+
rest: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* An index found by reading migration SQL, with whether it is raw (partial or
|
|
63
|
+
* keyed on an expression).
|
|
64
|
+
*
|
|
65
|
+
* @stability experimental
|
|
66
|
+
*/
|
|
67
|
+
export interface ScannedAnyIndex extends ScannedIndex {
|
|
68
|
+
/** True when the index has a `WHERE` clause or a key element that is an expression. */
|
|
69
|
+
raw: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Reads every index that migration SQL leaves behind, in statement order: a
|
|
73
|
+
* `CREATE INDEX` or `CREATE UNIQUE INDEX` statement adds one, `DROP INDEX`
|
|
74
|
+
* removes it and `ALTER INDEX` with `RENAME TO` renames it. Comments are
|
|
75
|
+
* ignored. {@link scanRawSqlIndexes} keeps only the raw ones.
|
|
76
|
+
*
|
|
77
|
+
* @param migrations - `[id, sql]` pairs in history order.
|
|
78
|
+
* @returns The indexes that survive the whole history, in creation order.
|
|
79
|
+
* @stability experimental
|
|
80
|
+
*/
|
|
81
|
+
export declare function scanAllIndexes(migrations: ReadonlyArray<readonly [string, string]>): ScannedAnyIndex[];
|
|
82
|
+
/**
|
|
83
|
+
* Reads the raw-SQL indexes that migration SQL leaves behind (see
|
|
84
|
+
* {@link scanAllIndexes}): an index is raw when it has a `WHERE` clause or any
|
|
85
|
+
* key element that is an expression.
|
|
86
|
+
*
|
|
87
|
+
* @param migrations - `[id, sql]` pairs in history order.
|
|
88
|
+
* @returns The raw-SQL indexes that survive the whole history, in creation order.
|
|
89
|
+
* @stability experimental
|
|
90
|
+
*/
|
|
91
|
+
export declare function scanRawSqlIndexes(migrations: ReadonlyArray<readonly [string, string]>): ScannedIndex[];
|
|
92
|
+
/**
|
|
93
|
+
* One `@@unique`, `@@index` or field-level `@unique` found in a fragment.
|
|
94
|
+
*
|
|
95
|
+
* @stability experimental
|
|
96
|
+
*/
|
|
97
|
+
export interface FragmentIndex {
|
|
98
|
+
/** The fragment's label, as passed to {@link scanFragmentIndexes}. */
|
|
99
|
+
file: string;
|
|
100
|
+
/** 1-based line of the declaration. */
|
|
101
|
+
line: number;
|
|
102
|
+
/** The Prisma model name. */
|
|
103
|
+
model: string;
|
|
104
|
+
/** The database table (`@@map`, else the model name). */
|
|
105
|
+
table: string;
|
|
106
|
+
/** Which declaration it is. */
|
|
107
|
+
kind: '@@unique' | '@@index' | '@unique';
|
|
108
|
+
/** Database column names in key order. */
|
|
109
|
+
columns: string[];
|
|
110
|
+
/** The database name given with `map:` or `name:`, when there is one. */
|
|
111
|
+
names: string[];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reads every model's index declarations out of `prisma format`-shaped schema
|
|
115
|
+
* text: `@@unique`, `@@index` and single-field `@unique`, with Prisma field
|
|
116
|
+
* names translated to database column names through `@map`.
|
|
117
|
+
*
|
|
118
|
+
* @param file - A label for messages.
|
|
119
|
+
* @param text - The fragment's text.
|
|
120
|
+
* @returns One entry per declaration.
|
|
121
|
+
* @stability experimental
|
|
122
|
+
*/
|
|
123
|
+
export declare function scanFragmentIndexes(file: string, text: string): FragmentIndex[];
|
|
124
|
+
/**
|
|
125
|
+
* What {@link checkRawSqlIndexSources} reads.
|
|
126
|
+
*
|
|
127
|
+
* @stability experimental
|
|
128
|
+
*/
|
|
129
|
+
export interface TripwireInput {
|
|
130
|
+
/** The package history, in order. */
|
|
131
|
+
manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[];
|
|
132
|
+
/** Reads a package migration's SQL by directory; `undefined` when it does not exist. */
|
|
133
|
+
readMigration: (dir: string) => string | undefined;
|
|
134
|
+
/** Every schema fragment: a label and its text. */
|
|
135
|
+
fragments: ReadonlyArray<{
|
|
136
|
+
/** A label for messages, usually the path. */
|
|
137
|
+
file: string;
|
|
138
|
+
/** The fragment's text. */
|
|
139
|
+
text: string;
|
|
140
|
+
}>;
|
|
141
|
+
/** The list to hold the migrations to; default {@link RAW_SQL_INDEXES}. */
|
|
142
|
+
listed?: ReadonlyArray<PackageRawSqlIndex>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The raw-SQL index tripwire, as a pure function. It fails when
|
|
146
|
+
*
|
|
147
|
+
* - a migration creates a partial or expression index that is not listed,
|
|
148
|
+
* - a listed index is not created by the migrations (or no longer partial or expression), or its table, uniqueness or `createdIn` disagree,
|
|
149
|
+
* - a schema fragment declares `@@unique`, `@@index` or `@unique` under a listed index's name, or on the same table and key columns.
|
|
150
|
+
*
|
|
151
|
+
* The last rule is the CLAUDE.md invariant in executable form: the indexes
|
|
152
|
+
* are intentional schema drift, never "fixed" with `@@unique`.
|
|
153
|
+
*
|
|
154
|
+
* @param input - See {@link TripwireInput}.
|
|
155
|
+
* @returns Every problem found, in a stable order; empty when the tripwire holds.
|
|
156
|
+
* @stability experimental
|
|
157
|
+
*/
|
|
158
|
+
export declare function checkRawSqlIndexSources(input: TripwireInput): TripwireProblem[];
|
|
159
|
+
/**
|
|
160
|
+
* The key columns of a listed index definition, or `undefined` when a key element is an expression.
|
|
161
|
+
*
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
export declare function columnsOfDefinition(definition: string): string[] | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* What {@link assertRawSqlIndexes} reads from disk.
|
|
167
|
+
*
|
|
168
|
+
* @stability experimental
|
|
169
|
+
*/
|
|
170
|
+
export interface AssertRawSqlIndexesOptions {
|
|
171
|
+
/** The package history (`migrations/manifest.json`, parsed). */
|
|
172
|
+
manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[];
|
|
173
|
+
/** The package's `migrations/` directory. */
|
|
174
|
+
migrationsDir: string;
|
|
175
|
+
/** The schema fragments directory (`schema/`); a missing directory means none. */
|
|
176
|
+
fragmentsDir: string;
|
|
177
|
+
/** The list to hold the migrations to; default {@link RAW_SQL_INDEXES}. */
|
|
178
|
+
listed?: ReadonlyArray<PackageRawSqlIndex>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Runs the raw-SQL index tripwire against the files on disk: the package's
|
|
182
|
+
* migrations (every manifest entry) and schema fragments. This is the entry
|
|
183
|
+
* the conformance suite and an app's CI call; see {@link checkRawSqlIndexSources}
|
|
184
|
+
* for the rules.
|
|
185
|
+
*
|
|
186
|
+
* @param options - See {@link AssertRawSqlIndexesOptions}.
|
|
187
|
+
* @throws Error listing every problem when the tripwire is tripped.
|
|
188
|
+
* @stability experimental
|
|
189
|
+
*/
|
|
190
|
+
export declare function assertRawSqlIndexes(options: AssertRawSqlIndexesOptions): void;
|
|
191
|
+
//# sourceMappingURL=raw-sql-tripwire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-sql-tripwire.d.ts","sourceRoot":"","sources":["../../src/drift/raw-sql-tripwire.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,iFAAiF;IACjF,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,mBAAmB,GAC3B,oBAAoB,GACpB,wB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