@marinoscar/platform-db 0.0.0-stage → 0.1.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/LICENSE +21 -0
- package/README.md +525 -2
- package/bin/platform.js +28 -0
- package/dist/baseline/deps.d.ts +32 -0
- package/dist/baseline/deps.d.ts.map +1 -0
- package/dist/baseline/deps.js +66 -0
- package/dist/baseline/deps.js.map +1 -0
- package/dist/baseline/errors.d.ts +36 -0
- package/dist/baseline/errors.d.ts.map +1 -0
- package/dist/baseline/errors.js +23 -0
- package/dist/baseline/errors.js.map +1 -0
- package/dist/baseline/fs.d.ts +9 -0
- package/dist/baseline/fs.d.ts.map +1 -0
- package/dist/baseline/fs.js +39 -0
- package/dist/baseline/fs.js.map +1 -0
- package/dist/baseline/index.d.ts +8 -0
- package/dist/baseline/index.d.ts.map +1 -0
- package/dist/baseline/index.js +24 -0
- package/dist/baseline/index.js.map +1 -0
- package/dist/baseline/mapping.d.ts +43 -0
- package/dist/baseline/mapping.d.ts.map +1 -0
- package/dist/baseline/mapping.js +80 -0
- package/dist/baseline/mapping.js.map +1 -0
- package/dist/baseline/normalise.d.ts +42 -0
- package/dist/baseline/normalise.d.ts.map +1 -0
- package/dist/baseline/normalise.js +133 -0
- package/dist/baseline/normalise.js.map +1 -0
- package/dist/baseline/plan.d.ts +66 -0
- package/dist/baseline/plan.d.ts.map +1 -0
- package/dist/baseline/plan.js +105 -0
- package/dist/baseline/plan.js.map +1 -0
- package/dist/baseline/report.d.ts +127 -0
- package/dist/baseline/report.d.ts.map +1 -0
- package/dist/baseline/report.js +89 -0
- package/dist/baseline/report.js.map +1 -0
- package/dist/baseline/run.d.ts +117 -0
- package/dist/baseline/run.d.ts.map +1 -0
- package/dist/baseline/run.js +358 -0
- package/dist/baseline/run.js.map +1 -0
- package/dist/bin/db-commands.d.ts +31 -0
- package/dist/bin/db-commands.d.ts.map +1 -0
- package/dist/bin/db-commands.js +311 -0
- package/dist/bin/db-commands.js.map +1 -0
- package/dist/bin/fs-io.d.ts +7 -0
- package/dist/bin/fs-io.d.ts.map +1 -0
- package/dist/bin/fs-io.js +45 -0
- package/dist/bin/fs-io.js.map +1 -0
- package/dist/bin/platform.d.ts +21 -0
- package/dist/bin/platform.d.ts.map +1 -0
- package/dist/bin/platform.js +99 -0
- package/dist/bin/platform.js.map +1 -0
- package/dist/compose/api.d.ts +84 -0
- package/dist/compose/api.d.ts.map +1 -0
- package/dist/compose/api.js +101 -0
- package/dist/compose/api.js.map +1 -0
- package/dist/compose/compose.d.ts +51 -0
- package/dist/compose/compose.d.ts.map +1 -0
- package/dist/compose/compose.js +177 -0
- package/dist/compose/compose.js.map +1 -0
- package/dist/compose/diff.d.ts +7 -0
- package/dist/compose/diff.d.ts.map +1 -0
- package/dist/compose/diff.js +68 -0
- package/dist/compose/diff.js.map +1 -0
- package/dist/compose/errors.d.ts +31 -0
- package/dist/compose/errors.d.ts.map +1 -0
- package/dist/compose/errors.js +35 -0
- package/dist/compose/errors.js.map +1 -0
- package/dist/compose/index.d.ts +3 -0
- package/dist/compose/index.d.ts.map +1 -0
- package/dist/compose/index.js +11 -0
- package/dist/compose/index.js.map +1 -0
- package/dist/compose/parse.d.ts +65 -0
- package/dist/compose/parse.d.ts.map +1 -0
- package/dist/compose/parse.js +122 -0
- package/dist/compose/parse.js.map +1 -0
- package/dist/drift/app-objects.d.ts +107 -0
- package/dist/drift/app-objects.d.ts.map +1 -0
- package/dist/drift/app-objects.js +193 -0
- package/dist/drift/app-objects.js.map +1 -0
- package/dist/drift/db-conformance.d.ts +52 -0
- package/dist/drift/db-conformance.d.ts.map +1 -0
- package/dist/drift/db-conformance.js +89 -0
- package/dist/drift/db-conformance.js.map +1 -0
- package/dist/drift/index.d.ts +8 -0
- package/dist/drift/index.d.ts.map +1 -0
- package/dist/drift/index.js +43 -0
- package/dist/drift/index.js.map +1 -0
- package/dist/drift/raw-sql-indexes.d.ts +106 -0
- package/dist/drift/raw-sql-indexes.d.ts.map +1 -0
- package/dist/drift/raw-sql-indexes.js +113 -0
- package/dist/drift/raw-sql-indexes.js.map +1 -0
- package/dist/drift/raw-sql-tripwire.d.ts +191 -0
- package/dist/drift/raw-sql-tripwire.d.ts.map +1 -0
- package/dist/drift/raw-sql-tripwire.js +422 -0
- package/dist/drift/raw-sql-tripwire.js.map +1 -0
- package/dist/drift/rls-policies.d.ts +226 -0
- package/dist/drift/rls-policies.d.ts.map +1 -0
- package/dist/drift/rls-policies.js +317 -0
- package/dist/drift/rls-policies.js.map +1 -0
- package/dist/drift/run.d.ts +152 -0
- package/dist/drift/run.d.ts.map +1 -0
- package/dist/drift/run.js +252 -0
- package/dist/drift/run.js.map +1 -0
- package/dist/drift/sql-expression.d.ts +27 -0
- package/dist/drift/sql-expression.d.ts.map +1 -0
- package/dist/drift/sql-expression.js +64 -0
- package/dist/drift/sql-expression.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/lock/hash.d.ts +13 -0
- package/dist/lock/hash.d.ts.map +1 -0
- package/dist/lock/hash.js +19 -0
- package/dist/lock/hash.js.map +1 -0
- package/dist/lock/index.d.ts +5 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js +20 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/lock/lock.d.ts +154 -0
- package/dist/lock/lock.d.ts.map +1 -0
- package/dist/lock/lock.js +151 -0
- package/dist/lock/lock.js.map +1 -0
- package/dist/lock/manifest.d.ts +68 -0
- package/dist/lock/manifest.d.ts.map +1 -0
- package/dist/lock/manifest.js +96 -0
- package/dist/lock/manifest.js.map +1 -0
- package/dist/lock/semver.d.ts +10 -0
- package/dist/lock/semver.d.ts.map +1 -0
- package/dist/lock/semver.js +13 -0
- package/dist/lock/semver.js.map +1 -0
- package/dist/seed/index.d.ts +5 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +16 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/seed/input.d.ts +52 -0
- package/dist/seed/input.d.ts.map +1 -0
- package/dist/seed/input.js +77 -0
- package/dist/seed/input.js.map +1 -0
- package/dist/seed/seed-platform.d.ts +41 -0
- package/dist/seed/seed-platform.d.ts.map +1 -0
- package/dist/seed/seed-platform.js +165 -0
- package/dist/seed/seed-platform.js.map +1 -0
- package/dist/seed/steps.d.ts +172 -0
- package/dist/seed/steps.d.ts.map +1 -0
- package/dist/seed/steps.js +136 -0
- package/dist/seed/steps.js.map +1 -0
- package/dist/seed/types.d.ts +287 -0
- package/dist/seed/types.d.ts.map +1 -0
- package/dist/seed/types.js +5 -0
- package/dist/seed/types.js.map +1 -0
- package/dist/sync/app-migrations.d.ts +52 -0
- package/dist/sync/app-migrations.d.ts.map +1 -0
- package/dist/sync/app-migrations.js +62 -0
- package/dist/sync/app-migrations.js.map +1 -0
- package/dist/sync/apply.d.ts +29 -0
- package/dist/sync/apply.d.ts.map +1 -0
- package/dist/sync/apply.js +38 -0
- package/dist/sync/apply.js.map +1 -0
- package/dist/sync/check.d.ts +59 -0
- package/dist/sync/check.d.ts.map +1 -0
- package/dist/sync/check.js +115 -0
- package/dist/sync/check.js.map +1 -0
- package/dist/sync/errors.d.ts +32 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +23 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +10 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +27 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/ledger.d.ts +65 -0
- package/dist/sync/ledger.d.ts.map +1 -0
- package/dist/sync/ledger.js +49 -0
- package/dist/sync/ledger.js.map +1 -0
- package/dist/sync/plan.d.ts +63 -0
- package/dist/sync/plan.d.ts.map +1 -0
- package/dist/sync/plan.js +86 -0
- package/dist/sync/plan.js.map +1 -0
- package/dist/sync/promote.d.ts +62 -0
- package/dist/sync/promote.d.ts.map +1 -0
- package/dist/sync/promote.js +95 -0
- package/dist/sync/promote.js.map +1 -0
- package/dist/sync/timestamps.d.ts +41 -0
- package/dist/sync/timestamps.d.ts.map +1 -0
- package/dist/sync/timestamps.js +68 -0
- package/dist/sync/timestamps.js.map +1 -0
- package/dist/sync/version.d.ts +28 -0
- package/dist/sync/version.d.ts.map +1 -0
- package/dist/sync/version.js +66 -0
- package/dist/sync/version.js.map +1 -0
- package/migrations/0001_initial/migration.sql +297 -0
- package/migrations/0002_add_personal_access_tokens/migration.sql +31 -0
- package/migrations/0003_add_credentials/migration.sql +20 -0
- package/migrations/0004_add_notification_deliveries/migration.sql +27 -0
- package/migrations/0005_drop_stale_uuid_defaults/migration.sql +35 -0
- package/migrations/0006_add_notifications/migration.sql +22 -0
- package/migrations/0007_add_push_subscriptions/migration.sql +25 -0
- package/migrations/0008_add_jobs/migration.sql +110 -0
- package/migrations/0009_add_worker_nodes/migration.sql +90 -0
- package/migrations/0010_add_database_backup_runs/migration.sql +104 -0
- package/migrations/0011_add_notification_broadcasts/migration.sql +57 -0
- package/migrations/0012_add_backup_run_job_link/migration.sql +87 -0
- package/migrations/0013_add_job_node_secrets/migration.sql +61 -0
- package/migrations/0014_add_backup_run_pg_dump_version/migration.sql +26 -0
- package/migrations/0015_add_job_claim_token/migration.sql +92 -0
- package/migrations/0016_add_ai_platform/migration.sql +108 -0
- package/migrations/0017_revoke_viewer_ai_use/migration.sql +32 -0
- package/migrations/0018_add_user_credentials/migration.sql +29 -0
- package/migrations/0019_add_device_session_credential_link/migration.sql +52 -0
- package/migrations/0020_add_worker_node_vitals/migration.sql +3 -0
- package/migrations/0021_add_job_trace_context/migration.sql +6 -0
- package/migrations/0022_add_retention_created_at_indexes/migration.sql +13 -0
- package/migrations/0023_add_organizations/migration.sql +142 -0
- package/migrations/0024_split_system_org_roles/migration.sql +131 -0
- package/migrations/0025_org_scoped_rls/migration.sql +215 -0
- package/migrations/0026_add_groups/migration.sql +165 -0
- package/migrations/0027_add_grants/migration.sql +117 -0
- package/migrations/0028_add_org_settings/migration.sql +49 -0
- package/migrations/0029_add_org_credentials/migration.sql +54 -0
- package/migrations/0030_add_jobs_org_id/migration.sql +18 -0
- package/migrations/0031_add_jobs_org_id_status_index/migration.sql +6 -0
- package/migrations/0032_add_broadcast_target_org/migration.sql +21 -0
- package/migrations/0033_add_android_app/migration.sql +60 -0
- package/migrations/0034_open_job_reason/migration.sql +16 -0
- package/migrations/0035_ai_usage_feature/migration.sql +37 -0
- package/migrations/0036_add_app_metadata/migration.sql +49 -0
- package/migrations/0037_open_sharing_vocabularies/migration.sql +97 -0
- package/migrations/manifest.json +379 -0
- package/package.json +78 -4
- package/raw-sql-indexes.json +94 -0
- package/rls-policies.json +74 -0
- package/schema/ai.prisma +444 -0
- package/schema/android-app.prisma +47 -0
- package/schema/base.prisma +11 -0
- package/schema/credentials.prisma +170 -0
- package/schema/db-backup.prisma +376 -0
- package/schema/identity.prisma +439 -0
- package/schema/jobs.prisma +760 -0
- package/schema/notifications.prisma +649 -0
- package/schema/settings.prisma +60 -0
- package/schema/sharing.prisma +223 -0
- package/schema/storage.prisma +84 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import type { SeedStepSummary } from './steps.js';
|
|
2
|
+
/**
|
|
3
|
+
* A JSON value, the shape of a `SystemSettings.value` column.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export type SeedJsonValue = string | number | boolean | null | SeedJsonValue[] | {
|
|
8
|
+
[key: string]: SeedJsonValue;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* What a role or a permission operates: the deployment (`'system'`) or one
|
|
12
|
+
* organization (`'org'`). The values of the `RoleScope` database enum.
|
|
13
|
+
*
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
export type SeedScope = 'system' | 'org';
|
|
17
|
+
/**
|
|
18
|
+
* A role or a permission as the seed writes it.
|
|
19
|
+
*
|
|
20
|
+
* @stability experimental
|
|
21
|
+
*/
|
|
22
|
+
export interface SeedNamedEntry {
|
|
23
|
+
/** The unique name (`admin`, `jobs:read`). */
|
|
24
|
+
name: string;
|
|
25
|
+
/** What it is for; refreshed on every run. */
|
|
26
|
+
description: string;
|
|
27
|
+
/**
|
|
28
|
+
* The scope, refreshed on every run like the description. Optional so a
|
|
29
|
+
* catalog written before scopes existed keeps working: an entry without one
|
|
30
|
+
* is written without one (the column default, `'system'`, applies on create
|
|
31
|
+
* and an existing row keeps its scope).
|
|
32
|
+
*/
|
|
33
|
+
scope?: SeedScope;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Everything `seedPlatform` writes. Every field a later slice adds (org-scoped
|
|
37
|
+
* roles, a default organization) is added as an **optional** field, so a
|
|
38
|
+
* caller written today keeps compiling.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const input = platformSeedInputFrom({ permissions, settings }, process.env);
|
|
43
|
+
* await seedPlatform(prisma, input, { info: console.log });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @extensionPoint option
|
|
47
|
+
* @stability experimental
|
|
48
|
+
*/
|
|
49
|
+
export interface PlatformSeedInput {
|
|
50
|
+
/** Roles, upserted by `name`; the description is updated on every run. */
|
|
51
|
+
roles: ReadonlyArray<SeedNamedEntry>;
|
|
52
|
+
/** Permissions, upserted by `name`; the description is updated on every run. */
|
|
53
|
+
permissions: ReadonlyArray<SeedNamedEntry>;
|
|
54
|
+
/** Default grants: role name to permission names. A name that no row carries is skipped, never created. */
|
|
55
|
+
roleGrants: Readonly<Record<string, readonly string[]>>;
|
|
56
|
+
/** The value of the `global` system settings row, composed from the namespaces. Written once, never overwritten. */
|
|
57
|
+
systemSettingsDefaults: Readonly<Record<string, unknown>>;
|
|
58
|
+
/** The email of the initial administrator. When set, it is added to the allowlist (lower-cased, never updated). */
|
|
59
|
+
initialAdminEmail?: string;
|
|
60
|
+
/**
|
|
61
|
+
* The default organization created when the database has none (default:
|
|
62
|
+
* `Default organization`, slug `default`). Never updated afterwards: an
|
|
63
|
+
* administrator may rename it.
|
|
64
|
+
*/
|
|
65
|
+
defaultOrganization?: SeedDefaultOrganization;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The default organization as the seed creates it.
|
|
69
|
+
*
|
|
70
|
+
* @stability experimental
|
|
71
|
+
*/
|
|
72
|
+
export interface SeedDefaultOrganization {
|
|
73
|
+
/** Display name. */
|
|
74
|
+
name: string;
|
|
75
|
+
/** Unique slug, lower-case `[a-z0-9-]`, 2 to 63 characters. */
|
|
76
|
+
slug: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Where `seedPlatform` reports progress. The package logs nothing by itself.
|
|
80
|
+
*
|
|
81
|
+
* @stability experimental
|
|
82
|
+
*/
|
|
83
|
+
export interface SeedLogger {
|
|
84
|
+
/**
|
|
85
|
+
* Report one line of progress.
|
|
86
|
+
*
|
|
87
|
+
* @param msg - The line, without a trailing newline.
|
|
88
|
+
*/
|
|
89
|
+
info(msg: string): void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* What one `seedPlatform` run did.
|
|
93
|
+
*
|
|
94
|
+
* @stability experimental
|
|
95
|
+
*/
|
|
96
|
+
export interface SeedSummary {
|
|
97
|
+
/** Roles upserted. */
|
|
98
|
+
roles: number;
|
|
99
|
+
/** Permissions upserted. */
|
|
100
|
+
permissions: number;
|
|
101
|
+
/** Role-permission grants upserted (a grant naming an unknown role or permission is not counted). */
|
|
102
|
+
rolePermissions: number;
|
|
103
|
+
/** Grants skipped because the role or the permission has no row, as `role: permission` (`role` alone for an unknown role). */
|
|
104
|
+
skippedGrants: string[];
|
|
105
|
+
/** The allowlisted initial administrator (lower-cased), or `null` when none was given. */
|
|
106
|
+
allowlistedEmail: string | null;
|
|
107
|
+
/** True when this run created the default organization; false when one already existed. */
|
|
108
|
+
defaultOrganizationCreated: boolean;
|
|
109
|
+
/** What each extra step did, in run order. Present only when the run was given `extras`. */
|
|
110
|
+
extras?: SeedStepSummary[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The arguments of an upsert, as the seed writes them.
|
|
114
|
+
*
|
|
115
|
+
* @stability experimental
|
|
116
|
+
*/
|
|
117
|
+
export interface SeedUpsertArgs<Where, Update, Create> {
|
|
118
|
+
/** The natural unique the row is found by. */
|
|
119
|
+
where: Where;
|
|
120
|
+
/** What an existing row is updated with (`{}` never overwrites). */
|
|
121
|
+
update: Update;
|
|
122
|
+
/** What a missing row is created with. */
|
|
123
|
+
create: Create;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The delegate of a table the seed upserts by `name` and looks up by `name`
|
|
127
|
+
* (`role`, `permission`).
|
|
128
|
+
*
|
|
129
|
+
* @stability experimental
|
|
130
|
+
*/
|
|
131
|
+
export interface SeedNamedDelegate {
|
|
132
|
+
/**
|
|
133
|
+
* Create the row, or refresh its description.
|
|
134
|
+
*
|
|
135
|
+
* @param args - Keyed on `name`.
|
|
136
|
+
* @returns Anything awaitable.
|
|
137
|
+
*/
|
|
138
|
+
upsert(args: SeedUpsertArgs<{
|
|
139
|
+
name: string;
|
|
140
|
+
}, {
|
|
141
|
+
description: string;
|
|
142
|
+
scope?: SeedScope;
|
|
143
|
+
}, SeedNamedEntry>): PromiseLike<unknown>;
|
|
144
|
+
/**
|
|
145
|
+
* Find the row id by name.
|
|
146
|
+
*
|
|
147
|
+
* @param args - Keyed on `name`.
|
|
148
|
+
* @returns The row, or `null` when none exists.
|
|
149
|
+
*/
|
|
150
|
+
findUnique(args: {
|
|
151
|
+
where: {
|
|
152
|
+
name: string;
|
|
153
|
+
};
|
|
154
|
+
}): PromiseLike<SeedRowId | null>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The only column of a looked-up row the seed reads.
|
|
158
|
+
*
|
|
159
|
+
* @stability experimental
|
|
160
|
+
*/
|
|
161
|
+
export interface SeedRowId {
|
|
162
|
+
/** The row's primary key. */
|
|
163
|
+
id: string;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The delegate of `role_permissions`.
|
|
167
|
+
*
|
|
168
|
+
* @stability experimental
|
|
169
|
+
*/
|
|
170
|
+
export interface SeedRolePermissionDelegate {
|
|
171
|
+
/**
|
|
172
|
+
* Create the grant when it is missing; an existing grant is left as it is.
|
|
173
|
+
*
|
|
174
|
+
* @param args - Keyed on `roleId_permissionId`.
|
|
175
|
+
* @returns Anything awaitable.
|
|
176
|
+
*/
|
|
177
|
+
upsert(args: SeedUpsertArgs<{
|
|
178
|
+
roleId_permissionId: {
|
|
179
|
+
roleId: string;
|
|
180
|
+
permissionId: string;
|
|
181
|
+
};
|
|
182
|
+
}, Record<string, never>, {
|
|
183
|
+
roleId: string;
|
|
184
|
+
permissionId: string;
|
|
185
|
+
}>): PromiseLike<unknown>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The delegate of `system_settings`.
|
|
189
|
+
*
|
|
190
|
+
* @stability experimental
|
|
191
|
+
*/
|
|
192
|
+
export interface SeedSystemSettingsDelegate {
|
|
193
|
+
/**
|
|
194
|
+
* Create the `global` row when it is missing; an existing row is left as it is.
|
|
195
|
+
*
|
|
196
|
+
* @param args - Keyed on `key`.
|
|
197
|
+
* @returns Anything awaitable.
|
|
198
|
+
*/
|
|
199
|
+
upsert(args: SeedUpsertArgs<{
|
|
200
|
+
key: string;
|
|
201
|
+
}, Record<string, never>, {
|
|
202
|
+
key: string;
|
|
203
|
+
value: {
|
|
204
|
+
[key: string]: SeedJsonValue;
|
|
205
|
+
};
|
|
206
|
+
version: number;
|
|
207
|
+
}>): PromiseLike<unknown>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The delegate of `allowed_emails`.
|
|
211
|
+
*
|
|
212
|
+
* @stability experimental
|
|
213
|
+
*/
|
|
214
|
+
export interface SeedAllowedEmailDelegate {
|
|
215
|
+
/**
|
|
216
|
+
* Create the allowlist entry when it is missing; an existing entry is left as it is.
|
|
217
|
+
*
|
|
218
|
+
* @param args - Keyed on `email`.
|
|
219
|
+
* @returns Anything awaitable.
|
|
220
|
+
*/
|
|
221
|
+
upsert(args: SeedUpsertArgs<{
|
|
222
|
+
email: string;
|
|
223
|
+
}, Record<string, never>, {
|
|
224
|
+
email: string;
|
|
225
|
+
notes: string;
|
|
226
|
+
}>): PromiseLike<unknown>;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The delegate of `organizations`.
|
|
230
|
+
*
|
|
231
|
+
* @stability experimental
|
|
232
|
+
*/
|
|
233
|
+
export interface SeedOrganizationDelegate {
|
|
234
|
+
/**
|
|
235
|
+
* Find the default organization, whatever its slug has become.
|
|
236
|
+
*
|
|
237
|
+
* @param args - Filters on `isDefault` and selects only `id`, so the seed never reads a column a later migration adds.
|
|
238
|
+
* @returns The row, or `null` when none is flagged default.
|
|
239
|
+
*/
|
|
240
|
+
findFirst(args: {
|
|
241
|
+
where: {
|
|
242
|
+
isDefault: true;
|
|
243
|
+
};
|
|
244
|
+
select: {
|
|
245
|
+
id: true;
|
|
246
|
+
};
|
|
247
|
+
}): PromiseLike<SeedRowId | null>;
|
|
248
|
+
/**
|
|
249
|
+
* Create the default organization when its slug is free; an existing row is left as it is.
|
|
250
|
+
*
|
|
251
|
+
* @param args - Keyed on `slug`.
|
|
252
|
+
* @returns Anything awaitable.
|
|
253
|
+
*/
|
|
254
|
+
upsert(args: SeedUpsertArgs<{
|
|
255
|
+
slug: string;
|
|
256
|
+
}, Record<string, never>, {
|
|
257
|
+
name: string;
|
|
258
|
+
slug: string;
|
|
259
|
+
isDefault: true;
|
|
260
|
+
}> & {
|
|
261
|
+
select: {
|
|
262
|
+
id: true;
|
|
263
|
+
};
|
|
264
|
+
}): PromiseLike<unknown>;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The part of a generated Prisma client the seed uses, as a structural type.
|
|
268
|
+
* The package compiles against these types and never imports or bundles a
|
|
269
|
+
* client: pass the app's `PrismaClient` (or a fake in a test).
|
|
270
|
+
*
|
|
271
|
+
* @stability experimental
|
|
272
|
+
*/
|
|
273
|
+
export interface SeedPrisma {
|
|
274
|
+
/** The `roles` table. */
|
|
275
|
+
role: SeedNamedDelegate;
|
|
276
|
+
/** The `permissions` table. */
|
|
277
|
+
permission: SeedNamedDelegate;
|
|
278
|
+
/** The `role_permissions` table. */
|
|
279
|
+
rolePermission: SeedRolePermissionDelegate;
|
|
280
|
+
/** The `system_settings` table. */
|
|
281
|
+
systemSettings: SeedSystemSettingsDelegate;
|
|
282
|
+
/** The `allowed_emails` table. */
|
|
283
|
+
allowedEmail: SeedAllowedEmailDelegate;
|
|
284
|
+
/** The `organizations` table. */
|
|
285
|
+
organization: SeedOrganizationDelegate;
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/seed/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,aAAa,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,CAAC;AAElH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E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kC;IAClC,YAAY,EAAE,wBAAwB,CAAC;IACvC,iCAAiC;IACjC,YAAY,EAAE,wBAAwB,CAAC;CACxC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Types of the platform seed (issue #712). Kept apart from the functions so the
|
|
3
|
+
// structural `SeedPrisma` can be read, and mocked, without importing a client.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/seed/types.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+EAA+E"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ManifestEntry, PlatformLock } from '../lock/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The class of an app-migration ordering failure.
|
|
4
|
+
*
|
|
5
|
+
* - `APP_MIGRATION_ID_COLLISION`: an app-authored migration directory is named exactly like a package migration (its id or directory), so the history cannot tell the two apart.
|
|
6
|
+
* - `APP_MIGRATION_OUT_OF_ORDER`: an app-authored migration directory sorts before an installed platform migration but was not there when `platform db sync` last wrote the lock, so a fresh database would apply it before platform migrations that were already applied elsewhere (it reorders history).
|
|
7
|
+
*
|
|
8
|
+
* @stability experimental
|
|
9
|
+
*/
|
|
10
|
+
export type AppMigrationProblemCode = 'APP_MIGRATION_ID_COLLISION' | 'APP_MIGRATION_OUT_OF_ORDER';
|
|
11
|
+
/**
|
|
12
|
+
* One app-authored migration that would collide with, or reorder, the installed platform history.
|
|
13
|
+
*
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
export interface AppMigrationProblem {
|
|
17
|
+
/** The class of failure. */
|
|
18
|
+
code: AppMigrationProblemCode;
|
|
19
|
+
/** The offending app-authored directory. */
|
|
20
|
+
localDir: string;
|
|
21
|
+
/** A one-line explanation naming the directory and the fix. */
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Finds the app-authored migrations that collide with, or would reorder, the
|
|
26
|
+
* installed platform history. An app-authored directory is one under
|
|
27
|
+
* `prisma/migrations` that no `platform.lock` entry names.
|
|
28
|
+
*
|
|
29
|
+
* Two rules, both offline:
|
|
30
|
+
*
|
|
31
|
+
* 1. **Id collision.** An app-authored directory must not be named like a
|
|
32
|
+
* package migration (`0036_add_app_metadata`): the history would hold two
|
|
33
|
+
* migrations the tooling cannot tell apart.
|
|
34
|
+
* 2. **Order.** `platform db sync` always installs a platform migration under
|
|
35
|
+
* a timestamp later than everything in the history, so an app migration that
|
|
36
|
+
* existed at that moment sorts before it by design (an app's own `add_notes`
|
|
37
|
+
* between two platform migrations is normal). One that appears *afterwards*
|
|
38
|
+
* with an older timestamp (a branch started before the sync, merged after)
|
|
39
|
+
* would run, on a fresh database, before platform migrations other
|
|
40
|
+
* databases applied first. The lock remembers which app directories existed
|
|
41
|
+
* at the last sync (`appMigrations`); a directory outside that list that
|
|
42
|
+
* sorts before the last installed platform directory is the failure. A lock
|
|
43
|
+
* without the field skips this rule until its next sync.
|
|
44
|
+
*
|
|
45
|
+
* @param manifest - The package history.
|
|
46
|
+
* @param lock - The app's `platform.lock`.
|
|
47
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
48
|
+
* @returns Every problem found, in directory order; empty when none.
|
|
49
|
+
* @stability experimental
|
|
50
|
+
*/
|
|
51
|
+
export declare function checkAppMigrations(manifest: readonly Pick<ManifestEntry, 'id' | 'dir'>[], lock: Pick<PlatformLock, 'migrations' | 'appMigrations'>, localDirs: readonly string[]): AppMigrationProblem[];
|
|
52
|
+
//# sourceMappingURL=app-migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-migrations.d.ts","sourceRoot":"","sources":["../../src/sync/app-migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,MAAM,uBAAuB,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;AAElG;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,IAAI,EAAE,uBAAuB,CAAC;IAC9B,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,KAAK,CAAC,EAAE,EACtD,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,GAAG,eAAe,CAAC,EACxD,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,mBAAmB,EAAE,CA4BvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkAppMigrations = checkAppMigrations;
|
|
4
|
+
/**
|
|
5
|
+
* Finds the app-authored migrations that collide with, or would reorder, the
|
|
6
|
+
* installed platform history. An app-authored directory is one under
|
|
7
|
+
* `prisma/migrations` that no `platform.lock` entry names.
|
|
8
|
+
*
|
|
9
|
+
* Two rules, both offline:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Id collision.** An app-authored directory must not be named like a
|
|
12
|
+
* package migration (`0036_add_app_metadata`): the history would hold two
|
|
13
|
+
* migrations the tooling cannot tell apart.
|
|
14
|
+
* 2. **Order.** `platform db sync` always installs a platform migration under
|
|
15
|
+
* a timestamp later than everything in the history, so an app migration that
|
|
16
|
+
* existed at that moment sorts before it by design (an app's own `add_notes`
|
|
17
|
+
* between two platform migrations is normal). One that appears *afterwards*
|
|
18
|
+
* with an older timestamp (a branch started before the sync, merged after)
|
|
19
|
+
* would run, on a fresh database, before platform migrations other
|
|
20
|
+
* databases applied first. The lock remembers which app directories existed
|
|
21
|
+
* at the last sync (`appMigrations`); a directory outside that list that
|
|
22
|
+
* sorts before the last installed platform directory is the failure. A lock
|
|
23
|
+
* without the field skips this rule until its next sync.
|
|
24
|
+
*
|
|
25
|
+
* @param manifest - The package history.
|
|
26
|
+
* @param lock - The app's `platform.lock`.
|
|
27
|
+
* @param localDirs - Every directory name under the app's `prisma/migrations`.
|
|
28
|
+
* @returns Every problem found, in directory order; empty when none.
|
|
29
|
+
* @stability experimental
|
|
30
|
+
*/
|
|
31
|
+
function checkAppMigrations(manifest, lock, localDirs) {
|
|
32
|
+
const problems = [];
|
|
33
|
+
const locked = new Set(lock.migrations.map((entry) => entry.localDir));
|
|
34
|
+
const packageNames = new Set(manifest.flatMap((entry) => [entry.id, entry.dir]));
|
|
35
|
+
const known = lock.appMigrations ? new Set(lock.appMigrations) : undefined;
|
|
36
|
+
let lastInstalled;
|
|
37
|
+
for (const entry of lock.migrations) {
|
|
38
|
+
if (lastInstalled === undefined || entry.localDir > lastInstalled)
|
|
39
|
+
lastInstalled = entry.localDir;
|
|
40
|
+
}
|
|
41
|
+
for (const dir of [...localDirs].sort()) {
|
|
42
|
+
if (locked.has(dir))
|
|
43
|
+
continue;
|
|
44
|
+
if (packageNames.has(dir)) {
|
|
45
|
+
problems.push({
|
|
46
|
+
code: 'APP_MIGRATION_ID_COLLISION',
|
|
47
|
+
localDir: dir,
|
|
48
|
+
message: `prisma/migrations/${dir} is named like the package migration ${dir}; an app migration keeps Prisma's timestamped name (nothing applied may be renamed: if it was never applied, rename it now)`,
|
|
49
|
+
});
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (known && lastInstalled !== undefined && dir < lastInstalled && !known.has(dir)) {
|
|
53
|
+
problems.push({
|
|
54
|
+
code: 'APP_MIGRATION_OUT_OF_ORDER',
|
|
55
|
+
localDir: dir,
|
|
56
|
+
message: `prisma/migrations/${dir} sorts before the installed platform migration ${lastInstalled} but was added after the last \`platform db sync\`; a fresh database would apply it before platform migrations other databases already ran. If it was never applied, give it a timestamp after ${lastInstalled}; if it was applied, record it by running \`platform db sync\``,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return problems;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=app-migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-migrations.js","sourceRoot":"","sources":["../../src/sync/app-migrations.ts"],"names":[],"mappings":";;AAqDA,gDAgCC;AA3DD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,kBAAkB,CAChC,QAAsD,EACtD,IAAwD,EACxD,SAA4B;IAE5B,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,IAAI,aAAiC,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QACpC,IAAI,aAAa,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,GAAG,aAAa;YAAE,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC;IACpG,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACxC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC9B,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,4BAA4B;gBAClC,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,qBAAqB,GAAG,wCAAwC,GAAG,6HAA6H;aAC1M,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QACD,IAAI,KAAK,IAAI,aAAa,KAAK,SAAS,IAAI,GAAG,GAAG,aAAa,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnF,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,4BAA4B;gBAClC,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,qBAAqB,GAAG,kDAAkD,aAAa,kMAAkM,aAAa,gEAAgE;aAChX,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type PlatformLock } from '../lock/index.js';
|
|
2
|
+
import { type SyncPlan } from './plan.js';
|
|
3
|
+
/**
|
|
4
|
+
* The file-system side of {@link applySync}, injectable so the logic is testable.
|
|
5
|
+
*
|
|
6
|
+
* @stability experimental
|
|
7
|
+
*/
|
|
8
|
+
export interface SyncIo {
|
|
9
|
+
/** Reads `<package>/migrations/<packageDir>/migration.sql`. */
|
|
10
|
+
readPackageFile(packageDir: string): Uint8Array;
|
|
11
|
+
/** Creates `prisma/migrations/<localDir>/migration.sql` with exactly these bytes; must throw when the directory already exists. */
|
|
12
|
+
writeLocalMigration(localDir: string, bytes: Uint8Array): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Executes a plan: byte-copies every planned migration into the app and
|
|
16
|
+
* returns the lock to write.
|
|
17
|
+
*
|
|
18
|
+
* Every package file is verified against its manifest hash before the first
|
|
19
|
+
* copy, so a stale or tampered package fails without leaving half an install.
|
|
20
|
+
* Bytes are copied verbatim: never re-encoded, never given a header.
|
|
21
|
+
*
|
|
22
|
+
* @param plan - The result of {@link planSync}.
|
|
23
|
+
* @param io - File access.
|
|
24
|
+
* @returns The new lock (the caller writes it with `serializeLock`).
|
|
25
|
+
* @throws SyncError `PACKAGE_FILE_MISMATCH` before any copy, or `LOCAL_DIR_EXISTS` from the io.
|
|
26
|
+
* @stability experimental
|
|
27
|
+
*/
|
|
28
|
+
export declare function applySync(plan: SyncPlan, io: SyncIo): PlatformLock;
|
|
29
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,+DAA+D;IAC/D,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;IAChD,mIAAmI;IACnI,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;CAChE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,CAmBlE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applySync = applySync;
|
|
4
|
+
const index_js_1 = require("../lock/index.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
const plan_js_1 = require("./plan.js");
|
|
7
|
+
/**
|
|
8
|
+
* Executes a plan: byte-copies every planned migration into the app and
|
|
9
|
+
* returns the lock to write.
|
|
10
|
+
*
|
|
11
|
+
* Every package file is verified against its manifest hash before the first
|
|
12
|
+
* copy, so a stale or tampered package fails without leaving half an install.
|
|
13
|
+
* Bytes are copied verbatim: never re-encoded, never given a header.
|
|
14
|
+
*
|
|
15
|
+
* @param plan - The result of {@link planSync}.
|
|
16
|
+
* @param io - File access.
|
|
17
|
+
* @returns The new lock (the caller writes it with `serializeLock`).
|
|
18
|
+
* @throws SyncError `PACKAGE_FILE_MISMATCH` before any copy, or `LOCAL_DIR_EXISTS` from the io.
|
|
19
|
+
* @stability experimental
|
|
20
|
+
*/
|
|
21
|
+
function applySync(plan, io) {
|
|
22
|
+
const files = plan.installs.map((install) => {
|
|
23
|
+
const bytes = io.readPackageFile(install.packageDir);
|
|
24
|
+
const actual = (0, index_js_1.sha256Hex)(bytes);
|
|
25
|
+
if (actual !== install.sha256) {
|
|
26
|
+
throw new errors_js_1.SyncError('PACKAGE_FILE_MISMATCH', `${install.originId}: package file hashes to ${actual}, the manifest says ${install.sha256}; the package is corrupt or a released migration was edited`);
|
|
27
|
+
}
|
|
28
|
+
return bytes;
|
|
29
|
+
});
|
|
30
|
+
plan.installs.forEach((install, i) => io.writeLocalMigration(install.localDir, files[i]));
|
|
31
|
+
return {
|
|
32
|
+
...plan.baseLock,
|
|
33
|
+
platformVersion: plan.installs.length ? plan.platformVersion : plan.baseLock.platformVersion,
|
|
34
|
+
migrations: [...plan.baseLock.migrations, ...plan.installs.map(plan_js_1.lockEntryOf)],
|
|
35
|
+
...(plan.installs.length ? { appMigrations: plan.appMigrations } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.js","sourceRoot":"","sources":["../../src/sync/apply.ts"],"names":[],"mappings":";;AA8BA,8BAmBC;AAjDD,+CAAgE;AAChE,2CAAwC;AACxC,uCAAuD;AAcvD;;;;;;;;;;;;;GAaG;AACH,SAAgB,SA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|
2
|
+
import { type AppMigrationProblemCode } from './app-migrations.js';
|
|
3
|
+
/**
|
|
4
|
+
* The class of a lock failure; each is named in the command's output.
|
|
5
|
+
*
|
|
6
|
+
* - `LOCAL_MODIFIED`: an installed file's bytes differ from the lock (`localSha256 ?? sha256`).
|
|
7
|
+
* - `PACKAGE_MODIFIED`: the lock's hash differs from the manifest's for the same origin id (a released migration was rewritten).
|
|
8
|
+
* - `PACKAGE_FILE_MODIFIED`: the package's `migration.sql` differs from its manifest hash (or is missing).
|
|
9
|
+
* - `NOT_INSTALLED`: a package migration is not in the lock; run `platform db sync`.
|
|
10
|
+
* - `LOCAL_DIR_MISSING`: a locked `localDir` does not exist.
|
|
11
|
+
* - `NOT_IN_PACKAGE`: the lock names a migration the manifest does not have.
|
|
12
|
+
* - `LOCAL_OUT_OF_ORDER`: installed directories do not sort in package order.
|
|
13
|
+
* - `APP_MIGRATION_ID_COLLISION` / `APP_MIGRATION_OUT_OF_ORDER`: an app-authored migration directory is named like a package migration, or would reorder the installed history (see {@link checkAppMigrations}); reported only when the caller passes `localDirs`.
|
|
14
|
+
*
|
|
15
|
+
* @stability experimental
|
|
16
|
+
*/
|
|
17
|
+
export type CheckProblemCode = 'LOCAL_MODIFIED' | 'PACKAGE_MODIFIED' | 'PACKAGE_FILE_MODIFIED' | 'NOT_INSTALLED' | 'LOCAL_DIR_MISSING' | 'NOT_IN_PACKAGE' | 'LOCAL_OUT_OF_ORDER' | AppMigrationProblemCode;
|
|
18
|
+
/**
|
|
19
|
+
* One offending migration.
|
|
20
|
+
*
|
|
21
|
+
* @stability experimental
|
|
22
|
+
*/
|
|
23
|
+
export interface CheckProblem {
|
|
24
|
+
/** The class of failure. */
|
|
25
|
+
code: CheckProblemCode;
|
|
26
|
+
/** The origin id of the offending migration. */
|
|
27
|
+
originId: string;
|
|
28
|
+
/** The app-local directory, when there is one. */
|
|
29
|
+
localDir?: string;
|
|
30
|
+
/** A one-line explanation naming the migration and the fix. */
|
|
31
|
+
message: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The outcome of {@link checkLock}.
|
|
35
|
+
*
|
|
36
|
+
* @stability experimental
|
|
37
|
+
*/
|
|
38
|
+
export interface CheckResult {
|
|
39
|
+
/** True when `problems` is empty. */
|
|
40
|
+
ok: boolean;
|
|
41
|
+
/** Every offending migration, locked ones first (lock order), then uninstalled ones. */
|
|
42
|
+
problems: CheckProblem[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* `platform db check`, offline half. Read-only and pure apart from the two
|
|
46
|
+
* readers. Fails when a locked migration's local bytes differ from the lock,
|
|
47
|
+
* the lock differs from the manifest, a package migration is not installed, or
|
|
48
|
+
* a locked directory is missing.
|
|
49
|
+
*
|
|
50
|
+
* @param manifest - The package history.
|
|
51
|
+
* @param lock - The app's `platform.lock`.
|
|
52
|
+
* @param readLocal - Reads `prisma/migrations/<localDir>/migration.sql`; returns `undefined` when the directory or file does not exist.
|
|
53
|
+
* @param readPackage - Optional: reads the package's actual `migration.sql` so a file edited without its manifest hash is also caught; `undefined` means missing.
|
|
54
|
+
* @param localDirs - Optional: every directory name under the app's `prisma/migrations`; when given, app-authored directories that collide with or reorder the installed history are reported too (see {@link checkAppMigrations}).
|
|
55
|
+
* @returns Every problem found; `ok` when there is none.
|
|
56
|
+
* @stability experimental
|
|
57
|
+
*/
|
|
58
|
+
export declare function checkLock(manifest: readonly ManifestEntry[], lock: PlatformLock, readLocal: (localDir: string) => Uint8Array | undefined, readPackage?: (packageDir: string) => Uint8Array | undefined, localDirs?: readonly string[]): CheckResult;
|
|
59
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/sync/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChG,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEvF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,gBAAgB,GACxB,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,eAAe,GACf,mBAAmB,GACnB,gBAAgB,GAChB,oBAAoB,GACpB,uBAAuB,CAAC;AAE5B;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,gBAAgB,CAAC;IACvB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,EAAE,EAAE,OAAO,CAAC;IACZ,wFAAwF;IACxF,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EACvD,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,EAC5D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAC5B,WAAW,CAgGb"}
|