@atscript/db 0.1.127 → 0.1.129
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/dist/{db-error-DXwEzmYJ.cjs → db-error-C4JuLcvb.cjs} +27 -0
- package/dist/{db-error-BHPXOKzc.mjs → db-error-COrO58t5.mjs} +22 -1
- package/dist/{db-readable-BkAGccv9.d.mts → db-readable-B7eYWS5q.d.cts} +299 -17
- package/dist/{db-readable-C0nDKX8A.d.cts → db-readable-Bn1bV_eC.d.mts} +299 -17
- package/dist/{db-space-B_ASuDaR.d.mts → db-space-C2UCnGHd.d.cts} +108 -30
- package/dist/{db-space-CSntT6yS.d.cts → db-space-DdIPYD0Q.d.mts} +108 -30
- package/dist/{db-view-BP0Qbeux.cjs → db-view-CRBgkEp0.cjs} +786 -100
- package/dist/{db-view-C8rZM5_N.mjs → db-view-Dl0aDTiT.mjs} +733 -101
- package/dist/index.cjs +48 -3
- package/dist/index.d.cts +162 -37
- package/dist/index.d.mts +162 -37
- package/dist/index.mjs +37 -5
- package/dist/{nested-writer-DI-HeTky.mjs → nested-writer-CkDo-ZfH.mjs} +1 -1
- package/dist/{nested-writer-DoDhl3X3.cjs → nested-writer-DxPhmWFz.cjs} +1 -1
- package/dist/{ops-DJRnNTVo.d.cts → ops-AqhV7s9o.d.cts} +24 -1
- package/dist/{ops-DJRnNTVo.d.mts → ops-AqhV7s9o.d.mts} +24 -1
- package/dist/ops.cjs +44 -1
- package/dist/ops.d.cts +2 -2
- package/dist/ops.d.mts +2 -2
- package/dist/ops.mjs +44 -2
- package/dist/plugin.cjs +12 -5
- package/dist/plugin.mjs +12 -5
- package/dist/rel.cjs +2 -2
- package/dist/rel.d.cts +1 -1
- package/dist/rel.d.mts +1 -1
- package/dist/rel.mjs +2 -2
- package/dist/{relation-loader-BnUgJsUG.cjs → relation-loader-C8GOpNYJ.cjs} +1 -1
- package/dist/{relation-loader-BmeOMj0b.mjs → relation-loader-CUGcxJ18.mjs} +1 -1
- package/dist/sync.cjs +1270 -398
- package/dist/sync.d.cts +255 -18
- package/dist/sync.d.mts +255 -18
- package/dist/sync.mjs +1269 -399
- package/dist/{validator-0vRXN51D.mjs → validator-CeD_fqyW.mjs} +21 -4
- package/dist/{validator-CSGug4vg.cjs → validator-lkCJKuoo.cjs} +32 -3
- package/dist/{validator-BcBtg8yW.d.cts → validator-wBARmD68.d.cts} +57 -1
- package/dist/{validator-BcBtg8yW.d.mts → validator-wBARmD68.d.mts} +57 -1
- package/dist/validator.cjs +7 -1
- package/dist/validator.d.cts +3 -3
- package/dist/validator.d.mts +3 -3
- package/dist/validator.mjs +4 -3
- package/package.json +8 -8
package/dist/sync.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as AtscriptDbView, t as DbSpace } from "./db-space-
|
|
1
|
+
import { B as TDbForeignKey, K as TDbObjectKind, L as TDbDefaultValue, O as TColumnDiff, Pt as TGenericLogger, Z as TDbStorageType, at as TExistingForeignKey, ht as TReferencingForeignKey, it as TExistingColumn, mt as TPrimaryKeyChange, ot as TExistingTableOption, rt as TEnsureTableOptions, t as AtscriptDbReadable, yt as TTableOptionDiff, z as TDbFieldMeta } from "./db-readable-Bn1bV_eC.mjs";
|
|
2
|
+
import { c as AtscriptQueryFieldRef$1, i as AtscriptDbView, l as AtscriptQueryNode$1, t as DbSpace } from "./db-space-DdIPYD0Q.mjs";
|
|
3
3
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/schema/sync-entry.d.ts
|
|
@@ -13,6 +13,13 @@ interface TSyncColors {
|
|
|
13
13
|
underline(s: string): string;
|
|
14
14
|
}
|
|
15
15
|
type TSyncEntryStatus = "create" | "alter" | "drop" | "in-sync" | "error";
|
|
16
|
+
/**
|
|
17
|
+
* Desired work safe mode did not apply (since 0.1.128): the primary-key
|
|
18
|
+
* rebuild, the `@db.sync.method 'drop'` recreate of a type change, the
|
|
19
|
+
* recreate a destructive table-option change needs, and nullable/default
|
|
20
|
+
* changes on adapters that need DDL for them.
|
|
21
|
+
*/
|
|
22
|
+
type TSyncSkippedWork = "pk-rebuild" | "recreate" | "table-options" | "nullable-defaults";
|
|
16
23
|
interface TSyncEntryInit {
|
|
17
24
|
name: string;
|
|
18
25
|
/** 'V' = virtual view, 'M' = materialized view, 'E' = external view, undefined = table */
|
|
@@ -59,6 +66,47 @@ interface TSyncEntryInit {
|
|
|
59
66
|
recreated?: boolean;
|
|
60
67
|
errors?: string[];
|
|
61
68
|
renamedFrom?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The table's primary-key field set changes. `rebuild: true` when sync
|
|
71
|
+
* rebuilds the key (empty table); `false` when the rebuild is skipped
|
|
72
|
+
* (safe mode). A populated table is refused instead (see `refused`).
|
|
73
|
+
* @since 0.1.128
|
|
74
|
+
*/
|
|
75
|
+
pkChange?: {
|
|
76
|
+
from: string[];
|
|
77
|
+
to: string[];
|
|
78
|
+
rebuild: boolean;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The work safe mode skipped on this table: `"pk-rebuild"` (`pkChange`
|
|
82
|
+
* kept with `rebuild: false`), `"recreate"` (`typeChanges` kept),
|
|
83
|
+
* `"table-options"` (`optionChanges` kept) and `"nullable-defaults"`
|
|
84
|
+
* (`nullableChanges` / `defaultChanges` kept). Each is pending: the
|
|
85
|
+
* table's snapshot and the schema hash are withheld, and the next run
|
|
86
|
+
* without `safe` applies it. Printed as `… — skipped (safe mode)`.
|
|
87
|
+
* Identical in the plan and in the run.
|
|
88
|
+
* @since 0.1.128
|
|
89
|
+
*/
|
|
90
|
+
skipped?: ReadonlyArray<TSyncSkippedWork>;
|
|
91
|
+
/**
|
|
92
|
+
* Names of the tables this entry's DDL waits for (FK parents for tables,
|
|
93
|
+
* entry/join tables for views, referencing children for drops).
|
|
94
|
+
* Informational — schema sync already executes in that order.
|
|
95
|
+
* @since 0.1.128
|
|
96
|
+
*/
|
|
97
|
+
dependsOn?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Present when the table is dropped together with the other members of a
|
|
100
|
+
* foreign-key cycle (one group operation).
|
|
101
|
+
* @since 0.1.128
|
|
102
|
+
*/
|
|
103
|
+
dropGroup?: string[];
|
|
104
|
+
/**
|
|
105
|
+
* `true` when this `error` entry is a pre-flight refusal: schema sync
|
|
106
|
+
* detected a change it cannot apply safely and issued no DDL at all.
|
|
107
|
+
* @since 0.1.128
|
|
108
|
+
*/
|
|
109
|
+
refused?: boolean;
|
|
62
110
|
}
|
|
63
111
|
declare class SyncEntry {
|
|
64
112
|
readonly name: string;
|
|
@@ -106,8 +154,44 @@ declare class SyncEntry {
|
|
|
106
154
|
readonly recreated: boolean;
|
|
107
155
|
readonly errors: string[];
|
|
108
156
|
readonly renamedFrom?: string;
|
|
157
|
+
/** @since 0.1.128 — see {@link TSyncEntryInit.pkChange}. */
|
|
158
|
+
readonly pkChange?: {
|
|
159
|
+
from: string[];
|
|
160
|
+
to: string[];
|
|
161
|
+
rebuild: boolean;
|
|
162
|
+
};
|
|
163
|
+
/** @since 0.1.128 — see {@link TSyncEntryInit.skipped}. */
|
|
164
|
+
readonly skipped: ReadonlyArray<TSyncSkippedWork>;
|
|
165
|
+
/** @since 0.1.128 — see {@link TSyncEntryInit.dependsOn}. */
|
|
166
|
+
readonly dependsOn: string[];
|
|
167
|
+
/** @since 0.1.128 — see {@link TSyncEntryInit.dropGroup}. */
|
|
168
|
+
readonly dropGroup?: string[];
|
|
169
|
+
/** @since 0.1.128 — see {@link TSyncEntryInit.refused}. */
|
|
170
|
+
readonly refused: boolean;
|
|
109
171
|
constructor(init: TSyncEntryInit);
|
|
110
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* The init object this entry was built from — lets callers derive a
|
|
174
|
+
* modified copy (`new SyncEntry({ ...entry.toInit(), status: "error" })`).
|
|
175
|
+
* @since 0.1.128
|
|
176
|
+
*/
|
|
177
|
+
toInit(): TSyncEntryInit;
|
|
178
|
+
/**
|
|
179
|
+
* This entry as an `error` entry with `msg` appended to its errors — the
|
|
180
|
+
* shape a DDL failure inside the entry's step reports (the planned work is
|
|
181
|
+
* kept, the status says it did not land).
|
|
182
|
+
* @since 0.1.129
|
|
183
|
+
*/
|
|
184
|
+
withError(msg: string): SyncEntry;
|
|
185
|
+
/**
|
|
186
|
+
* Whether desired work is still pending after this entry — DDL that was
|
|
187
|
+
* not issued because the entry errored or safe mode skipped it (see
|
|
188
|
+
* `skipped`). A pending entry withholds its snapshot and the schema hash,
|
|
189
|
+
* so the next run retries / applies it. External views are advisory and
|
|
190
|
+
* never pending.
|
|
191
|
+
* @since 0.1.128
|
|
192
|
+
*/
|
|
193
|
+
get pending(): boolean;
|
|
194
|
+
/** Whether this entry involves destructive operations (pending work safe mode skipped is not) */
|
|
111
195
|
get destructive(): boolean;
|
|
112
196
|
/** Whether this entry represents any change (not in-sync) */
|
|
113
197
|
get hasChanges(): boolean;
|
|
@@ -117,6 +201,24 @@ declare class SyncEntry {
|
|
|
117
201
|
print(mode: "plan" | "result", colors?: TSyncColors): string[];
|
|
118
202
|
private labelAndPrefix;
|
|
119
203
|
private printError;
|
|
204
|
+
/** `! PK (id) → (code) — rebuild (table is empty)` / `— skipped (safe mode)` */
|
|
205
|
+
private printPkChange;
|
|
206
|
+
/**
|
|
207
|
+
* `! col: t1 → t2 — drop` (plan), or `! type col (t1 → t2) — skipped (safe
|
|
208
|
+
* mode)` in plan and result when the `'drop'` recreate was skipped.
|
|
209
|
+
*/
|
|
210
|
+
private printTypeChanges;
|
|
211
|
+
/** `~ col — nullable` / `~ col — default a → b`, `— skipped (safe mode)` when pending. */
|
|
212
|
+
private printNullableDefaults;
|
|
213
|
+
/**
|
|
214
|
+
* Plan: `~ option k: a → b`, or `! option k: a → b — requires recreation`
|
|
215
|
+
* for a destructive change. Result: `~ option k: a → b` for an applied
|
|
216
|
+
* change. Both: `! option k: a → b — skipped (safe mode)` when pending.
|
|
217
|
+
*/
|
|
218
|
+
private printOptionChanges;
|
|
219
|
+
/** `· after: a, b` (plan only — the executor already runs in this order). */
|
|
220
|
+
private printDependsOn;
|
|
221
|
+
private printDropGroup;
|
|
120
222
|
private printPlan;
|
|
121
223
|
private printResult;
|
|
122
224
|
private printInSync;
|
|
@@ -158,12 +260,30 @@ interface TTableSnapshot {
|
|
|
158
260
|
/** Adapter-specific table-level options (e.g., MySQL engine/charset, MongoDB capped). */
|
|
159
261
|
tableOptions?: TExistingTableOption[];
|
|
160
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* One join of a managed view as stored in its snapshot.
|
|
265
|
+
* @since 0.1.128 — `joinTables` elements were bare target-table names before;
|
|
266
|
+
* the ON predicate is now part of the view definition.
|
|
267
|
+
*/
|
|
268
|
+
interface TViewJoinSnapshot {
|
|
269
|
+
targetTable: string;
|
|
270
|
+
/** Canonical JSON of the join condition (see {@link canonicalizeQueryNode}). */
|
|
271
|
+
condition: string;
|
|
272
|
+
/** Reserved for optional joins; absent today so it does not perturb the hash. */
|
|
273
|
+
kind?: "inner" | "left";
|
|
274
|
+
}
|
|
161
275
|
interface TViewSnapshot {
|
|
162
276
|
tableName: string;
|
|
163
277
|
viewType: "V" | "M" | "E";
|
|
164
278
|
entryTable?: string;
|
|
165
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Joins in declaration order. The key keeps its historical name so a
|
|
281
|
+
* join-less view (`[]`) serializes byte-identically to older snapshots.
|
|
282
|
+
*/
|
|
283
|
+
joinTables?: TViewJoinSnapshot[];
|
|
166
284
|
filterHash?: string;
|
|
285
|
+
/** @since 0.1.128 — hash of the canonical `@db.view.having` predicate. */
|
|
286
|
+
havingHash?: string;
|
|
167
287
|
materialized?: boolean;
|
|
168
288
|
fields: TFieldSnapshot[];
|
|
169
289
|
}
|
|
@@ -183,6 +303,30 @@ declare function computeTableSnapshot(readable: AtscriptDbReadable, typeMapper?:
|
|
|
183
303
|
* detecting view definition changes.
|
|
184
304
|
*/
|
|
185
305
|
declare function computeViewSnapshot(view: AtscriptDbView): TViewSnapshot;
|
|
306
|
+
/** Canonical (table-qualified, fixed-key-order) form of a view predicate. */
|
|
307
|
+
type TCanonicalQueryNode = {
|
|
308
|
+
and: TCanonicalQueryNode[];
|
|
309
|
+
} | {
|
|
310
|
+
or: TCanonicalQueryNode[];
|
|
311
|
+
} | {
|
|
312
|
+
not: TCanonicalQueryNode;
|
|
313
|
+
} /** `r` is `{ f: "<table>.<field>" }` for a field-to-field comparison, else the literal. */ | {
|
|
314
|
+
l: string;
|
|
315
|
+
op: string;
|
|
316
|
+
r?: unknown;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Converts a view predicate (join condition, `@db.view.filter`,
|
|
320
|
+
* `@db.view.having`) into a serializable structure whose JSON is a stable
|
|
321
|
+
* function of its MEANING: field refs become `qualify(ref)` — the view's
|
|
322
|
+
* `resolveFieldRef(ref, (n) => n)`, i.e. `"<table>.<field>"`, so a predicate
|
|
323
|
+
* retargeted to another table with the same field name changes — operators
|
|
324
|
+
* and literal values are kept as-is, `$and`/`$or` keep declaration order, and
|
|
325
|
+
* no function references survive. Two identical models produce byte-identical
|
|
326
|
+
* JSON.
|
|
327
|
+
* @since 0.1.128
|
|
328
|
+
*/
|
|
329
|
+
declare function canonicalizeQueryNode(node: AtscriptQueryNode$1, qualify: (ref: AtscriptQueryFieldRef$1) => string): TCanonicalQueryNode;
|
|
186
330
|
/**
|
|
187
331
|
* Computes a deterministic hash string from multiple table snapshots.
|
|
188
332
|
* Uses FNV-1a for speed — not cryptographic, just needs stability + collision resistance.
|
|
@@ -233,16 +377,23 @@ interface TSyncOptions {
|
|
|
233
377
|
pollIntervalMs?: number;
|
|
234
378
|
/** Force sync even if hash matches. Default: false. */
|
|
235
379
|
force?: boolean;
|
|
236
|
-
/**
|
|
380
|
+
/**
|
|
381
|
+
* Safe mode — skip destructive operations (column/table drops, `'drop'`
|
|
382
|
+
* recreates, destructive table-option recreates, key rebuilds, nullable /
|
|
383
|
+
* default DDL). Skipped work is pending (`entry.skipped`): the table's
|
|
384
|
+
* snapshot and the hash are withheld until a run without `safe` applies
|
|
385
|
+
* it. Default: false.
|
|
386
|
+
*/
|
|
237
387
|
safe?: boolean;
|
|
238
388
|
/**
|
|
239
|
-
* Logger for sync progress and failures (
|
|
240
|
-
* not thrown). Default: NoopLogger —
|
|
389
|
+
* Logger for sync progress and failures (DDL errors inside a table's step
|
|
390
|
+
* are logged and recorded on its entry, not thrown). Default: NoopLogger —
|
|
391
|
+
* pass `console` to surface them.
|
|
241
392
|
*/
|
|
242
393
|
logger?: TGenericLogger;
|
|
243
394
|
/**
|
|
244
|
-
* What to do when the run finishes with errored entries (failed
|
|
245
|
-
*
|
|
395
|
+
* What to do when the run finishes with errored entries (failed DDL inside
|
|
396
|
+
* a table's step, external-view checks, pre-flight refusals, …):
|
|
246
397
|
* - `"warn"` (default) — emit a one-line summary plus per-entry error lines
|
|
247
398
|
* via the configured logger, **falling back to `console` when no logger
|
|
248
399
|
* is set** (errors are never silently swallowed by the NoopLogger default);
|
|
@@ -252,7 +403,16 @@ interface TSyncOptions {
|
|
|
252
403
|
onError?: "throw" | "warn" | "silent";
|
|
253
404
|
}
|
|
254
405
|
interface TSyncResult {
|
|
255
|
-
|
|
406
|
+
/**
|
|
407
|
+
* - `"up-to-date"` — stored hash matches, nothing ran;
|
|
408
|
+
* - `"synced"` — the run executed (inspect `entries` for per-table status);
|
|
409
|
+
* - `"synced-by-peer"` — another pod synced while this one waited for the lock;
|
|
410
|
+
* - `"refused"` (since 0.1.128) — pre-flight found a change that cannot be
|
|
411
|
+
* applied safely: NO DDL ran, tracking/snapshots/hash are untouched, the
|
|
412
|
+
* lock is released. `entries` is the full plan with the refused entries
|
|
413
|
+
* as `error` entries (`refused: true`).
|
|
414
|
+
*/
|
|
415
|
+
status: "up-to-date" | "synced" | "synced-by-peer" | "refused";
|
|
256
416
|
schemaHash: string;
|
|
257
417
|
entries: SyncEntry[];
|
|
258
418
|
}
|
|
@@ -272,8 +432,8 @@ declare class SchemaSync {
|
|
|
272
432
|
*/
|
|
273
433
|
private checkExternalView;
|
|
274
434
|
/**
|
|
275
|
-
* Detects tables/views present in the previous sync but absent from the
|
|
276
|
-
*
|
|
435
|
+
* Detects tables/views present in the previous sync but absent from the
|
|
436
|
+
* current schema (external views excluded — sync owns no DDL for them).
|
|
277
437
|
*/
|
|
278
438
|
private detectRemoved;
|
|
279
439
|
/**
|
|
@@ -285,9 +445,58 @@ declare class SchemaSync {
|
|
|
285
445
|
/** Throws if the heartbeat detected a stolen/missing lock. */
|
|
286
446
|
private assertLockHeld;
|
|
287
447
|
/**
|
|
288
|
-
* Runs schema synchronization with distributed locking
|
|
448
|
+
* Runs schema synchronization with distributed locking, in three phases:
|
|
449
|
+
*
|
|
450
|
+
* 1. **Discover** (read-only, under the lock): introspect every table once,
|
|
451
|
+
* diff columns/FKs, read tracking, build the dependency graph.
|
|
452
|
+
* 2. **Pre-flight** (pure): every change that no order of DDL can apply
|
|
453
|
+
* safely becomes a refusal. One refusal → `status: "refused"`, no DDL,
|
|
454
|
+
* nothing persisted, lock released.
|
|
455
|
+
* 3. **Execute** in dependency order: stale/removed views → inbound FKs of
|
|
456
|
+
* key-changing tables → tables (parents first; a removed table that
|
|
457
|
+
* blocks a table's drop-and-recreate or key rebuild is dropped right
|
|
458
|
+
* before it) → deferred FKs of cycles → managed views → external-view
|
|
459
|
+
* checks → remaining removed tables (children first) →
|
|
460
|
+
* snapshots/tracking/hash.
|
|
289
461
|
*/
|
|
290
462
|
run(types: readonly TAtscriptAnnotatedType[], opts?: TSyncOptions): Promise<TSyncResult>;
|
|
463
|
+
private discover;
|
|
464
|
+
/** Whether an object named `name` exists, or `undefined` when the adapter cannot tell. */
|
|
465
|
+
private objectPresent;
|
|
466
|
+
/**
|
|
467
|
+
* Introspects one desired table and computes its plan entry.
|
|
468
|
+
* `probeRecreateInbound` — whether a drop-and-recreate's live inbound FKs
|
|
469
|
+
* are worth probing (a removed table exists that could block it).
|
|
470
|
+
* `safe` — safe mode skips the key rebuild, so its plan rule does not apply.
|
|
471
|
+
*/
|
|
472
|
+
private discoverTable;
|
|
473
|
+
/**
|
|
474
|
+
* Pure validation over the discovery facts. Every refusal is a change that
|
|
475
|
+
* no order of DDL can apply safely; the messages are user-facing.
|
|
476
|
+
*/
|
|
477
|
+
private preflight;
|
|
478
|
+
/**
|
|
479
|
+
* The one ordering walk `plan()` and `run()` share: tables parents-first,
|
|
480
|
+
* each preceded by the removed tables that block its drop/rebuild; the
|
|
481
|
+
* deferred FK pass; managed views; external-view checks; removed views;
|
|
482
|
+
* the remaining removed tables children-first.
|
|
483
|
+
*/
|
|
484
|
+
private orderedSteps;
|
|
485
|
+
/** The plan entries in execution order, refusals folded in as `error` entries. */
|
|
486
|
+
private buildPlanEntries;
|
|
487
|
+
private execute;
|
|
488
|
+
/**
|
|
489
|
+
* Drops one removed-table group (a table, or a foreign-key cycle as one
|
|
490
|
+
* operation) and returns its entries. A live inbound FK from outside the
|
|
491
|
+
* removed set blocks the group — error entries, kept tracked — instead of
|
|
492
|
+
* leaving a dangling constraint or cascading. The probe runs at execution
|
|
493
|
+
* time, so an inventory child whose FK to the group was dropped earlier in
|
|
494
|
+
* this run does not block it. Called from the walk for early groups (right
|
|
495
|
+
* before the table they block) and late groups (after the views) alike.
|
|
496
|
+
*/
|
|
497
|
+
private dropRemovedGroup;
|
|
498
|
+
/** The error-entry message of a DDL failure inside a view step, logged at error level. */
|
|
499
|
+
private stepFailed;
|
|
291
500
|
/**
|
|
292
501
|
* Surfaces the run outcome per the `onError` policy. Reporting must never be
|
|
293
502
|
* silently lost to the NoopLogger default — when no real logger is
|
|
@@ -296,22 +505,32 @@ declare class SchemaSync {
|
|
|
296
505
|
*/
|
|
297
506
|
private reportOutcome;
|
|
298
507
|
/**
|
|
299
|
-
* Computes a dry-run plan showing what `run()` would do, without executing
|
|
508
|
+
* Computes a dry-run plan showing what `run()` would do, without executing
|
|
509
|
+
* any DDL. Entries come back in execution order; pre-flight refusals appear
|
|
510
|
+
* as `error` entries (`refused: true`) exactly as `run()` would report them.
|
|
300
511
|
*/
|
|
301
512
|
plan(types: readonly TAtscriptAnnotatedType[], opts?: Pick<TSyncOptions, "force" | "safe">): Promise<TSyncPlan>;
|
|
302
513
|
/** Fallback typeMapper for snapshot-based Path B: compares designType directly, skips unions. */
|
|
303
514
|
private resolveTypeMapper;
|
|
304
|
-
private planTable;
|
|
305
515
|
/**
|
|
306
516
|
* Populates plan init from a column diff (shared by Path A and Path B).
|
|
517
|
+
*
|
|
518
|
+
* The plan's rule set is canonical (since 0.1.129): every change the
|
|
519
|
+
* executor cannot apply without DDL it does not have is an `error` entry
|
|
520
|
+
* here, and `executeSyncTable` returns an errored plan entry untouched —
|
|
521
|
+
* so the executor's own copies of these rules are reached only when
|
|
522
|
+
* discovery had no diff (a pending rename whose old name it could not
|
|
523
|
+
* introspect).
|
|
307
524
|
*/
|
|
308
525
|
private populatePlanFromDiff;
|
|
309
526
|
/**
|
|
310
527
|
* Computes table option diff using DB-first introspection with snapshot fallback.
|
|
311
|
-
* Returns null if the adapter has no table options.
|
|
528
|
+
* Returns null if the adapter has no table options. `tableName` is the name
|
|
529
|
+
* the table has in the database right now — the OLD name of a pending
|
|
530
|
+
* `@db.table.renamed` (the adapter's bound name is the new one, which does
|
|
531
|
+
* not exist yet); omitted for a table that is not being renamed.
|
|
312
532
|
*/
|
|
313
533
|
private diffTableOptions;
|
|
314
|
-
private planView;
|
|
315
534
|
private buildExecutorDeps;
|
|
316
535
|
}
|
|
317
536
|
//#endregion
|
|
@@ -365,6 +584,24 @@ declare function computeForeignKeyDiff(desired: ReadonlyMap<string, TDbForeignKe
|
|
|
365
584
|
/** Whether the FK diff contains any changes. */
|
|
366
585
|
declare function hasForeignKeyChanges(diff: TForeignKeyDiff): boolean;
|
|
367
586
|
//#endregion
|
|
587
|
+
//#region src/schema/dependency-order.d.ts
|
|
588
|
+
/** A directed edge `from → to`: `from` depends on `to` (child → parent). */
|
|
589
|
+
type TDependencyEdge = readonly [from: string, to: string];
|
|
590
|
+
/**
|
|
591
|
+
* Orders `nodes` so that dependencies come first. Returns the strongly-
|
|
592
|
+
* connected components in dependency order: every group appears AFTER each
|
|
593
|
+
* group it depends on (parents first). Singleton groups are ordinary tables;
|
|
594
|
+
* groups of size > 1 are cycles. Members are name-sorted.
|
|
595
|
+
*
|
|
596
|
+
* - Edges referencing a name outside `nodes` are ignored (external tables
|
|
597
|
+
* impose no ordering).
|
|
598
|
+
* - Self-loops are ignored (a self-referential FK is legal inline everywhere).
|
|
599
|
+
* - Deterministic: nodes and adjacency lists are sorted by name before the
|
|
600
|
+
* traversal, so two processes with different inventory orders compute the
|
|
601
|
+
* same plan.
|
|
602
|
+
*/
|
|
603
|
+
declare function topoOrder(nodes: Iterable<string>, edges: Iterable<TDependencyEdge>): string[][];
|
|
604
|
+
//#endregion
|
|
368
605
|
//#region src/sync.d.ts
|
|
369
606
|
/**
|
|
370
607
|
* Synchronizes database schema with distributed locking.
|
|
@@ -412,4 +649,4 @@ declare function syncSchema(space: DbSpace, types: readonly TAtscriptAnnotatedTy
|
|
|
412
649
|
*/
|
|
413
650
|
declare function planSchema(space: DbSpace, types: readonly TAtscriptAnnotatedType[], opts?: Pick<TSyncOptions, "force" | "safe">): Promise<TSyncPlan>;
|
|
414
651
|
//#endregion
|
|
415
|
-
export { SchemaSync, SyncEntry, type TFieldSnapshot, type TForeignKeyDiff, type TForeignKeySnapshot, type TSyncColors, type TSyncEntryStatus, type TSyncOptions, type TSyncPlan, type TSyncResult, type TTableSnapshot, type TViewSnapshot, computeColumnDiff, computeForeignKeyDiff, computeSchemaHash, computeTableHash, computeTableOptionDiff, computeTableSnapshot, computeViewSnapshot, fkKey, hasForeignKeyChanges, planSchema, readStoredSnapshot, snapshotToExistingColumns, snapshotToExistingTableOptions, syncSchema };
|
|
652
|
+
export { SchemaSync, SyncEntry, type TDbObjectKind, type TDependencyEdge, type TEnsureTableOptions, type TExistingForeignKey, type TFieldSnapshot, type TForeignKeyDiff, type TForeignKeySnapshot, type TPrimaryKeyChange, type TReferencingForeignKey, type TSyncColors, type TSyncEntryInit, type TSyncEntryStatus, type TSyncOptions, type TSyncPlan, type TSyncResult, type TSyncSkippedWork, type TTableSnapshot, type TViewJoinSnapshot, type TViewSnapshot, canonicalizeQueryNode, computeColumnDiff, computeForeignKeyDiff, computeSchemaHash, computeTableHash, computeTableOptionDiff, computeTableSnapshot, computeViewSnapshot, fkKey, hasForeignKeyChanges, planSchema, readStoredSnapshot, snapshotToExistingColumns, snapshotToExistingTableOptions, syncSchema, topoOrder };
|