@quereus/quereus 4.7.0 → 4.9.0
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/src/common/types.d.ts +19 -0
- package/dist/src/common/types.d.ts.map +1 -1
- package/dist/src/common/types.js.map +1 -1
- package/dist/src/core/database.d.ts +45 -1
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +212 -2
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +86 -0
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
- package/dist/src/func/builtins/aggregate.js +3 -2
- package/dist/src/func/builtins/aggregate.js.map +1 -1
- package/dist/src/func/builtins/conversion.d.ts +5 -0
- package/dist/src/func/builtins/conversion.d.ts.map +1 -1
- package/dist/src/func/builtins/conversion.js +16 -2
- package/dist/src/func/builtins/conversion.js.map +1 -1
- package/dist/src/func/builtins/index.d.ts.map +1 -1
- package/dist/src/func/builtins/index.js +5 -2
- package/dist/src/func/builtins/index.js.map +1 -1
- package/dist/src/func/builtins/string.d.ts +2 -0
- package/dist/src/func/builtins/string.d.ts.map +1 -1
- package/dist/src/func/builtins/string.js +60 -4
- package/dist/src/func/builtins/string.js.map +1 -1
- package/dist/src/index.d.ts +11 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +1 -1
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +121 -51
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
- package/dist/src/planner/rules/shared/index-style-context.d.ts +14 -4
- package/dist/src/planner/rules/shared/index-style-context.d.ts.map +1 -1
- package/dist/src/planner/rules/shared/index-style-context.js +14 -4
- package/dist/src/planner/rules/shared/index-style-context.js.map +1 -1
- package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-table.js +212 -155
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts +26 -12
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.js +45 -26
- package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -1
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +6 -6
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/assertion-rename-helpers.js +18 -20
- package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +12 -10
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/column-rename-cascade.d.ts +84 -0
- package/dist/src/runtime/emit/column-rename-cascade.d.ts.map +1 -0
- package/dist/src/runtime/emit/column-rename-cascade.js +134 -0
- package/dist/src/runtime/emit/column-rename-cascade.js.map +1 -0
- package/dist/src/runtime/emit/drop-column-guards.d.ts +82 -53
- package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-column-guards.js +155 -90
- package/dist/src/runtime/emit/drop-column-guards.js.map +1 -1
- package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-table.js +5 -0
- package/dist/src/runtime/emit/drop-table.js.map +1 -1
- package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-view.js +5 -0
- package/dist/src/runtime/emit/drop-view.js.map +1 -1
- package/dist/src/runtime/emit/expression-drop-guard.d.ts +57 -0
- package/dist/src/runtime/emit/expression-drop-guard.d.ts.map +1 -0
- package/dist/src/runtime/emit/expression-drop-guard.js +82 -0
- package/dist/src/runtime/emit/expression-drop-guard.js.map +1 -0
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +26 -9
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +37 -17
- package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view.js +3 -0
- package/dist/src/runtime/emit/materialized-view.js.map +1 -1
- package/dist/src/runtime/emit/remote-query.d.ts.map +1 -1
- package/dist/src/runtime/emit/remote-query.js +8 -3
- package/dist/src/runtime/emit/remote-query.js.map +1 -1
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +4 -1
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/schema-declarative.js +2 -2
- package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
- package/dist/src/runtime/parallel-driver.d.ts +4 -3
- package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
- package/dist/src/runtime/parallel-driver.js +8 -3
- package/dist/src/runtime/parallel-driver.js.map +1 -1
- package/dist/src/runtime/types.d.ts +10 -0
- package/dist/src/runtime/types.d.ts.map +1 -1
- package/dist/src/runtime/types.js.map +1 -1
- package/dist/src/runtime/utils.d.ts.map +1 -1
- package/dist/src/runtime/utils.js +11 -0
- package/dist/src/runtime/utils.js.map +1 -1
- package/dist/src/schema/assertion.d.ts +58 -0
- package/dist/src/schema/assertion.d.ts.map +1 -1
- package/dist/src/schema/assertion.js +78 -0
- package/dist/src/schema/assertion.js.map +1 -1
- package/dist/src/schema/catalog-persistability.d.ts +11 -3
- package/dist/src/schema/catalog-persistability.d.ts.map +1 -1
- package/dist/src/schema/catalog-persistability.js +48 -29
- package/dist/src/schema/catalog-persistability.js.map +1 -1
- package/dist/src/schema/catalog.d.ts +22 -0
- package/dist/src/schema/catalog.d.ts.map +1 -1
- package/dist/src/schema/catalog.js +4 -1
- package/dist/src/schema/catalog.js.map +1 -1
- package/dist/src/schema/column-republication.d.ts +126 -0
- package/dist/src/schema/column-republication.d.ts.map +1 -0
- package/dist/src/schema/column-republication.js +121 -0
- package/dist/src/schema/column-republication.js.map +1 -0
- package/dist/src/schema/column-source-resolver.d.ts +29 -6
- package/dist/src/schema/column-source-resolver.d.ts.map +1 -1
- package/dist/src/schema/column-source-resolver.js +78 -9
- package/dist/src/schema/column-source-resolver.js.map +1 -1
- package/dist/src/schema/expression-dependents.d.ts +160 -0
- package/dist/src/schema/expression-dependents.d.ts.map +1 -0
- package/dist/src/schema/expression-dependents.js +228 -0
- package/dist/src/schema/expression-dependents.js.map +1 -0
- package/dist/src/schema/object-dependency-closure.d.ts +127 -0
- package/dist/src/schema/object-dependency-closure.d.ts.map +1 -0
- package/dist/src/schema/object-dependency-closure.js +117 -0
- package/dist/src/schema/object-dependency-closure.js.map +1 -0
- package/dist/src/schema/object-ref-resolver.d.ts +83 -0
- package/dist/src/schema/object-ref-resolver.d.ts.map +1 -0
- package/dist/src/schema/object-ref-resolver.js +135 -0
- package/dist/src/schema/object-ref-resolver.js.map +1 -0
- package/dist/src/schema/rename/column-rename.d.ts +228 -0
- package/dist/src/schema/rename/column-rename.d.ts.map +1 -0
- package/dist/src/schema/rename/column-rename.js +1225 -0
- package/dist/src/schema/rename/column-rename.js.map +1 -0
- package/dist/src/schema/rename/self-qualifier-strip.d.ts +29 -0
- package/dist/src/schema/rename/self-qualifier-strip.d.ts.map +1 -0
- package/dist/src/schema/rename/self-qualifier-strip.js +267 -0
- package/dist/src/schema/rename/self-qualifier-strip.js.map +1 -0
- package/dist/src/schema/rename/shared.d.ts +108 -0
- package/dist/src/schema/rename/shared.d.ts.map +1 -0
- package/dist/src/schema/rename/shared.js +49 -0
- package/dist/src/schema/rename/shared.js.map +1 -0
- package/dist/src/schema/rename/table-rename.d.ts +263 -0
- package/dist/src/schema/rename/table-rename.d.ts.map +1 -0
- package/dist/src/schema/rename/table-rename.js +860 -0
- package/dist/src/schema/rename/table-rename.js.map +1 -0
- package/dist/src/schema/rename-rewriter.d.ts +18 -278
- package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
- package/dist/src/schema/rename-rewriter.js +17 -1506
- package/dist/src/schema/rename-rewriter.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts.map +1 -1
- package/dist/src/schema/schema-differ.js +228 -21
- package/dist/src/schema/schema-differ.js.map +1 -1
- package/dist/src/types/builtin-types.d.ts.map +1 -1
- package/dist/src/types/builtin-types.js +12 -28
- package/dist/src/types/builtin-types.js.map +1 -1
- package/dist/src/types/cast-semantics.d.ts +7 -5
- package/dist/src/types/cast-semantics.d.ts.map +1 -1
- package/dist/src/types/cast-semantics.js +20 -9
- package/dist/src/types/cast-semantics.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/registry.d.ts.map +1 -1
- package/dist/src/types/registry.js +2 -1
- package/dist/src/types/registry.js.map +1 -1
- package/dist/src/types/temporal-types.d.ts +11 -0
- package/dist/src/types/temporal-types.d.ts.map +1 -1
- package/dist/src/types/temporal-types.js +82 -0
- package/dist/src/types/temporal-types.js.map +1 -1
- package/dist/src/util/abort-signal.d.ts +25 -0
- package/dist/src/util/abort-signal.d.ts.map +1 -0
- package/dist/src/util/abort-signal.js +40 -0
- package/dist/src/util/abort-signal.js.map +1 -0
- package/dist/src/util/affinity.d.ts +2 -1
- package/dist/src/util/affinity.d.ts.map +1 -1
- package/dist/src/util/affinity.js +16 -5
- package/dist/src/util/affinity.js.map +1 -1
- package/dist/src/util/ast-spine-clone.d.ts +2 -2
- package/dist/src/util/ast-spine-clone.js +2 -2
- package/dist/src/util/value-text.d.ts +48 -0
- package/dist/src/util/value-text.d.ts.map +1 -0
- package/dist/src/util/value-text.js +35 -0
- package/dist/src/util/value-text.js.map +1 -0
- package/dist/src/vtab/concurrency.d.ts +15 -0
- package/dist/src/vtab/concurrency.d.ts.map +1 -1
- package/dist/src/vtab/concurrency.js +17 -0
- package/dist/src/vtab/concurrency.js.map +1 -1
- package/dist/src/vtab/memory/layer/base.d.ts +10 -0
- package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.js +10 -0
- package/dist/src/vtab/memory/layer/base.js.map +1 -1
- package/dist/src/vtab/memory/layer/interface.d.ts +24 -0
- package/dist/src/vtab/memory/layer/interface.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.d.ts +21 -3
- package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.js +118 -93
- package/dist/src/vtab/memory/layer/manager.js.map +1 -1
- package/dist/src/vtab/memory/layer/transaction.d.ts +11 -0
- package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/transaction.js +19 -0
- package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts +41 -0
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +41 -0
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/dist/src/vtab/memory/table.d.ts +12 -1
- package/dist/src/vtab/memory/table.d.ts.map +1 -1
- package/dist/src/vtab/memory/table.js +12 -1
- package/dist/src/vtab/memory/table.js.map +1 -1
- package/dist/src/vtab/module.d.ts +33 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/dist/src/vtab/test-support/commit-stall.d.ts +53 -0
- package/dist/src/vtab/test-support/commit-stall.d.ts.map +1 -0
- package/dist/src/vtab/test-support/commit-stall.js +73 -0
- package/dist/src/vtab/test-support/commit-stall.js.map +1 -0
- package/dist/src/vtab/test-support/committed-read-conformance.d.ts +96 -0
- package/dist/src/vtab/test-support/committed-read-conformance.d.ts.map +1 -0
- package/dist/src/vtab/test-support/committed-read-conformance.js +364 -0
- package/dist/src/vtab/test-support/committed-read-conformance.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type * as AST from '../../parser/ast.js';
|
|
2
|
+
import { type ResolveObjectRef, type TableRenameTarget } from './shared.js';
|
|
3
|
+
/**
|
|
4
|
+
* Scope-aware, in-place table-reference walker: propagates
|
|
5
|
+
* `ALTER TABLE … RENAME` into dependent object ASTs (view bodies, CHECK
|
|
6
|
+
* expressions, assertion bodies, partial-index predicates, column DEFAULT /
|
|
7
|
+
* generated expressions) and answers the read-only "does this AST reference
|
|
8
|
+
* table X?" probe the DROP guards use.
|
|
9
|
+
*
|
|
10
|
+
* All three verbs are expressed over ONE traversal ({@link visitTableRefs}),
|
|
11
|
+
* which reports every REAL table reference — one not shadowed by a CTE, a FROM
|
|
12
|
+
* alias, or the `new.`/`old.` row image — to a sink. The rewrite sink renames
|
|
13
|
+
* matching references in place; the probe sink records a match and stops the
|
|
14
|
+
* walk; the collect sink ({@link collectTableRefsInAst}) keys every reference
|
|
15
|
+
* for the reachability closure the DROP guards follow through view chains. One
|
|
16
|
+
* traversal is the invariant, not an implementation detail: the DROP guards
|
|
17
|
+
* must refuse exactly the references a rename would rewrite.
|
|
18
|
+
*
|
|
19
|
+
* All name comparisons are case-insensitive to match the Quereus catalog
|
|
20
|
+
* rules. Walkers mutate the input AST and return whether anything changed, so
|
|
21
|
+
* callers can skip cloning when nothing matched.
|
|
22
|
+
*/
|
|
23
|
+
/** Options for the table-reference walk, threaded from the entry points. */
|
|
24
|
+
export interface TableRenameOpts {
|
|
25
|
+
/**
|
|
26
|
+
* The walked expression is evaluated against a WRITTEN ROW — a CHECK
|
|
27
|
+
* constraint or a column DEFAULT / generated body — so a bare `new.` /
|
|
28
|
+
* `old.` column qualifier names the row image, never a table called `new`
|
|
29
|
+
* or `old`. Suppression is scope-aware: it applies only while no FROM/WITH
|
|
30
|
+
* frame rebinds the qualifier (a subquery selecting from a real table
|
|
31
|
+
* named `new` still counts as a table reference), and never to a
|
|
32
|
+
* schema-qualified `main.new.a`, which is a real three-part reference.
|
|
33
|
+
*
|
|
34
|
+
* Deliberately NOT set for partial-index predicates: a predicate describes
|
|
35
|
+
* rows already stored and has no written-row context, so `new.x` there IS
|
|
36
|
+
* a table reference. (The column walker records the same asymmetry by
|
|
37
|
+
* passing row-image mode `'none'` for predicates.)
|
|
38
|
+
*
|
|
39
|
+
* A boolean where the column walker's
|
|
40
|
+
* {@link import('./shared.js').RowImageContext} is three-valued, and
|
|
41
|
+
* COMPLETE at two: this walker never *matches* a row image, only
|
|
42
|
+
* suppresses one, so the column walker's `'own'`/`'foreign'` split
|
|
43
|
+
* collapses — `false` maps to `'none'`, `true` to `'foreign'`. Like the
|
|
44
|
+
* column walker, the flag is overridden (to `true`) over `with inverse` /
|
|
45
|
+
* `with defaults` subtrees regardless of the entry-point value, because
|
|
46
|
+
* written-row context there is a property of the position, not the walk.
|
|
47
|
+
*/
|
|
48
|
+
rowImageContext?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The walked expression is SCHEMA-AUTHORED — a CHECK constraint, a column
|
|
51
|
+
* DEFAULT / generated body, or a partial-index predicate — so it plans under
|
|
52
|
+
* `schemaAuthoredContext` (`planner/building/schema-authored-context.ts`):
|
|
53
|
+
* its owning schema and NOTHING else, never the session schema path. Set by
|
|
54
|
+
* the three collection helpers below; absent for the stored bodies that DO
|
|
55
|
+
* plan under the home schema path (view bodies, materialized-view bodies,
|
|
56
|
+
* assertion checks).
|
|
57
|
+
*
|
|
58
|
+
* Suppresses the untouched-reference arm of {@link renameTableInAst}, for
|
|
59
|
+
* two reasons that agree:
|
|
60
|
+
*
|
|
61
|
+
* - Nothing is lost. That arm fires only when an unqualified name resolves
|
|
62
|
+
* through to ANOTHER schema, which is precisely what this planning context
|
|
63
|
+
* rejects — so it could only ever fire on a body the planner already
|
|
64
|
+
* refuses to evaluate.
|
|
65
|
+
* - It keeps the walk IDEMPOTENT where idempotence is load-bearing. The
|
|
66
|
+
* renamed table's own CHECK / predicate / column expressions are walked
|
|
67
|
+
* more than once on purpose: `runRenameTable` rewrites them before the
|
|
68
|
+
* catalog swap, `propagateTableRename` walks every table again afterwards,
|
|
69
|
+
* and a persisting module rewrites the same shared ASTs inside its own
|
|
70
|
+
* `renameTable` hook. The rewrite arm is idempotent by construction (after
|
|
71
|
+
* it runs, nothing names `oldName`); the untouched arm is NOT, because a
|
|
72
|
+
* reference the rewrite already turned into `newName` is indistinguishable
|
|
73
|
+
* — to the resolvers — from one the new name captured. Confining that arm
|
|
74
|
+
* to the once-walked home-path bodies is what keeps the two facts from
|
|
75
|
+
* colliding.
|
|
76
|
+
*/
|
|
77
|
+
schemaAuthoredBody?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* `target.resolve` and the derived `targetKey` (`objectRefKey(target.schemaName,
|
|
81
|
+
* target.oldName)`) decide matching for the rewrite and the probe below alike: a
|
|
82
|
+
* reference matches when `resolve(ref.schema, ref.name)` — the reference's
|
|
83
|
+
* planner-parity resolution under the WALKED BODY's home schema path — equals
|
|
84
|
+
* `targetKey`. The bare-name equality check in front is a pure short-circuit:
|
|
85
|
+
* the resolver echoes the name it is given into the key, so a reference spelled
|
|
86
|
+
* differently can never resolve to the target.
|
|
87
|
+
*
|
|
88
|
+
* The rewrite additionally enforces a POST-CONDITION the probe does not need,
|
|
89
|
+
* and it covers EVERY reference the walk reports — not only the ones it
|
|
90
|
+
* rewrites:
|
|
91
|
+
*
|
|
92
|
+
* > Walking a body for a rename, every reference must mean after the statement
|
|
93
|
+
* > exactly what it meant before.
|
|
94
|
+
*
|
|
95
|
+
* Both arms decide that the same way: re-resolve the reference under the same
|
|
96
|
+
* home schema path against the catalog AS IT WILL BE AFTER THE RENAME
|
|
97
|
+
* (`target.resolveAfter`) and compare with what it meant before.
|
|
98
|
+
*
|
|
99
|
+
* - A REWRITTEN reference must still yield the renamed object's key. When it
|
|
100
|
+
* would not — the bare new name is captured by an earlier schema on the
|
|
101
|
+
* body's home path — it is schema-qualified to the renamed schema via
|
|
102
|
+
* {@link TableRef.qualify}.
|
|
103
|
+
* - An UNTOUCHED reference must still yield its own before-answer. A rename
|
|
104
|
+
* also CREATES a name, and that new name can capture a reference the walk
|
|
105
|
+
* never matched: a `temp`-owned body reading bare `k` (falling through to
|
|
106
|
+
* `main.k`, because `temp` holds no `k`) silently re-binds to `temp.k` the
|
|
107
|
+
* moment `alter table temp.other rename to k` lands, without its text ever
|
|
108
|
+
* mentioning the renamed table. When the answer would change, the reference
|
|
109
|
+
* is qualified to the schema its BEFORE-answer named — recovered from that
|
|
110
|
+
* key by {@link import('./shared.js').objectRefKeySchema}. This arm applies
|
|
111
|
+
* to the stored bodies that plan under the home schema path and is walked
|
|
112
|
+
* ONCE per body; {@link TableRenameOpts.schemaAuthoredBody} turns it off for
|
|
113
|
+
* the schema-authored expressions, which need it neither for correctness nor
|
|
114
|
+
* for the re-walks they are deliberately subjected to — see that flag.
|
|
115
|
+
*
|
|
116
|
+
* The post-condition also covers the FROM-frame namespace, not just the
|
|
117
|
+
* catalog's: inside one body, the bare qualifier an unaliased FROM source
|
|
118
|
+
* exposes must keep binding that source. When the rename would give a source a
|
|
119
|
+
* name already visible as a qualifier where it sits ({@link
|
|
120
|
+
* TableRef.qualifierCollides}), the source pins its pre-rename spelling as an
|
|
121
|
+
* explicit alias ({@link TableRef.aliasAs}) and every column qualifier bound
|
|
122
|
+
* through it keeps the old spelling — `from t join u as t2` becomes
|
|
123
|
+
* `from t2 as t join u as t2` under `t → t2`, with `t.x` untouched. And when
|
|
124
|
+
* the new name is shadowed by a CTE in scope at the source ({@link
|
|
125
|
+
* TableRef.cteShadows}) — invisible to the catalog resolvers — the reference
|
|
126
|
+
* is schema-qualified so it cannot re-bind to the CTE.
|
|
127
|
+
*
|
|
128
|
+
* Qualification is conditional in both arms, never eager, so the common
|
|
129
|
+
* no-collision rename leaves body text (and a materialized view's `bodyHash`)
|
|
130
|
+
* exactly as before. A qualified reference resolves by passthrough, so its
|
|
131
|
+
* before- and after-answers are always equal and neither arm can fire on one;
|
|
132
|
+
* only unqualified references ever gain a qualifier. And only the NEW name can
|
|
133
|
+
* change meaning without being rewritten: removing the old name can only push a
|
|
134
|
+
* resolution later, and the references that resolved to the removed entry are
|
|
135
|
+
* exactly the ones the rewrite already matches — so there is no freed-name
|
|
136
|
+
* direction to handle.
|
|
137
|
+
*
|
|
138
|
+
* ALREADY-BROKEN BODIES: the resolver answers a total function — a name held by
|
|
139
|
+
* no schema on the path still gets a stable key, the home schema's — so a body
|
|
140
|
+
* naming an object that exists nowhere reads `before = <home>.<name>`, and a
|
|
141
|
+
* rename introducing that name in an earlier schema flips `after`. The
|
|
142
|
+
* untouched arm then qualifies the reference to the home schema, PINNING the
|
|
143
|
+
* pre-existing "no such table" failure rather than letting the body silently
|
|
144
|
+
* start reading the new arrival. That is the invariant-faithful answer, so no
|
|
145
|
+
* existence probe is added to dodge it (same reasoning as the seedless-qualifier
|
|
146
|
+
* emit site below: it only ever fires on an already-unevaluable body).
|
|
147
|
+
*/
|
|
148
|
+
export declare function renameTableInAst(node: AST.AstNode | undefined, target: TableRenameTarget, opts?: TableRenameOpts): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Whether `node` refers to the table/view identified by `targetKey` (spelled
|
|
151
|
+
* `name`) — read-only, nothing is mutated.
|
|
152
|
+
*
|
|
153
|
+
* Deliberately the SAME traversal {@link renameTableInAst} uses — both are
|
|
154
|
+
* sinks over {@link visitTableRefs} — so "refers to" can never drift from
|
|
155
|
+
* "would have been rewritten by a rename". That equivalence is the whole
|
|
156
|
+
* point: the DROP guard refuses exactly the cases `ALTER TABLE … RENAME`
|
|
157
|
+
* would have followed. In particular, a body whose `with <name> as (…)`
|
|
158
|
+
* merely SHADOWS the probed name is not a reference — the walk skips it for
|
|
159
|
+
* both verbs. The probe's sink stops the walk at the first match.
|
|
160
|
+
*
|
|
161
|
+
* The column-level probes ({@link import('./column-rename.js').columnReferencedInAst},
|
|
162
|
+
* {@link import('./column-rename.js').columnReferencedInCheckExpression}) reach
|
|
163
|
+
* the same equivalence a different way — a real rename, to a sentinel name,
|
|
164
|
+
* over a throwaway clone — because the column walker has ~8 mutation points
|
|
165
|
+
* and a CTE-re-exposure branch that reads the new name; see their comments.
|
|
166
|
+
*/
|
|
167
|
+
export declare function tableReferencedInAst(node: AST.AstNode | undefined, name: string, resolve: ResolveObjectRef, targetKey: string, opts?: TableRenameOpts): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Every real (non-shadowed) table / view reference in `node`, keyed the way
|
|
170
|
+
* {@link renameTableInAst} and {@link tableReferencedInAst} key their target:
|
|
171
|
+
* `resolve(ref.schema, ref.name)`, the reference's planner-parity resolution
|
|
172
|
+
* under the WALKED BODY's home schema path.
|
|
173
|
+
*
|
|
174
|
+
* The collect-all THIRD sink over the same {@link walkTableRefs} traversal, so
|
|
175
|
+
* it inherits the scope-awareness of the other two for free: a body whose
|
|
176
|
+
* `with t as (…)` merely SHADOWS the name contributes no `<schema>.t` key, a FROM
|
|
177
|
+
* alias contributes nothing, and a `new.` / `old.` row-image qualifier under
|
|
178
|
+
* {@link TableRenameOpts.rowImageContext} contributes nothing. That matters
|
|
179
|
+
* more here than anywhere else — a collect-everything walk is exactly where
|
|
180
|
+
* that property gets quietly lost, and the reachability closure built on this
|
|
181
|
+
* ({@link import('../object-dependency-closure.js').reachableObjects}) turns
|
|
182
|
+
* every key it yields into a refused DROP.
|
|
183
|
+
*
|
|
184
|
+
* The value is the object NAME the key was built from, lowercased. The
|
|
185
|
+
* resolver echoes the name it is given into the key, so this is always
|
|
186
|
+
* `ref.name.toLowerCase()`; it is returned rather than re-derived because a
|
|
187
|
+
* schema name may itself contain a dot, which makes splitting a key by
|
|
188
|
+
* separator scan wrong — see {@link import('./shared.js').objectRefKeySchema},
|
|
189
|
+
* whose whole job is that split and which needs exactly this.
|
|
190
|
+
*/
|
|
191
|
+
export declare function collectTableRefsInAst(node: AST.AstNode | undefined, resolve: ResolveObjectRef, opts?: TableRenameOpts): Map<string, string>;
|
|
192
|
+
/**
|
|
193
|
+
* Rewrite the renamed table inside every partial-index predicate of `indexes`,
|
|
194
|
+
* in place. A predicate may carry a table-qualified self-reference
|
|
195
|
+
* (`create index ix on t (b) where t.b > 0`), which a table rename must follow.
|
|
196
|
+
*
|
|
197
|
+
* No {@link TableRenameOpts.rowImageContext}: a predicate describes rows
|
|
198
|
+
* already stored, so `new.x` there is a real table reference — see the flag's
|
|
199
|
+
* doc comment. {@link TableRenameOpts.schemaAuthoredBody} IS set: a predicate
|
|
200
|
+
* plans under its owning schema alone, and this AST is one of the several the
|
|
201
|
+
* rename walks more than once.
|
|
202
|
+
*
|
|
203
|
+
* Sharing and idempotence work exactly as in
|
|
204
|
+
* {@link import('./column-rename.js').renameColumnInIndexPredicates}: the
|
|
205
|
+
* predicate `Expression` is shared by reference with the catalog's
|
|
206
|
+
* `TableSchema` and with a unique partial index's `derivedFromIndex` UNIQUE
|
|
207
|
+
* constraint, so one in-place rewrite covers all of them, and a second call
|
|
208
|
+
* with the same pair finds nothing naming `oldName` and returns false.
|
|
209
|
+
*/
|
|
210
|
+
export declare function renameTableInIndexPredicates(indexes: ReadonlyArray<{
|
|
211
|
+
readonly predicate?: AST.Expression;
|
|
212
|
+
}> | undefined, target: TableRenameTarget): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Rewrite the renamed table inside every CHECK constraint expression of `checks`,
|
|
215
|
+
* in place. A CHECK may carry a table-qualified self-reference (`check (t.b > 0)`)
|
|
216
|
+
* exactly as a partial-index predicate may, and a table rename must follow it.
|
|
217
|
+
*
|
|
218
|
+
* A CHECK is evaluated against a written row, so the walk runs with
|
|
219
|
+
* {@link TableRenameOpts.rowImageContext}: a bare `new.a` / `old.a` names the
|
|
220
|
+
* row image and survives even a rename of a table literally called `new`. It
|
|
221
|
+
* also runs with {@link TableRenameOpts.schemaAuthoredBody}, for the same
|
|
222
|
+
* reasons the predicate arm above does.
|
|
223
|
+
*
|
|
224
|
+
* Same sharing and idempotence story as {@link renameTableInIndexPredicates}: the
|
|
225
|
+
* `expr` is the very AST the catalog's `TableSchema` holds, so one rewrite covers
|
|
226
|
+
* every holder and a second call with the same pair is a no-op.
|
|
227
|
+
*/
|
|
228
|
+
export declare function renameTableInCheckConstraints(checks: ReadonlyArray<{
|
|
229
|
+
readonly expr: AST.Expression;
|
|
230
|
+
}> | undefined, target: TableRenameTarget): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Rewrite the renamed table inside the two expressions a `ColumnSchema` can carry —
|
|
233
|
+
* a column DEFAULT (`w integer default ((select min(v) from u))`, however authored:
|
|
234
|
+
* inline, or via `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same
|
|
235
|
+
* field) and a generated column's body (`g integer generated always as ((select
|
|
236
|
+
* min(u.v) from u) + id)`) — in place.
|
|
237
|
+
*
|
|
238
|
+
* Both expressions evaluate against the row being written, so the walk runs
|
|
239
|
+
* with {@link TableRenameOpts.rowImageContext}: a default's `new.a` names the
|
|
240
|
+
* row image, not a table called `new`. It also runs with
|
|
241
|
+
* {@link TableRenameOpts.schemaAuthoredBody}, for the same reasons the two arms
|
|
242
|
+
* above do.
|
|
243
|
+
*
|
|
244
|
+
* Unlike the column-rename counterpart
|
|
245
|
+
* ({@link import('./column-rename.js').renameColumnInColumnExpressions}) there
|
|
246
|
+
* is no seeded/unseeded split: {@link renameTableInAst} resolves nothing against an
|
|
247
|
+
* implicit owning table, so the SAME entry point is correct for the renamed table's own
|
|
248
|
+
* columns (a self-referencing default, `default ((select count(*) from t))`) and for
|
|
249
|
+
* every other table's.
|
|
250
|
+
*
|
|
251
|
+
* Same sharing and idempotence story as {@link renameTableInCheckConstraints}: the
|
|
252
|
+
* `Expression` is the very AST the catalog's `TableSchema` holds, so one in-place
|
|
253
|
+
* rewrite reaches every holder and a second call with the same pair finds nothing
|
|
254
|
+
* naming `oldName` and returns false.
|
|
255
|
+
*
|
|
256
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
257
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
258
|
+
*/
|
|
259
|
+
export declare function renameTableInColumnExpressions(columns: ReadonlyArray<{
|
|
260
|
+
readonly defaultValue?: AST.Expression | null;
|
|
261
|
+
readonly generatedExpr?: AST.Expression;
|
|
262
|
+
}> | undefined, target: TableRenameTarget): boolean;
|
|
263
|
+
//# sourceMappingURL=table-rename.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-rename.d.ts","sourceRoot":"","sources":["../../../../src/schema/rename/table-rename.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAqD,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE/H;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA6GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,MAAM,EAAE,iBAAiB,EACzB,IAAI,CAAC,EAAE,eAAe,GACpB,OAAO,CAoET;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,EACzB,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,eAAe,GACpB,OAAO,CAUT;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,EAC7B,OAAO,EAAE,gBAAgB,EACzB,IAAI,CAAC,EAAE,eAAe,GACpB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,aAAa,CAAC;IAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,UAAU,CAAA;CAAE,CAAC,GAAG,SAAS,EAC3E,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,aAAa,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAA;CAAE,CAAC,GAAG,SAAS,EACpE,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;CACxC,CAAC,GAAG,SAAS,EACd,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAOT"}
|