@quereus/quereus 4.6.0 → 4.8.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/README.md +2 -2
- package/dist/src/common/errors.d.ts +17 -0
- package/dist/src/common/errors.d.ts.map +1 -1
- package/dist/src/common/errors.js +21 -0
- package/dist/src/common/errors.js.map +1 -1
- 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-assertions.d.ts +4 -3
- package/dist/src/core/database-assertions.d.ts.map +1 -1
- package/dist/src/core/database-assertions.js +44 -14
- package/dist/src/core/database-assertions.js.map +1 -1
- package/dist/src/core/database-events.d.ts +62 -0
- package/dist/src/core/database-events.d.ts.map +1 -1
- package/dist/src/core/database-events.js +88 -2
- package/dist/src/core/database-events.js.map +1 -1
- package/dist/src/core/database-internal.d.ts +5 -2
- package/dist/src/core/database-internal.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views-plan-builders.js +4 -2
- package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
- package/dist/src/core/database-materialized-views-plans.d.ts +12 -2
- package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views.d.ts +46 -0
- package/dist/src/core/database-materialized-views.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views.js +75 -4
- package/dist/src/core/database-materialized-views.js.map +1 -1
- package/dist/src/core/database.d.ts +48 -2
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +222 -11
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/derived-row-validator.d.ts.map +1 -1
- package/dist/src/core/derived-row-validator.js +7 -1
- package/dist/src/core/derived-row-validator.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +101 -5
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/emit/ast-stringify.d.ts +18 -2
- package/dist/src/emit/ast-stringify.d.ts.map +1 -1
- package/dist/src/emit/ast-stringify.js +22 -4
- package/dist/src/emit/ast-stringify.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +19 -5
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/scalar.d.ts.map +1 -1
- package/dist/src/func/builtins/scalar.js +24 -20
- package/dist/src/func/builtins/scalar.js.map +1 -1
- package/dist/src/func/builtins/schema.d.ts.map +1 -1
- package/dist/src/func/builtins/schema.js +32 -5
- package/dist/src/func/builtins/schema.js.map +1 -1
- package/dist/src/index.d.ts +9 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/ast.d.ts +58 -1
- package/dist/src/parser/ast.d.ts.map +1 -1
- package/dist/src/parser/parser.js +1 -1
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/src/parser/utils.d.ts +13 -1
- package/dist/src/parser/utils.d.ts.map +1 -1
- package/dist/src/parser/utils.js +14 -0
- package/dist/src/parser/utils.js.map +1 -1
- package/dist/src/planner/analysis/assertion-classifier.d.ts.map +1 -1
- package/dist/src/planner/analysis/assertion-classifier.js +7 -2
- package/dist/src/planner/analysis/assertion-classifier.js.map +1 -1
- package/dist/src/planner/analysis/assertion-hoist-cache.d.ts.map +1 -1
- package/dist/src/planner/analysis/assertion-hoist-cache.js +5 -0
- package/dist/src/planner/analysis/assertion-hoist-cache.js.map +1 -1
- package/dist/src/planner/analysis/change-scope.d.ts +11 -3
- package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
- package/dist/src/planner/analysis/change-scope.js +5 -4
- package/dist/src/planner/analysis/change-scope.js.map +1 -1
- package/dist/src/planner/analysis/coverage-prover.d.ts.map +1 -1
- package/dist/src/planner/analysis/coverage-prover.js +13 -5
- package/dist/src/planner/analysis/coverage-prover.js.map +1 -1
- package/dist/src/planner/analysis/equi-correlation.d.ts +6 -1
- package/dist/src/planner/analysis/equi-correlation.d.ts.map +1 -1
- package/dist/src/planner/analysis/equi-correlation.js +8 -1
- package/dist/src/planner/analysis/equi-correlation.js.map +1 -1
- package/dist/src/planner/analysis/predicate-dependencies.d.ts +34 -0
- package/dist/src/planner/analysis/predicate-dependencies.d.ts.map +1 -0
- package/dist/src/planner/analysis/predicate-dependencies.js +60 -0
- package/dist/src/planner/analysis/predicate-dependencies.js.map +1 -0
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.js +0 -26
- package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
- package/dist/src/planner/building/alter-table.d.ts.map +1 -1
- package/dist/src/planner/building/alter-table.js +53 -17
- package/dist/src/planner/building/alter-table.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +9 -5
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/building/create-assertion.d.ts.map +1 -1
- package/dist/src/planner/building/create-assertion.js +72 -1
- package/dist/src/planner/building/create-assertion.js.map +1 -1
- package/dist/src/planner/building/create-view.d.ts +6 -1
- package/dist/src/planner/building/create-view.d.ts.map +1 -1
- package/dist/src/planner/building/create-view.js +12 -3
- package/dist/src/planner/building/create-view.js.map +1 -1
- package/dist/src/planner/building/ddl.d.ts.map +1 -1
- package/dist/src/planner/building/ddl.js +6 -2
- package/dist/src/planner/building/ddl.js.map +1 -1
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +23 -10
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/dml-target.d.ts.map +1 -1
- package/dist/src/planner/building/dml-target.js +4 -0
- package/dist/src/planner/building/dml-target.js.map +1 -1
- package/dist/src/planner/building/drop-assertion.d.ts.map +1 -1
- package/dist/src/planner/building/drop-assertion.js +3 -1
- package/dist/src/planner/building/drop-assertion.js.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.js +7 -5
- package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
- package/dist/src/planner/building/function-call.d.ts +35 -0
- package/dist/src/planner/building/function-call.d.ts.map +1 -1
- package/dist/src/planner/building/function-call.js +53 -40
- package/dist/src/planner/building/function-call.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +185 -48
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/materialized-view.d.ts.map +1 -1
- package/dist/src/planner/building/materialized-view.js +3 -1
- package/dist/src/planner/building/materialized-view.js.map +1 -1
- package/dist/src/planner/building/schema-authored-context.d.ts +69 -0
- package/dist/src/planner/building/schema-authored-context.d.ts.map +1 -0
- package/dist/src/planner/building/schema-authored-context.js +75 -0
- package/dist/src/planner/building/schema-authored-context.js.map +1 -0
- package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
- package/dist/src/planner/building/schema-resolution.js +7 -4
- package/dist/src/planner/building/schema-resolution.js.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts +187 -2
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +414 -81
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-compound.js +2 -2
- package/dist/src/planner/building/select-compound.js.map +1 -1
- package/dist/src/planner/building/select-context.d.ts +91 -0
- package/dist/src/planner/building/select-context.d.ts.map +1 -1
- package/dist/src/planner/building/select-context.js +113 -0
- package/dist/src/planner/building/select-context.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +10 -3
- package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
- package/dist/src/planner/building/select-modifiers.js +29 -8
- package/dist/src/planner/building/select-modifiers.js.map +1 -1
- package/dist/src/planner/building/select-ordinal.d.ts +64 -19
- package/dist/src/planner/building/select-ordinal.d.ts.map +1 -1
- package/dist/src/planner/building/select-ordinal.js +79 -30
- package/dist/src/planner/building/select-ordinal.js.map +1 -1
- package/dist/src/planner/building/select-projections.d.ts +1 -1
- package/dist/src/planner/building/select-projections.d.ts.map +1 -1
- package/dist/src/planner/building/select-projections.js +18 -11
- package/dist/src/planner/building/select-projections.js.map +1 -1
- package/dist/src/planner/building/select-window.d.ts +13 -3
- package/dist/src/planner/building/select-window.d.ts.map +1 -1
- package/dist/src/planner/building/select-window.js +142 -37
- package/dist/src/planner/building/select-window.js.map +1 -1
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +129 -59
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/building/update.d.ts.map +1 -1
- package/dist/src/planner/building/update.js +27 -13
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/building/view-mutation-builder.d.ts +1 -1
- package/dist/src/planner/building/view-mutation-builder.d.ts.map +1 -1
- package/dist/src/planner/building/view-mutation-builder.js +102 -8
- package/dist/src/planner/building/view-mutation-builder.js.map +1 -1
- package/dist/src/planner/building/with.d.ts.map +1 -1
- package/dist/src/planner/building/with.js +34 -4
- package/dist/src/planner/building/with.js.map +1 -1
- package/dist/src/planner/cache/correlation-detector.d.ts +15 -0
- package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -1
- package/dist/src/planner/cache/correlation-detector.js +26 -0
- package/dist/src/planner/cache/correlation-detector.js.map +1 -1
- package/dist/src/planner/cache/materialization-advisory.d.ts +7 -0
- package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/cache/materialization-advisory.js +12 -3
- package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
- package/dist/src/planner/framework/characteristics.d.ts +9 -0
- package/dist/src/planner/framework/characteristics.d.ts.map +1 -1
- package/dist/src/planner/framework/characteristics.js.map +1 -1
- package/dist/src/planner/framework/pass.d.ts +2 -0
- package/dist/src/planner/framework/pass.d.ts.map +1 -1
- package/dist/src/planner/framework/pass.js +15 -0
- package/dist/src/planner/framework/pass.js.map +1 -1
- package/dist/src/planner/mutation/backward-body.d.ts.map +1 -1
- package/dist/src/planner/mutation/backward-body.js +4 -1
- package/dist/src/planner/mutation/backward-body.js.map +1 -1
- package/dist/src/planner/mutation/body-context.d.ts +23 -0
- package/dist/src/planner/mutation/body-context.d.ts.map +1 -0
- package/dist/src/planner/mutation/body-context.js +26 -0
- package/dist/src/planner/mutation/body-context.js.map +1 -0
- package/dist/src/planner/mutation/cte-flatten.js +15 -2
- package/dist/src/planner/mutation/cte-flatten.js.map +1 -1
- package/dist/src/planner/mutation/decomposition.d.ts +8 -0
- package/dist/src/planner/mutation/decomposition.d.ts.map +1 -1
- package/dist/src/planner/mutation/decomposition.js +8 -3
- package/dist/src/planner/mutation/decomposition.js.map +1 -1
- package/dist/src/planner/mutation/lens-enforcement.js +1 -1
- package/dist/src/planner/mutation/multi-source.d.ts +7 -0
- package/dist/src/planner/mutation/multi-source.d.ts.map +1 -1
- package/dist/src/planner/mutation/multi-source.js +5 -0
- package/dist/src/planner/mutation/multi-source.js.map +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.d.ts +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.d.ts.map +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.js.map +1 -1
- package/dist/src/planner/mutation/scope-transform.d.ts +32 -0
- package/dist/src/planner/mutation/scope-transform.d.ts.map +1 -1
- package/dist/src/planner/mutation/scope-transform.js +181 -33
- package/dist/src/planner/mutation/scope-transform.js.map +1 -1
- package/dist/src/planner/mutation/set-op.d.ts.map +1 -1
- package/dist/src/planner/mutation/set-op.js +66 -16
- package/dist/src/planner/mutation/set-op.js.map +1 -1
- package/dist/src/planner/mutation/single-source.d.ts.map +1 -1
- package/dist/src/planner/mutation/single-source.js +100 -24
- package/dist/src/planner/mutation/single-source.js.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts +15 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.js +10 -1
- package/dist/src/planner/nodes/add-constraint-node.js.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.d.ts +14 -5
- package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.js +28 -21
- package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
- package/dist/src/planner/nodes/alter-table-node.d.ts +27 -2
- package/dist/src/planner/nodes/alter-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/alter-table-node.js +49 -2
- package/dist/src/planner/nodes/alter-table-node.js.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.js +17 -19
- package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts +2 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.js +5 -2
- package/dist/src/planner/nodes/create-assertion-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts +19 -9
- package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-node.js +25 -9
- package/dist/src/planner/nodes/cte-node.js.map +1 -1
- package/dist/src/planner/nodes/delete-node.d.ts +20 -2
- package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/delete-node.js +11 -2
- package/dist/src/planner/nodes/delete-node.js.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts +58 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.js +107 -15
- package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts +2 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.js +5 -2
- package/dist/src/planner/nodes/drop-assertion-node.js.map +1 -1
- package/dist/src/planner/nodes/filter.d.ts.map +1 -1
- package/dist/src/planner/nodes/filter.js +12 -6
- package/dist/src/planner/nodes/filter.js.map +1 -1
- package/dist/src/planner/nodes/hash-aggregate.d.ts +0 -5
- package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/hash-aggregate.js +17 -20
- package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/insert-node.d.ts +19 -2
- package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/insert-node.js +10 -2
- package/dist/src/planner/nodes/insert-node.js.map +1 -1
- package/dist/src/planner/nodes/key-set-semi-join-node.d.ts +42 -10
- package/dist/src/planner/nodes/key-set-semi-join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/key-set-semi-join-node.js +85 -16
- package/dist/src/planner/nodes/key-set-semi-join-node.js.map +1 -1
- package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts +5 -0
- package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/lens-auxiliary-access-node.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +5 -0
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +12 -0
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/project-node.js +16 -35
- package/dist/src/planner/nodes/project-node.js.map +1 -1
- package/dist/src/planner/nodes/retrieve-node.d.ts +16 -2
- package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/retrieve-node.js +8 -1
- package/dist/src/planner/nodes/retrieve-node.js.map +1 -1
- package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/returning-node.js +13 -32
- package/dist/src/planner/nodes/returning-node.js.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.d.ts +0 -5
- package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.js +18 -24
- package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts +89 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.js +64 -2
- package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
- package/dist/src/planner/nodes/update-node.d.ts +19 -2
- package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/update-node.js +10 -2
- package/dist/src/planner/nodes/update-node.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts +18 -0
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +59 -10
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/planning-context.d.ts +24 -0
- package/dist/src/planner/planning-context.d.ts.map +1 -1
- package/dist/src/planner/planning-context.js.map +1 -1
- package/dist/src/planner/rules/access/rule-key-set-seek.d.ts +78 -20
- package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-key-set-seek.js +297 -71
- package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js +2 -2
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +11 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js +46 -2
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts +7 -4
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js +39 -5
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js +6 -2
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +10 -3
- package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.js +13 -7
- package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts +4 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +50 -15
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-elimination.d.ts +6 -0
- package/dist/src/planner/rules/join/rule-join-elimination.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-elimination.js +25 -9
- package/dist/src/planner/rules/join/rule-join-elimination.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts +7 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.js +23 -11
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +2 -2
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.js +46 -16
- package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts +2 -0
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +14 -0
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts +2 -2
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js +19 -22
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +33 -19
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +37 -18
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts +6 -3
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js +6 -3
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +11 -21
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.d.ts +16 -3
- package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.js +21 -5
- package/dist/src/planner/rules/shared/access-leaf.js.map +1 -1
- package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js +1 -1
- package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js.map +1 -1
- package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js +1 -1
- package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js.map +1 -1
- package/dist/src/planner/stored-body-context.d.ts +57 -0
- package/dist/src/planner/stored-body-context.d.ts.map +1 -0
- package/dist/src/planner/stored-body-context.js +64 -0
- package/dist/src/planner/stored-body-context.js.map +1 -0
- package/dist/src/planner/util/ind-utils.d.ts +28 -20
- package/dist/src/planner/util/ind-utils.d.ts.map +1 -1
- package/dist/src/planner/util/ind-utils.js +36 -27
- package/dist/src/planner/util/ind-utils.js.map +1 -1
- package/dist/src/planner/util/key-utils.d.ts +19 -4
- package/dist/src/planner/util/key-utils.d.ts.map +1 -1
- package/dist/src/planner/util/key-utils.js +23 -7
- package/dist/src/planner/util/key-utils.js.map +1 -1
- package/dist/src/planner/util/output-names.d.ts +12 -0
- package/dist/src/planner/util/output-names.d.ts.map +1 -0
- package/dist/src/planner/util/output-names.js +20 -0
- package/dist/src/planner/util/output-names.js.map +1 -0
- package/dist/src/planner/util/row-estimates.d.ts +11 -0
- package/dist/src/planner/util/row-estimates.d.ts.map +1 -1
- package/dist/src/planner/util/row-estimates.js +28 -0
- package/dist/src/planner/util/row-estimates.js.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.js +3 -2
- package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
- package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
- package/dist/src/runtime/emit/add-constraint.js +22 -6
- package/dist/src/runtime/emit/add-constraint.js.map +1 -1
- package/dist/src/runtime/emit/alter-schema-event.d.ts +59 -4
- package/dist/src/runtime/emit/alter-schema-event.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-schema-event.js +63 -4
- package/dist/src/runtime/emit/alter-schema-event.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 -92
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
- package/dist/src/runtime/emit/analyze.js +15 -4
- package/dist/src/runtime/emit/analyze.js.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts +37 -0
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -0
- package/dist/src/runtime/emit/assertion-drop-guard.js +59 -0
- package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +33 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.js +124 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -0
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +10 -227
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -1
- package/dist/src/runtime/emit/create-assertion.js +31 -14
- package/dist/src/runtime/emit/create-assertion.js.map +1 -1
- package/dist/src/runtime/emit/cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte.js +11 -6
- package/dist/src/runtime/emit/cte.js.map +1 -1
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +169 -1
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/drop-assertion.js +8 -8
- package/dist/src/runtime/emit/drop-assertion.js.map +1 -1
- package/dist/src/runtime/emit/drop-column-guards.d.ts +151 -0
- package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -0
- package/dist/src/runtime/emit/drop-column-guards.js +230 -0
- package/dist/src/runtime/emit/drop-column-guards.js.map +1 -0
- package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-table.js +6 -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 +4 -0
- package/dist/src/runtime/emit/drop-view.js.map +1 -1
- package/dist/src/runtime/emit/key-set-semi-join.d.ts.map +1 -1
- package/dist/src/runtime/emit/key-set-semi-join.js +5 -3
- package/dist/src/runtime/emit/key-set-semi-join.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +4 -4
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +34 -22
- 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 +7 -2
- package/dist/src/runtime/emit/materialized-view.js.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.js +4 -5
- package/dist/src/runtime/emit/recursive-cte.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/emit/update.d.ts.map +1 -1
- package/dist/src/runtime/emit/update.js +18 -6
- package/dist/src/runtime/emit/update.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/row-constraints.d.ts +85 -0
- package/dist/src/runtime/row-constraints.d.ts.map +1 -0
- package/dist/src/runtime/row-constraints.js +239 -0
- package/dist/src/runtime/row-constraints.js.map +1 -0
- package/dist/src/runtime/types.d.ts +18 -11
- 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 +14 -1
- package/dist/src/schema/assertion.d.ts.map +1 -1
- package/dist/src/schema/assertion.js +14 -1
- package/dist/src/schema/assertion.js.map +1 -1
- package/dist/src/schema/catalog-persistability.js +19 -3
- package/dist/src/schema/catalog-persistability.js.map +1 -1
- package/dist/src/schema/catalog.d.ts +6 -0
- package/dist/src/schema/catalog.d.ts.map +1 -1
- package/dist/src/schema/catalog.js +26 -36
- package/dist/src/schema/catalog.js.map +1 -1
- package/dist/src/schema/column-source-resolver.d.ts +18 -0
- package/dist/src/schema/column-source-resolver.d.ts.map +1 -0
- package/dist/src/schema/column-source-resolver.js +22 -0
- package/dist/src/schema/column-source-resolver.js.map +1 -0
- package/dist/src/schema/constraint-builder.d.ts.map +1 -1
- package/dist/src/schema/constraint-builder.js +7 -1
- package/dist/src/schema/constraint-builder.js.map +1 -1
- package/dist/src/schema/ddl-generator.js +8 -0
- package/dist/src/schema/ddl-generator.js.map +1 -1
- package/dist/src/schema/lens-compiler.d.ts.map +1 -1
- package/dist/src/schema/lens-compiler.js +203 -51
- package/dist/src/schema/lens-compiler.js.map +1 -1
- package/dist/src/schema/lens-prover.d.ts +2 -3
- package/dist/src/schema/lens-prover.d.ts.map +1 -1
- package/dist/src/schema/lens-prover.js +19 -11
- package/dist/src/schema/lens-prover.js.map +1 -1
- package/dist/src/schema/manager.d.ts +30 -12
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +49 -17
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/schema/rename-rewriter.d.ts +142 -0
- package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
- package/dist/src/schema/rename-rewriter.js +254 -9
- package/dist/src/schema/rename-rewriter.js.map +1 -1
- package/dist/src/schema/reserved-tags.d.ts +1 -1
- package/dist/src/schema/reserved-tags.d.ts.map +1 -1
- package/dist/src/schema/reserved-tags.js +4 -3
- package/dist/src/schema/reserved-tags.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts +16 -0
- package/dist/src/schema/schema-differ.d.ts.map +1 -1
- package/dist/src/schema/schema-differ.js +122 -11
- package/dist/src/schema/schema-differ.js.map +1 -1
- package/dist/src/schema/view.d.ts +11 -0
- package/dist/src/schema/view.d.ts.map +1 -1
- package/dist/src/schema/view.js +12 -0
- package/dist/src/schema/view.js.map +1 -1
- package/dist/src/types/builtin-types.d.ts +38 -0
- package/dist/src/types/builtin-types.d.ts.map +1 -1
- package/dist/src/types/builtin-types.js +77 -26
- package/dist/src/types/builtin-types.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/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/{working-table-iterable.d.ts → array-row-iterable.d.ts} +6 -6
- package/dist/src/util/array-row-iterable.d.ts.map +1 -0
- package/dist/src/util/{working-table-iterable.js → array-row-iterable.js} +6 -6
- package/dist/src/util/array-row-iterable.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/events.d.ts +3 -0
- package/dist/src/vtab/events.d.ts.map +1 -1
- package/dist/src/vtab/events.js.map +1 -1
- package/dist/src/vtab/manifest.d.ts +15 -0
- package/dist/src/vtab/manifest.d.ts.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 +107 -157
- 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 +57 -1
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +103 -2
- 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 +59 -2
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/dist/src/vtab/table.d.ts +8 -1
- package/dist/src/vtab/table.d.ts.map +1 -1
- package/dist/src/vtab/table.js.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
- package/dist/src/util/working-table-iterable.d.ts.map +0 -1
- package/dist/src/util/working-table-iterable.js.map +0 -1
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { asRun } from '../types.js';
|
|
2
2
|
import { emitCallFromPlan } from '../emitters.js';
|
|
3
3
|
import { createRowSlot } from '../context-helpers.js';
|
|
4
|
-
import { QuereusError } from '../../common/errors.js';
|
|
4
|
+
import { QuereusError, RelationNotFoundError } from '../../common/errors.js';
|
|
5
5
|
import { StatusCode } from '../../common/types.js';
|
|
6
6
|
import { createLogger } from '../../common/logger.js';
|
|
7
7
|
import { buildColumnIndexMap, withGeneratedColumnGraph, requireVtabModule, resolveNamedConstraintClass, namedConstraintExists, assertConstraintNameFree, validateCollationForType, columnDefToSchema } from '../../schema/table.js';
|
|
8
8
|
import { validateForeignKeyCollations, buildForeignKeyConstraintSchema, extractColumnLevelCheckConstraints, extractColumnLevelForeignKeys, extractColumnLevelUniqueConstraints } from '../../schema/constraint-builder.js';
|
|
9
9
|
import { quoteIdentifier, expressionToString, astToString } from '../../emit/ast-stringify.js';
|
|
10
|
-
import { renameTableInAst, renameColumnInAst, renameColumnInCheckExpression } from '../../schema/rename-rewriter.js';
|
|
10
|
+
import { renameTableInAst, renameColumnInAst, renameColumnInCheckExpression, renameColumnInColumnExpressions, renameTableInColumnExpressions } from '../../schema/rename-rewriter.js';
|
|
11
11
|
import { assertCatalogObjectPersistable, assertRenameDependentsPersistable } from '../../schema/catalog-persistability.js';
|
|
12
12
|
import { assertUniqueConstraintIndexNameFree, assertUniqueConstraintNotDuplicated, uniqueConstraintColumnSetKey } from '../../schema/catalog.js';
|
|
13
13
|
import { isTruthy } from '../../util/comparison.js';
|
|
14
14
|
import { assertDdlTransactionPolicy, isExplicitTransactionOpen } from './ddl-transaction-policy.js';
|
|
15
|
-
import {
|
|
15
|
+
import { buildColumnSourceResolver } from '../../schema/column-source-resolver.js';
|
|
16
|
+
import { assertNoColumnDefaultNamesColumn, assertNoCheckConstraintNamesColumn, assertNoAssertionNamesColumn, assertNoForeignKeyReferencesColumn } from './drop-column-guards.js';
|
|
17
|
+
import { emitAlterSchemaEvent, withStatementScopedSchemaEvents } from './alter-schema-event.js';
|
|
16
18
|
import { foldDefaultToType, validateAndParse } from '../../types/validation.js';
|
|
17
19
|
import { snapshotStaleMaterializedViews, propagateTableRenameToMaterializedViews, propagateColumnRenameToMaterializedViews, restoreUnaffectedMaterializedViews, attachMaintainedDerivation, detachMaintainedDerivation, } from './materialized-view-helpers.js';
|
|
20
|
+
import { propagateTableRenameToAssertions, propagateColumnRenameToAssertions, } from './assertion-rename-helpers.js';
|
|
18
21
|
import { isMaintainedTable } from '../../schema/derivation.js';
|
|
19
22
|
import { inferType } from '../../types/registry.js';
|
|
20
23
|
const log = createLogger('runtime:emit:alter-table');
|
|
@@ -35,7 +38,9 @@ export function emitAlterTable(plan, ctx) {
|
|
|
35
38
|
// (via a row slot over the backfill's row descriptor). When the new column also carries a
|
|
36
39
|
// CHECK, its predicates ride alongside as further callbacks, evaluated per backfilled row
|
|
37
40
|
// against `[...existingRow, backfilledValue]`. Slot order is fixed: backfill first
|
|
38
|
-
// (present whenever checks are), then the checks in order
|
|
41
|
+
// (present whenever checks are), then the checks in order — this MUST match
|
|
42
|
+
// `AlterTableNode.addColumnExpressions()` (planner/nodes/alter-table-node.ts), which is
|
|
43
|
+
// the order the optimizer rewrites these children in via getChildren/withChildren.
|
|
39
44
|
const backfill = action.type === 'addColumn' ? action.backfill : undefined;
|
|
40
45
|
const checks = action.type === 'addColumn' ? action.checks : undefined;
|
|
41
46
|
const params = [
|
|
@@ -68,58 +73,66 @@ export function emitAlterTable(plan, ctx) {
|
|
|
68
73
|
? `cannot ALTER TABLE '${tableSchema.name}': it is a materialized view — use ALTER MATERIALIZED VIEW for tags`
|
|
69
74
|
: `cannot ALTER '${tableSchema.name}': it is a materialized view — its shape is defined by the view body (drop and recreate to change it)`, StatusCode.ERROR);
|
|
70
75
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
// Every arm runs under the statement-scoped schema-event scope: an arm that fails
|
|
77
|
+
// after the module call has already let an emitter-backed module announce the
|
|
78
|
+
// statement (it emits from inside `module.alterTable`, not at the statement's end),
|
|
79
|
+
// so the failure path must retract that announcement. See
|
|
80
|
+
// {@link withStatementScopedSchemaEvents} for why this sits at the statement
|
|
81
|
+
// boundary rather than inside any one arm's revert.
|
|
82
|
+
return withStatementScopedSchemaEvents(rctx, async () => {
|
|
83
|
+
switch (action.type) {
|
|
84
|
+
case 'renameTable':
|
|
85
|
+
return runRenameTable(rctx, tableSchema, schema, action.newName, plan.sql);
|
|
86
|
+
case 'renameColumn':
|
|
87
|
+
return runRenameColumn(rctx, tableSchema, schema, action.oldName, action.newName, plan.sql);
|
|
88
|
+
case 'addColumn': {
|
|
89
|
+
// Slot order set in `params`: backfill callback first (if any), then check callbacks.
|
|
90
|
+
const backfillCb = backfill ? args[0] : undefined;
|
|
91
|
+
const checkCbs = args.slice(backfill ? 1 : 0);
|
|
92
|
+
return runAddColumn(rctx, tableSchema, schema, action.column, plan.sql, backfill, backfillCb, checks, checkCbs);
|
|
93
|
+
}
|
|
94
|
+
case 'dropColumn':
|
|
95
|
+
return runDropColumn(rctx, tableSchema, schema, action.name, plan.sql);
|
|
96
|
+
case 'dropConstraint':
|
|
97
|
+
return runDropConstraint(rctx, tableSchema, schema, action.name, plan.sql);
|
|
98
|
+
case 'renameConstraint':
|
|
99
|
+
return runRenameConstraint(rctx, tableSchema, schema, action.oldName, action.newName, plan.sql);
|
|
100
|
+
case 'alterPrimaryKey':
|
|
101
|
+
return runAlterPrimaryKey(rctx, tableSchema, schema, action.columns, plan.sql);
|
|
102
|
+
case 'alterColumn':
|
|
103
|
+
return runAlterColumn(rctx, tableSchema, schema, action, plan.sql);
|
|
104
|
+
case 'setTags': {
|
|
105
|
+
const target = action.target;
|
|
106
|
+
if (action.mode === 'merge') {
|
|
107
|
+
// ADD TAGS — per-key merge onto the live tag set.
|
|
108
|
+
if (target.kind === 'column')
|
|
109
|
+
return runMergeColumnTags(rctx, tableSchema, target.columnName, action.tags);
|
|
110
|
+
if (target.kind === 'constraint')
|
|
111
|
+
return runMergeConstraintTags(rctx, tableSchema, target.constraintName, action.tags);
|
|
112
|
+
return runMergeTableTags(rctx, tableSchema, action.tags);
|
|
113
|
+
}
|
|
114
|
+
// SET TAGS — whole-set replace.
|
|
96
115
|
if (target.kind === 'column')
|
|
97
|
-
return
|
|
116
|
+
return runSetColumnTags(rctx, tableSchema, target.columnName, action.tags);
|
|
98
117
|
if (target.kind === 'constraint')
|
|
99
|
-
return
|
|
100
|
-
return
|
|
118
|
+
return runSetConstraintTags(rctx, tableSchema, target.constraintName, action.tags);
|
|
119
|
+
return runSetTableTags(rctx, tableSchema, action.tags);
|
|
101
120
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return runDropConstraintTags(rctx, tableSchema, target.constraintName, action.keys);
|
|
116
|
-
return runDropTableTags(rctx, tableSchema, action.keys);
|
|
121
|
+
case 'dropTags': {
|
|
122
|
+
// DROP TAGS — per-key delete (atomic NOTFOUND if any key absent).
|
|
123
|
+
const target = action.target;
|
|
124
|
+
if (target.kind === 'column')
|
|
125
|
+
return runDropColumnTags(rctx, tableSchema, target.columnName, action.keys);
|
|
126
|
+
if (target.kind === 'constraint')
|
|
127
|
+
return runDropConstraintTags(rctx, tableSchema, target.constraintName, action.keys);
|
|
128
|
+
return runDropTableTags(rctx, tableSchema, action.keys);
|
|
129
|
+
}
|
|
130
|
+
case 'setMaintained':
|
|
131
|
+
return runSetMaintained(rctx, tableSchema, schema, action.columns, action.select);
|
|
132
|
+
case 'dropMaintained':
|
|
133
|
+
return runDropMaintained(rctx, tableSchema, schema);
|
|
117
134
|
}
|
|
118
|
-
|
|
119
|
-
return runSetMaintained(rctx, tableSchema, schema, action.columns, action.select);
|
|
120
|
-
case 'dropMaintained':
|
|
121
|
-
return runDropMaintained(rctx, tableSchema, schema);
|
|
122
|
-
}
|
|
135
|
+
});
|
|
123
136
|
}
|
|
124
137
|
const note = (() => {
|
|
125
138
|
switch (action.type) {
|
|
@@ -155,7 +168,7 @@ export function emitAlterTable(plan, ctx) {
|
|
|
155
168
|
note,
|
|
156
169
|
};
|
|
157
170
|
}
|
|
158
|
-
async function runRenameTable(rctx, tableSchema, schema, newName) {
|
|
171
|
+
async function runRenameTable(rctx, tableSchema, schema, newName, sql) {
|
|
159
172
|
const oldName = tableSchema.name;
|
|
160
173
|
// Check for name conflict
|
|
161
174
|
if (schema.getTable(newName)) {
|
|
@@ -186,7 +199,9 @@ async function runRenameTable(rctx, tableSchema, schema, newName) {
|
|
|
186
199
|
// omit the hook.
|
|
187
200
|
const module = requireVtabModule(tableSchema);
|
|
188
201
|
if (module.renameTable) {
|
|
189
|
-
|
|
202
|
+
// `sql` marks this call as the statement's own action: an emitter-backed module
|
|
203
|
+
// emits its schema-change event iff it is present (see VirtualTableModule.renameTable).
|
|
204
|
+
await module.renameTable(rctx.db, tableSchema.schemaName, oldName, newName, sql);
|
|
190
205
|
}
|
|
191
206
|
// Events this transaction already recorded still carry the OLD name; relabel them so
|
|
192
207
|
// the commit delivers every event under the name the table has at delivery. AFTER the
|
|
@@ -196,9 +211,11 @@ async function runRenameTable(rctx, tableSchema, schema, newName) {
|
|
|
196
211
|
// matching where the other ALTER arms call `remapBatchedDataEvents`.
|
|
197
212
|
//
|
|
198
213
|
// NOTE: batched SCHEMA events are deliberately out of scope here. A schema event
|
|
199
|
-
// records a DDL operation, not current state —
|
|
200
|
-
//
|
|
201
|
-
//
|
|
214
|
+
// records a DDL operation, not current state — each now carries the statement's own
|
|
215
|
+
// canonical `ddl` text (and, for a rename, `oldObjectName`), so relabelling
|
|
216
|
+
// `objectName` without rewriting that text would produce an incoherent instruction.
|
|
217
|
+
// A consumer replays the schema events in order; the rename is one of them, carrying
|
|
218
|
+
// this very statement's SQL, so earlier events legitimately name the old table.
|
|
202
219
|
rctx.db._getEventEmitter().renameBatchedEvents(tableSchema.schemaName, oldName, newName);
|
|
203
220
|
// Deferred constraint checks this transaction already parked carry evaluators compiled
|
|
204
221
|
// against the OLD name — their scan leaves would connect to a table that no longer
|
|
@@ -265,13 +282,18 @@ async function runRenameTable(rctx, tableSchema, schema, newName) {
|
|
|
265
282
|
await module.finalizeRename?.(rctx.db, tableSchema.schemaName, oldName, newName);
|
|
266
283
|
// The public schema-change event, for a module with no emitter of its own — see
|
|
267
284
|
// {@link emitAlterSchemaEvent} for why every arm emits at its tail rather than
|
|
268
|
-
// alongside the module call.
|
|
269
|
-
//
|
|
270
|
-
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
285
|
+
// alongside the module call. `objectName` is the NEW table; `oldObjectName` says
|
|
286
|
+
// what it renamed FROM, so a receiver can tell which of its tables the event is about.
|
|
287
|
+
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
288
|
+
type: 'alter', objectType: 'table',
|
|
289
|
+
objectName: newName,
|
|
290
|
+
oldObjectName: oldName,
|
|
291
|
+
ddl: sql,
|
|
292
|
+
});
|
|
271
293
|
log('Renamed table %s.%s to %s', tableSchema.schemaName, oldName, newName);
|
|
272
294
|
return null;
|
|
273
295
|
}
|
|
274
|
-
async function runRenameColumn(rctx, tableSchema, schema, oldName, newName) {
|
|
296
|
+
async function runRenameColumn(rctx, tableSchema, schema, oldName, newName, sql) {
|
|
275
297
|
const colIndex = tableSchema.columnIndexMap.get(oldName.toLowerCase());
|
|
276
298
|
if (colIndex === undefined) {
|
|
277
299
|
throw new QuereusError(`Column '${oldName}' not found in table '${tableSchema.name}'`, StatusCode.ERROR);
|
|
@@ -290,7 +312,7 @@ async function runRenameColumn(rctx, tableSchema, schema, oldName, newName) {
|
|
|
290
312
|
// this probe runs pre-mutation while the propagation runs post-) is that
|
|
291
313
|
// `isTableInUnaliasedScope` skips the renamed table itself and probes only OTHER
|
|
292
314
|
// sources, whose column sets this rename does not touch.
|
|
293
|
-
const resolveColumnInSource = buildColumnSourceResolver(rctx.db);
|
|
315
|
+
const resolveColumnInSource = buildColumnSourceResolver(rctx.db.schemaManager);
|
|
294
316
|
assertRenameDependentsPersistable(rctx.db, schema, ast => renameColumnInAst(ast, tableSchema.name, oldName, newName, tableSchema.schemaName, resolveColumnInSource), t => rewriteTableForColumnRename(t, tableSchema.schemaName.toLowerCase(), tableSchema.name, oldName, newName, resolveColumnInSource));
|
|
295
317
|
assertRenamedColumnBackingNamesFree(tableSchema, colIndex, oldName, newName);
|
|
296
318
|
const existingCol = tableSchema.columns[colIndex];
|
|
@@ -309,6 +331,7 @@ async function runRenameColumn(rctx, tableSchema, schema, oldName, newName) {
|
|
|
309
331
|
oldName,
|
|
310
332
|
newName,
|
|
311
333
|
newColumnDefAst: newColumnDef,
|
|
334
|
+
ddl: sql,
|
|
312
335
|
});
|
|
313
336
|
}
|
|
314
337
|
else {
|
|
@@ -348,6 +371,7 @@ async function runRenameColumn(rctx, tableSchema, schema, oldName, newName) {
|
|
|
348
371
|
objectName: tableSchema.name,
|
|
349
372
|
columnName: newName,
|
|
350
373
|
oldColumnName: oldName,
|
|
374
|
+
ddl: sql,
|
|
351
375
|
});
|
|
352
376
|
log('Renamed column %s.%s.%s to %s', tableSchema.schemaName, tableSchema.name, oldName, newName);
|
|
353
377
|
return null;
|
|
@@ -423,7 +447,7 @@ function assertInlineConstraintNamesFree(tableSchema, columnDef) {
|
|
|
423
447
|
seen.add(declared.name.toLowerCase());
|
|
424
448
|
}
|
|
425
449
|
}
|
|
426
|
-
async function runAddColumn(rctx, tableSchema, schema, columnDef, backfill, backfillCb, checks, checkCbs) {
|
|
450
|
+
async function runAddColumn(rctx, tableSchema, schema, columnDef, sql, backfill, backfillCb, checks, checkCbs) {
|
|
427
451
|
// Validate column doesn't already exist
|
|
428
452
|
if (tableSchema.columnIndexMap.has(columnDef.name.toLowerCase())) {
|
|
429
453
|
throw new QuereusError(`Column '${columnDef.name}' already exists in table '${tableSchema.name}'`, StatusCode.ERROR);
|
|
@@ -578,10 +602,19 @@ async function runAddColumn(rctx, tableSchema, schema, columnDef, backfill, back
|
|
|
578
602
|
// the inverse event remap.
|
|
579
603
|
let addedColIndex;
|
|
580
604
|
try {
|
|
605
|
+
// `ddl` marks this call — and only this one — as the statement's own action: the
|
|
606
|
+
// inline-constraint installs below and any revert calls pass none, so an
|
|
607
|
+
// emitter-backed module announces exactly ONE event for the whole statement.
|
|
608
|
+
//
|
|
609
|
+
// That marker settles HOW MANY events a successful statement announces, not whether a
|
|
610
|
+
// failed one announces any: this call is not the end of the statement, so a failure in
|
|
611
|
+
// the inline-constraint installs below leaves this announcement already batched. The
|
|
612
|
+
// statement-scoped retraction wrapped around the whole arm dispatch is what removes it.
|
|
581
613
|
updatedTableSchema = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, {
|
|
582
614
|
type: 'addColumn',
|
|
583
615
|
columnDef,
|
|
584
616
|
backfillEvaluator,
|
|
617
|
+
ddl: sql,
|
|
585
618
|
});
|
|
586
619
|
// Events this transaction already batched for the table still describe the
|
|
587
620
|
// pre-ADD column set; insert the backfilled value at the new slot so a listener
|
|
@@ -695,6 +728,9 @@ async function runAddColumn(rctx, tableSchema, schema, columnDef, backfill, back
|
|
|
695
728
|
// orphans) and — store-backed — persists. Thread the returned schema forward so
|
|
696
729
|
// each constraint layers on the last. The module's answer carries no
|
|
697
730
|
// generated-column bookkeeping of its own, so re-derive it each round.
|
|
731
|
+
// Deliberately NO `ddl`: this is an engine-internal sub-step of the ADD COLUMN
|
|
732
|
+
// statement, so an emitter-backed module must announce nothing for it — the
|
|
733
|
+
// statement's one event rode the `addColumn` call above.
|
|
698
734
|
const withConstraint = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, {
|
|
699
735
|
type: 'addConstraint',
|
|
700
736
|
constraint,
|
|
@@ -720,14 +756,14 @@ async function runAddColumn(rctx, tableSchema, schema, columnDef, backfill, back
|
|
|
720
756
|
});
|
|
721
757
|
// ONE event for the whole statement, even when the column declared inline constraints.
|
|
722
758
|
// The install loop above makes a second `module.alterTable(addConstraint)` round-trip per
|
|
723
|
-
// inline constraint
|
|
724
|
-
//
|
|
725
|
-
//
|
|
726
|
-
// shape: do not "fix" this into two events.
|
|
759
|
+
// inline constraint; an emitter-backed module now agrees on one event too, because only
|
|
760
|
+
// the `addColumn` call carried `ddl` and a module emits iff it is set. Do not "fix"
|
|
761
|
+
// this into per-constraint events on either path.
|
|
727
762
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
728
763
|
type: 'alter', objectType: 'column',
|
|
729
764
|
objectName: tableSchema.name,
|
|
730
765
|
columnName: columnDef.name,
|
|
766
|
+
ddl: sql,
|
|
731
767
|
});
|
|
732
768
|
log('Added column %s to table %s.%s', columnDef.name, tableSchema.schemaName, tableSchema.name);
|
|
733
769
|
return null;
|
|
@@ -746,6 +782,14 @@ async function runAddColumn(rctx, tableSchema, schema, columnDef, backfill, back
|
|
|
746
782
|
* mask the original violation. Restoring the catalog entry is a no-op when the ALTER failed
|
|
747
783
|
* before registering anything (the original schema is still the live one).
|
|
748
784
|
*
|
|
785
|
+
* Every module call here passes no `ddl`, deliberately: an emitter-backed module emits only
|
|
786
|
+
* for a call carrying `ddl`, so the unwinding itself announces nothing. That is the SECOND
|
|
787
|
+
* line of defence, not the only one — the failed statement's own `addColumn` call DID carry
|
|
788
|
+
* `ddl`, and an emitter-backed module already batched an event for it before we got here.
|
|
789
|
+
* What actually keeps a failed ADD COLUMN silent is the statement-scoped retraction the whole
|
|
790
|
+
* arm dispatch runs under (`withStatementScopedSchemaEvents` in `emitAlterTable`'s `run()`),
|
|
791
|
+
* which drops that event as the error propagates.
|
|
792
|
+
*
|
|
749
793
|
* NOTE: the hand-back is by NAME, so it assumes a name resolves to the constraint this
|
|
750
794
|
* ALTER installed. A pre-existing constraint can legitimately share an auto-name (nothing
|
|
751
795
|
* rejects `constraint _check_w check (…)` on a table that later gets `add column w …
|
|
@@ -808,6 +852,12 @@ async function validateBackfillAgainstChecks(rctx, columnOnlySchema, newCheckCon
|
|
|
808
852
|
const checkSql = expressionToString(cc.expr);
|
|
809
853
|
const sql = `select 1 from ${qualifiedTable} where not (${checkSql}) limit 1`;
|
|
810
854
|
const stmt = rctx.db.prepare(sql);
|
|
855
|
+
// The CHECK is SCHEMA-AUTHORED: it belongs to the altered table's own DDL, so a
|
|
856
|
+
// bare relation name inside it means the ALTERED table's schema — not the session
|
|
857
|
+
// path this freshly-prepared validation statement would otherwise inherit. Owning
|
|
858
|
+
// schema ONLY, matching `schemaAuthoredContext` (planner/building/schema-authored-context.ts),
|
|
859
|
+
// which decides the same thing for every CHECK the DML builders compile.
|
|
860
|
+
stmt._schemaPathOverride = [columnOnlySchema.schemaName];
|
|
811
861
|
try {
|
|
812
862
|
let violated = false;
|
|
813
863
|
for await (const _row of stmt._iterateRowsRaw()) {
|
|
@@ -884,7 +934,7 @@ function predicateReferencesColumn(expr, columnName) {
|
|
|
884
934
|
visit(expr);
|
|
885
935
|
return found;
|
|
886
936
|
}
|
|
887
|
-
async function runDropColumn(rctx, tableSchema, schema, columnName) {
|
|
937
|
+
async function runDropColumn(rctx, tableSchema, schema, columnName, sql) {
|
|
888
938
|
const colIndex = tableSchema.columnIndexMap.get(columnName.toLowerCase());
|
|
889
939
|
if (colIndex === undefined) {
|
|
890
940
|
throw new QuereusError(`Column '${columnName}' not found in table '${tableSchema.name}'`, StatusCode.ERROR);
|
|
@@ -917,6 +967,16 @@ async function runDropColumn(rctx, tableSchema, schema, columnName) {
|
|
|
917
967
|
throw new QuereusError(`Cannot drop column '${columnName}' from '${tableSchema.name}': it is referenced by the WHERE clause of partial index '${idx.name}'`, StatusCode.CONSTRAINT);
|
|
918
968
|
}
|
|
919
969
|
}
|
|
970
|
+
// Validate: the remaining dependents `module.alterTable` cannot narrow — a sibling
|
|
971
|
+
// column's DEFAULT, a CHECK on this table, a foreign key in another table pointing AT
|
|
972
|
+
// the column, and an assertion body. All four run before `requireVtabModule` /
|
|
973
|
+
// `module.alterTable`, so a refused drop persists nothing. Ordered by widening blast
|
|
974
|
+
// radius (a column of this table → this table → another table → the whole database), so
|
|
975
|
+
// the most locally-explainable violation is the one reported.
|
|
976
|
+
assertNoColumnDefaultNamesColumn(rctx.db, tableSchema, columnName);
|
|
977
|
+
assertNoCheckConstraintNamesColumn(rctx.db, tableSchema, columnName);
|
|
978
|
+
assertNoForeignKeyReferencesColumn(rctx.db, tableSchema, columnName);
|
|
979
|
+
assertNoAssertionNamesColumn(rctx.db, tableSchema, columnName);
|
|
920
980
|
// Call module.alterTable for data + schema update
|
|
921
981
|
const module = requireVtabModule(tableSchema);
|
|
922
982
|
if (!module.alterTable) {
|
|
@@ -925,6 +985,7 @@ async function runDropColumn(rctx, tableSchema, schema, columnName) {
|
|
|
925
985
|
const updatedTableSchema = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, {
|
|
926
986
|
type: 'dropColumn',
|
|
927
987
|
columnName,
|
|
988
|
+
ddl: sql,
|
|
928
989
|
});
|
|
929
990
|
// Events this transaction already batched for the table still carry the pre-drop
|
|
930
991
|
// arity; drop the slot so a listener at commit pairs value i with column i of the
|
|
@@ -951,6 +1012,7 @@ async function runDropColumn(rctx, tableSchema, schema, columnName) {
|
|
|
951
1012
|
type: 'drop', objectType: 'column',
|
|
952
1013
|
objectName: tableSchema.name,
|
|
953
1014
|
columnName,
|
|
1015
|
+
ddl: sql,
|
|
954
1016
|
});
|
|
955
1017
|
log('Dropped column %s from table %s.%s', columnName, tableSchema.schemaName, tableSchema.name);
|
|
956
1018
|
return null;
|
|
@@ -965,7 +1027,7 @@ async function runDropColumn(rctx, tableSchema, schema, columnName) {
|
|
|
965
1027
|
* module owns the actual array rewrite and, for a UNIQUE, tearing down the
|
|
966
1028
|
* implicit covering index that backs it.
|
|
967
1029
|
*/
|
|
968
|
-
async function runDropConstraint(rctx, tableSchema, schema, constraintName) {
|
|
1030
|
+
async function runDropConstraint(rctx, tableSchema, schema, constraintName, sql) {
|
|
969
1031
|
const constraintClass = resolveNamedConstraintClass(tableSchema, constraintName);
|
|
970
1032
|
if (constraintClass === 'unique') {
|
|
971
1033
|
rejectDerivedFromIndex(tableSchema, constraintName, 'DROP');
|
|
@@ -977,6 +1039,7 @@ async function runDropConstraint(rctx, tableSchema, schema, constraintName) {
|
|
|
977
1039
|
const updatedTableSchema = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, {
|
|
978
1040
|
type: 'dropConstraint',
|
|
979
1041
|
constraintName,
|
|
1042
|
+
ddl: sql,
|
|
980
1043
|
});
|
|
981
1044
|
schema.addTable(updatedTableSchema);
|
|
982
1045
|
rctx.db.schemaManager.getChangeNotifier().notifyChange({
|
|
@@ -989,6 +1052,7 @@ async function runDropConstraint(rctx, tableSchema, schema, constraintName) {
|
|
|
989
1052
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
990
1053
|
type: 'alter', objectType: 'table',
|
|
991
1054
|
objectName: tableSchema.name,
|
|
1055
|
+
ddl: sql,
|
|
992
1056
|
});
|
|
993
1057
|
log('Dropped constraint %s from table %s.%s', constraintName, tableSchema.schemaName, tableSchema.name);
|
|
994
1058
|
return null;
|
|
@@ -999,7 +1063,7 @@ async function runDropConstraint(rctx, tableSchema, schema, constraintName) {
|
|
|
999
1063
|
* name must not already address a constraint), and rejects renaming a UNIQUE
|
|
1000
1064
|
* derived from an explicit index. Routed through `module.alterTable`.
|
|
1001
1065
|
*/
|
|
1002
|
-
async function runRenameConstraint(rctx, tableSchema, schema, oldName, newName) {
|
|
1066
|
+
async function runRenameConstraint(rctx, tableSchema, schema, oldName, newName, sql) {
|
|
1003
1067
|
const constraintClass = resolveNamedConstraintClass(tableSchema, oldName);
|
|
1004
1068
|
if (constraintClass === 'unique') {
|
|
1005
1069
|
rejectDerivedFromIndex(tableSchema, oldName, 'RENAME');
|
|
@@ -1030,6 +1094,7 @@ async function runRenameConstraint(rctx, tableSchema, schema, oldName, newName)
|
|
|
1030
1094
|
type: 'renameConstraint',
|
|
1031
1095
|
oldName,
|
|
1032
1096
|
newName,
|
|
1097
|
+
ddl: sql,
|
|
1033
1098
|
});
|
|
1034
1099
|
schema.addTable(updatedTableSchema);
|
|
1035
1100
|
rctx.db.schemaManager.getChangeNotifier().notifyChange({
|
|
@@ -1044,6 +1109,7 @@ async function runRenameConstraint(rctx, tableSchema, schema, oldName, newName)
|
|
|
1044
1109
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
1045
1110
|
type: 'alter', objectType: 'table',
|
|
1046
1111
|
objectName: tableSchema.name,
|
|
1112
|
+
ddl: sql,
|
|
1047
1113
|
});
|
|
1048
1114
|
log('Renamed constraint %s.%s.%s to %s', tableSchema.schemaName, tableSchema.name, oldName, newName);
|
|
1049
1115
|
return null;
|
|
@@ -1061,7 +1127,7 @@ function rejectDerivedFromIndex(tableSchema, constraintName, op) {
|
|
|
1061
1127
|
throw new QuereusError(`Cannot ${op} CONSTRAINT '${constraintName}' on '${tableSchema.name}': it is backed by index '${uc.derivedFromIndex}' (created via CREATE UNIQUE INDEX). Use DROP INDEX '${uc.derivedFromIndex}' instead.`, StatusCode.CONSTRAINT);
|
|
1062
1128
|
}
|
|
1063
1129
|
}
|
|
1064
|
-
async function runAlterColumn(rctx, tableSchema, schema, action) {
|
|
1130
|
+
async function runAlterColumn(rctx, tableSchema, schema, action, sql) {
|
|
1065
1131
|
const colIndex = tableSchema.columnIndexMap.get(action.columnName.toLowerCase());
|
|
1066
1132
|
if (colIndex === undefined) {
|
|
1067
1133
|
throw new QuereusError(`Column '${action.columnName}' not found in table '${tableSchema.name}'`, StatusCode.ERROR);
|
|
@@ -1118,6 +1184,7 @@ async function runAlterColumn(rctx, tableSchema, schema, action) {
|
|
|
1118
1184
|
setDataType: action.setDataType,
|
|
1119
1185
|
setDefault: action.setDefault,
|
|
1120
1186
|
setCollation: action.setCollation,
|
|
1187
|
+
ddl: sql,
|
|
1121
1188
|
});
|
|
1122
1189
|
// Events this transaction already batched still carry the PRE-conversion value at
|
|
1123
1190
|
// the altered column (`SET DATA TYPE`'s normalization, `SET NOT NULL`'s null →
|
|
@@ -1141,11 +1208,12 @@ async function runAlterColumn(rctx, tableSchema, schema, action) {
|
|
|
1141
1208
|
});
|
|
1142
1209
|
// All four attribute forms (SET/DROP NOT NULL, SET DATA TYPE, SET/DROP DEFAULT,
|
|
1143
1210
|
// SET COLLATE) report the same `alter`/`column` shape — the event says which column
|
|
1144
|
-
// changed, not which attribute.
|
|
1211
|
+
// changed, not which attribute; `ddl` says which attribute, exactly.
|
|
1145
1212
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
1146
1213
|
type: 'alter', objectType: 'column',
|
|
1147
1214
|
objectName: tableSchema.name,
|
|
1148
1215
|
columnName: action.columnName,
|
|
1216
|
+
ddl: sql,
|
|
1149
1217
|
});
|
|
1150
1218
|
log('Altered column %s.%s.%s', tableSchema.schemaName, tableSchema.name, action.columnName);
|
|
1151
1219
|
return null;
|
|
@@ -1268,7 +1336,7 @@ function runDropConstraintTags(rctx, tableSchema, constraintName, keys) {
|
|
|
1268
1336
|
log('Dropped tags on constraint %s.%s.%s', tableSchema.schemaName, tableSchema.name, constraintName);
|
|
1269
1337
|
return null;
|
|
1270
1338
|
}
|
|
1271
|
-
async function runAlterPrimaryKey(rctx, tableSchema, schema, columns) {
|
|
1339
|
+
async function runAlterPrimaryKey(rctx, tableSchema, schema, columns, sql) {
|
|
1272
1340
|
const newPkDef = columns.map(col => {
|
|
1273
1341
|
const idx = tableSchema.columnIndexMap.get(col.name.toLowerCase());
|
|
1274
1342
|
if (idx === undefined) {
|
|
@@ -1299,7 +1367,7 @@ async function runAlterPrimaryKey(rctx, tableSchema, schema, columns) {
|
|
|
1299
1367
|
if (module.alterTable) {
|
|
1300
1368
|
try {
|
|
1301
1369
|
const schemaChangePk = newPkDef.map(pk => ({ index: pk.index, desc: pk.desc ?? false }));
|
|
1302
|
-
const updatedTableSchema = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, { type: 'alterPrimaryKey', newPkColumns: schemaChangePk });
|
|
1370
|
+
const updatedTableSchema = await module.alterTable(rctx.db, tableSchema.schemaName, tableSchema.name, { type: 'alterPrimaryKey', newPkColumns: schemaChangePk, ddl: sql });
|
|
1303
1371
|
// Events this transaction already recorded identify their rows by the RETIRED
|
|
1304
1372
|
// key; re-derive each from its own row image so the commit delivers every event
|
|
1305
1373
|
// under the key the table has at delivery. AFTER the module call (a module
|
|
@@ -1329,6 +1397,7 @@ async function runAlterPrimaryKey(rctx, tableSchema, schema, columns) {
|
|
|
1329
1397
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
1330
1398
|
type: 'alter', objectType: 'table',
|
|
1331
1399
|
objectName: tableSchema.name,
|
|
1400
|
+
ddl: sql,
|
|
1332
1401
|
});
|
|
1333
1402
|
log('Altered primary key of %s.%s (native)', tableSchema.schemaName, tableSchema.name);
|
|
1334
1403
|
return null;
|
|
@@ -1397,6 +1466,7 @@ async function runAlterPrimaryKey(rctx, tableSchema, schema, columns) {
|
|
|
1397
1466
|
emitAlterSchemaEvent(rctx, tableSchema, {
|
|
1398
1467
|
type: 'alter', objectType: 'table',
|
|
1399
1468
|
objectName: tableSchema.name,
|
|
1469
|
+
ddl: sql,
|
|
1400
1470
|
});
|
|
1401
1471
|
log('Altered primary key of %s.%s (rebuild)', tableSchema.schemaName, tableSchema.name);
|
|
1402
1472
|
return null;
|
|
@@ -1495,7 +1565,7 @@ export function buildShadowTableDdl(tableSchema, shadowName, survivingColumns, n
|
|
|
1495
1565
|
async function runSetMaintained(rctx, tableSchema, schema, columns, select) {
|
|
1496
1566
|
const live = schema.getTable(tableSchema.name);
|
|
1497
1567
|
if (!live) {
|
|
1498
|
-
throw new
|
|
1568
|
+
throw new RelationNotFoundError(`no such table: ${tableSchema.name}`);
|
|
1499
1569
|
}
|
|
1500
1570
|
const explicit = columns !== undefined && columns.length > 0;
|
|
1501
1571
|
// Any omitted-insert defaults ride inside `select` (→ derivation.selectAst).
|
|
@@ -1654,6 +1724,11 @@ async function propagateTableRenameInSchema(db, schema, renamedSchemaName, oldNa
|
|
|
1654
1724
|
});
|
|
1655
1725
|
}
|
|
1656
1726
|
}
|
|
1727
|
+
// Assertions: same in-place body rewrite as plain views, plus a regenerated
|
|
1728
|
+
// `violationSql` (the text the commit-time evaluator re-parses). Assertions
|
|
1729
|
+
// feed no materialized view, so order against the MV pass is free; sitting
|
|
1730
|
+
// next to the view loop keeps the plain schema-level objects together.
|
|
1731
|
+
propagateTableRenameToAssertions(db, schema, renamedSchemaName, oldName, newName);
|
|
1657
1732
|
// Materialized views: same in-place body rewrite as plain views ("MV ≡
|
|
1658
1733
|
// faster view"), plus the derived-field re-key, row-time re-registration,
|
|
1659
1734
|
// and staleness discipline the MV record needs. Runs AFTER the view loop
|
|
@@ -1691,6 +1766,20 @@ function rewriteTableForTableRename(table, renamedSchemaLower, oldName, newName)
|
|
|
1691
1766
|
changed = true;
|
|
1692
1767
|
return { ...idx };
|
|
1693
1768
|
});
|
|
1769
|
+
// Column-level expressions — a DEFAULT (`w integer default ((select min(v) from u))`)
|
|
1770
|
+
// and a generated column's body. Unlike the column verb's arm, no seeded/unseeded
|
|
1771
|
+
// split: `renameTableInAst` resolves nothing against an implicit owning table, so one
|
|
1772
|
+
// entry point covers the renamed table's own self-referencing default and every other
|
|
1773
|
+
// table's alike.
|
|
1774
|
+
//
|
|
1775
|
+
// Also unlike the collections above, no per-item shallow copy: the rewrite is in place
|
|
1776
|
+
// and a `ColumnSchema`'s own fields are untouched, so a fresh column object would only
|
|
1777
|
+
// make the catalog's array stop being identical to the one the module's rename hook
|
|
1778
|
+
// just handed back. Flipping `changed` is what re-registers the table and fires
|
|
1779
|
+
// `table_modified`, which is all the copies above achieve either.
|
|
1780
|
+
const columnsRewritten = renameTableInColumnExpressions(table.columns, oldName, newName, renamedSchemaLower);
|
|
1781
|
+
if (columnsRewritten)
|
|
1782
|
+
changed = true;
|
|
1694
1783
|
if (!changed)
|
|
1695
1784
|
return table;
|
|
1696
1785
|
return Object.freeze({
|
|
@@ -1700,21 +1789,6 @@ function rewriteTableForTableRename(table, renamedSchemaLower, oldName, newName)
|
|
|
1700
1789
|
indexes: table.indexes ? Object.freeze(newIndexes) : table.indexes,
|
|
1701
1790
|
});
|
|
1702
1791
|
}
|
|
1703
|
-
/**
|
|
1704
|
-
* The catalog-backed {@link ResolveColumnInSource} the column-rename rewriters consult
|
|
1705
|
-
* to keep their unqualified-reference walk scope-aware. Built once per statement and
|
|
1706
|
-
* shared by the pre-flight probe in {@link runRenameColumn} and the real propagation
|
|
1707
|
-
* below, so the two cannot drift apart. Note it resolves against the LIVE catalog on
|
|
1708
|
-
* every call, so sharing it does not by itself freeze the answer between the two passes
|
|
1709
|
-
* — see the pre-flight's comment for why they agree anyway.
|
|
1710
|
-
*/
|
|
1711
|
-
function buildColumnSourceResolver(db) {
|
|
1712
|
-
return (s, t, col) => {
|
|
1713
|
-
const targetSchema = db.schemaManager.getSchema(s);
|
|
1714
|
-
const targetTable = targetSchema?.getTable(t);
|
|
1715
|
-
return targetTable?.columnIndexMap.has(col.toLowerCase()) ?? false;
|
|
1716
|
-
};
|
|
1717
|
-
}
|
|
1718
1792
|
async function propagateColumnRename(rctx, renamedSchemaName, tableName, oldCol, newCol, preStaleMvs, resolveColumnInSource) {
|
|
1719
1793
|
const schemaManager = rctx.db.schemaManager;
|
|
1720
1794
|
for (const schema of schemaManager._getAllSchemas()) {
|
|
@@ -1769,6 +1843,10 @@ async function propagateColumnRenameInSchema(db, schema, renamedSchemaName, tabl
|
|
|
1769
1843
|
});
|
|
1770
1844
|
}
|
|
1771
1845
|
}
|
|
1846
|
+
// Assertions: same in-place body rewrite as plain views (unseeded walker —
|
|
1847
|
+
// an assertion body owns its own FROM scopes), plus a regenerated
|
|
1848
|
+
// `violationSql`.
|
|
1849
|
+
propagateColumnRenameToAssertions(db, schema, renamedSchemaName, tableName, oldCol, newCol, resolveColumnInSource);
|
|
1772
1850
|
// Materialized views: same in-place body rewrite as plain views, then the
|
|
1773
1851
|
// MV-specific tail — backing-column rename for a shifted output name,
|
|
1774
1852
|
// row-time re-registration, staleness discipline (the listener marked every
|
|
@@ -1786,7 +1864,7 @@ function rewriteTableForColumnRename(table, renamedSchemaLower, tableName, oldCo
|
|
|
1786
1864
|
const newChecks = table.checkConstraints.map(cc => {
|
|
1787
1865
|
const rewrote = isRenamedTable
|
|
1788
1866
|
? renameColumnInCheckExpression(cc.expr, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource)
|
|
1789
|
-
: renameColumnInAst(cc.expr, tableName, oldCol, newCol, renamedSchemaLower);
|
|
1867
|
+
: renameColumnInAst(cc.expr, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource);
|
|
1790
1868
|
if (!rewrote)
|
|
1791
1869
|
return cc;
|
|
1792
1870
|
changed = true;
|
|
@@ -1832,12 +1910,29 @@ function rewriteTableForColumnRename(table, renamedSchemaLower, tableName, oldCo
|
|
|
1832
1910
|
const newIndexes = (table.indexes ?? []).map(idx => {
|
|
1833
1911
|
const rewrote = isRenamedTable
|
|
1834
1912
|
? renameColumnInCheckExpression(idx.predicate, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource)
|
|
1835
|
-
: renameColumnInAst(idx.predicate, tableName, oldCol, newCol, renamedSchemaLower);
|
|
1913
|
+
: renameColumnInAst(idx.predicate, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource);
|
|
1836
1914
|
if (!rewrote)
|
|
1837
1915
|
return idx;
|
|
1838
1916
|
changed = true;
|
|
1839
1917
|
return { ...idx };
|
|
1840
1918
|
});
|
|
1919
|
+
// Column-level expressions — a DEFAULT (`b integer default (new.a + 1)`) and a
|
|
1920
|
+
// generated column's body (`g integer generated always as (a + 1)`). Same branch split
|
|
1921
|
+
// the checks and predicates use above: the renamed table's own columns take the seeded
|
|
1922
|
+
// walk (a generated body's bare `a` binds to the owning table; a default's `new.a`
|
|
1923
|
+
// names its row image), any other table's take the unseeded one (it can reach here only
|
|
1924
|
+
// through a subquery, whose FROM must bind the ref).
|
|
1925
|
+
//
|
|
1926
|
+
// Unlike the collections above, no per-item shallow copy: the rewrite is in place and a
|
|
1927
|
+
// `ColumnSchema`'s own fields are untouched, so a fresh column object would only make
|
|
1928
|
+
// the catalog's array stop being identical to the one the module's rename hook just
|
|
1929
|
+
// built and handed back. Flipping `changed` is what re-registers the table and fires
|
|
1930
|
+
// `table_modified`, which is all the copies above achieve either.
|
|
1931
|
+
const columnsRewritten = isRenamedTable
|
|
1932
|
+
? renameColumnInColumnExpressions(table.columns, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource)
|
|
1933
|
+
: rewriteOtherTableColumnExpressions(table.columns, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource);
|
|
1934
|
+
if (columnsRewritten)
|
|
1935
|
+
changed = true;
|
|
1841
1936
|
if (!changed)
|
|
1842
1937
|
return table;
|
|
1843
1938
|
return Object.freeze({
|
|
@@ -1847,6 +1942,31 @@ function rewriteTableForColumnRename(table, renamedSchemaLower, tableName, oldCo
|
|
|
1847
1942
|
indexes: table.indexes ? Object.freeze(newIndexes) : table.indexes,
|
|
1848
1943
|
});
|
|
1849
1944
|
}
|
|
1945
|
+
/**
|
|
1946
|
+
* The unseeded arm of the column-expression rewrite above, for a table that is NOT the
|
|
1947
|
+
* renamed one. `renameColumnInColumnExpressions` is deliberately seeded-only (that is the
|
|
1948
|
+
* whole reason it exists), so the other branch walks the two fields directly with
|
|
1949
|
+
* {@link renameColumnInAst} — the same entry point the checks and predicates arms use for
|
|
1950
|
+
* a foreign table, and for the same reason: an unqualified ref in someone else's default
|
|
1951
|
+
* must bind inside its own subquery's FROM, never to this table.
|
|
1952
|
+
*
|
|
1953
|
+
* `resolveColumnInSource` is as load-bearing here as on the seeded arm, and for the mirror
|
|
1954
|
+
* reason: without it the walk cannot tell that an inner FROM source exposes the old name,
|
|
1955
|
+
* so a nested `(select (select max(a) from other) from t)` rewrites the INNER `a` — which
|
|
1956
|
+
* binds to `other` — and the default silently starts reading a different column. It also
|
|
1957
|
+
* keeps this pass in step with the pre-flight persistability probe, which runs the same
|
|
1958
|
+
* rewriter with the resolver supplied.
|
|
1959
|
+
*/
|
|
1960
|
+
function rewriteOtherTableColumnExpressions(columns, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource) {
|
|
1961
|
+
let changed = false;
|
|
1962
|
+
for (const col of columns) {
|
|
1963
|
+
for (const expr of [col.defaultValue, col.generatedExpr]) {
|
|
1964
|
+
if (expr && renameColumnInAst(expr, tableName, oldCol, newCol, renamedSchemaLower, resolveColumnInSource))
|
|
1965
|
+
changed = true;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
return changed;
|
|
1969
|
+
}
|
|
1850
1970
|
/**
|
|
1851
1971
|
* Build a minimal constraints array from an existing ColumnSchema
|
|
1852
1972
|
* so that the ColumnDef AST accurately represents the column.
|