feat: ADR-0035 4g — ALTER TABLE add/drop constraint + add FK
ALTER TABLE <T> ADD [CONSTRAINT <name>] (CHECK | UNIQUE | FOREIGN KEY)
and DROP CONSTRAINT <name>. ADD = table-CHECK + composite UNIQUE + FK
(ADD PRIMARY KEY and a named UNIQUE refused — composite UNIQUE is
anonymous in our model). Each ADD reuses a low-level path with a dry-run
guard (table-CHECK/UNIQUE rebuild; FK -> add_relationship, bare
REFERENCES -> parent single PK). DROP CONSTRAINT resolves the name to a
named table-CHECK then a child-side FK, else refuses. One undo step each.
Named table-CHECKs round-trip: a nullable `name` column on
__rdbms_playground_table_checks (rebuild-only arrival; a named add on a
pre-4g project is refused with a "rebuild first" hint) plus a project.yaml
check_constraints {expr, name} extension (bare-string form still reads).
The internal-__rdbms_* guard was folded into do_add_constraint /
do_add_relationship, completing that guard class.
Grammar: the action Choice keeps one branch per verb (add/drop/rename/
alter) with an inner Choice fanning out on the distinct second keyword,
since the walker's Choice does not backtrack between same-led branches.
Tests: 7 Tier-1 parse + 2 yaml round-trip + 1 internal-guard + 9 Tier-3
e2e. Help/usage refreshed; ADR-0035 §13 4g + README + requirements.md in
lockstep.
This commit is contained in:
@@ -274,7 +274,9 @@ help:
|
||||
alter table <T> add column <col> <type> [not null] [unique] [default …] [check …]
|
||||
alter table <T> drop column <col>
|
||||
alter table <T> rename column <old> to <new>
|
||||
alter table <T> alter column <col> type <type> — change a table's columns (advanced SQL)
|
||||
alter table <T> alter column <col> type <type>
|
||||
alter table <T> add [constraint <name>] check (<expr>) | unique (<col>, …) | foreign key (<col>) references <P>[(<col>)]
|
||||
alter table <T> drop constraint <name> — evolve a table's columns and constraints (advanced SQL)
|
||||
drop: |-
|
||||
drop table <T> — remove a table
|
||||
drop column [from] [table] <T>: <col> [--cascade] — remove a column
|
||||
@@ -425,6 +427,12 @@ parse:
|
||||
expression_too_deep: "expression nested too deeply"
|
||||
on_action_specified_twice: "`on {target}` specified twice"
|
||||
change_column_flags_exclusive: "`--force-conversion` and `--dont-convert` are mutually exclusive — pick one."
|
||||
# ADR-0035 §4g: adding a primary key to an existing table is not
|
||||
# supported — every table is created with its primary key.
|
||||
alter_add_primary_key: "a table's primary key is fixed at creation — `alter table … add primary key` is not supported."
|
||||
# ADR-0035 §4g: composite UNIQUE constraints are unnamed in this
|
||||
# tool, so a `constraint <name>` prefix on UNIQUE has nowhere to go.
|
||||
alter_named_unique: "a UNIQUE constraint cannot be named — use `alter table <T> add unique (<col>, …)` without `constraint <name>`."
|
||||
unknown_type: "unknown type '{found}' (expected one of: {expected})"
|
||||
unknown_action: "unknown referential action '{found}' (expected one of: {expected})"
|
||||
# Phase D typed-value-slot mismatch (ADR-0024 §Phase D):
|
||||
@@ -475,6 +483,8 @@ parse:
|
||||
alter table <Table> drop column <Name>
|
||||
alter table <Table> rename column <Old> to <New>
|
||||
alter table <Table> alter column <Name> type <Type>
|
||||
alter table <Table> add [constraint <Name>] check (<expr>) | unique (<col>, ...) | foreign key (<col>) references <Parent>[(<col>)]
|
||||
alter table <Table> drop constraint <Name>
|
||||
drop_table: "drop table <Name>"
|
||||
drop_column: "drop column [from] [table] <Table>: <Name>"
|
||||
drop_relationship: |-
|
||||
|
||||
Reference in New Issue
Block a user