feat: ADR-0035 4i(a,b) — CREATE TABLE help/usage + describe table constraints; Phase 4 complete

(b) describe shows table-level constraints: TableDescription gains
unique_constraints + check_constraints (populated by do_describe_table
from read_schema), rendered in a new "Table constraints:" section —
composite UNIQUE and table-level CHECK (named + unnamed). The per-column
Constraints column already covered single-column NOT NULL/UNIQUE/PK/CHECK.

(a) CREATE TABLE help/usage skeleton refreshed for the column DEFAULT/
CHECK/REFERENCES, table-level composite UNIQUE, table CHECK, and
table-level FOREIGN KEY forms (4a.2/4a.3/4b) — engine-neutral,
vocab-audit clean.

With 4i's (c)/(d)/(e) already shipped, this completes sub-phase 4i — the
verification sweep — and therefore ADR-0035 Phase 4 (4a–4i). ADR-0035
Status, §13 4i, the ADR index, and requirements.md Q1 updated to
"Phase 4 complete".

Tests: render_structure table-level-constraints unit test +
e2e_describe_shows_table_level_constraints. Full suite 1917 passing /
0 failing / 1 ignored; clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-26 14:38:28 +00:00
parent c2eb8cb982
commit 22e5bf5d6a
10 changed files with 176 additions and 46 deletions
+40 -40
View File
@@ -4,17 +4,20 @@
Accepted. Design agreed with the user (2026-05-24); the approach is
**validated end-to-end by sub-phases 4a / 4a.2 / 4a.3 / 4b / 4c / 4d /
4e / 4f / 4g / 4h** (`CREATE TABLE` with column- and table-level
4e / 4f / 4g / 4h / 4i** (`CREATE TABLE` with column- and table-level
constraints and foreign keys, `DROP TABLE [IF EXISTS]`,
`CREATE [UNIQUE] INDEX` / `DROP INDEX [IF EXISTS]`, `ALTER TABLE`
add/drop/rename column, `ALTER TABLE … ALTER COLUMN TYPE`, `ALTER TABLE`
add/drop constraint + add foreign key, and `ALTER TABLE … RENAME TO`,
implemented 2026-05-25/26 — plans
add/drop constraint + add foreign key, `ALTER TABLE … RENAME TO`, and the
4i verification sweep — completion merge, simple/advanced completion
colour, describe of table-level constraints, self-ref FK indicator, and
the CREATE-TABLE help/usage refresh — implemented 2026-05-25/26 — plans
`docs/plans/20260524-adr-0035-sql-ddl-4a.md`, `…-4a2.md`, `…-4a3.md`,
`docs/plans/20260525-adr-0035-sql-ddl-4b.md`, `…-4c.md`, `…-4d.md`,
`…-4e.md`, `…-4f.md`, `…-4g.md`,
`docs/plans/20260526-adr-0035-sql-ddl-4h.md`), so the decision is accepted
while the remaining sub-phase (**4i**, §13) continues. This is **Phase 4** of the ADR-0030 roadmap (the
`docs/plans/20260526-adr-0035-sql-ddl-4h.md`,
`docs/plans/20260526-adr-0035-sql-ddl-4i.md`). **Phase 4 is complete**
(4a4i all shipped). This is **Phase 4** of the ADR-0030 roadmap (the
advanced-mode SQL surface), the peer of ADR-0031 (expression grammar),
ADR-0032 (`SELECT`), and ADR-0033 (DML). It **clarifies ADR-0030 §4**
on how DDL is represented and executed.
@@ -515,41 +518,38 @@ ADR-0033's structure:
update; ADR-0035 §6 scope — user-confirmed; documented collision
caveat). One undo step (the whole-project snapshot). Advanced-mode only;
closes the rename half of `C1`.
- **4i — Verification sweep.** Typing-surface + matrix coverage,
engine-neutral error pass, undo-parity check (one step per
statement), `help`/usage for the new forms. **Carried in from earlier
slices:** (a) refresh the `CREATE TABLE` help/usage skeleton for the
4a.2 `DEFAULT`/`CHECK`/composite-`UNIQUE`, 4a.3 table-`CHECK`, and 4b
FK forms (deferred from each) — **4d's index forms already carry their
own help/usage** (`ddl.sql_create_index` / `ddl.sql_drop_index` + the
`parse.usage.*` keys), since the nodes are new; (b) `describe` display
of table-level constraints (composite `UNIQUE` + table `CHECK`) — note
the **unique-*index* marker shipped in 4d** (`[unique]` in the
structure view + items panel), so only the table-level *constraint*
display remains here; (c) **4b self-ref
FK indicator** — a `CREATE TABLE` with a self-referencing FK
(`references <self>`) parses + executes correctly, but the pre-submit
schema-existence diagnostic falsely flags the not-yet-created self
table as unknown (the FK parent slot is `IdentSource::Tables`). Make
the diagnostic treat a FK parent equal to the `CREATE TABLE` target as
valid, so the indicator stops lying for self-references. (d) **4c
shared-entry-word completion merge** — in advanced mode a shared entry
word surfaces only the SQL node's continuations, so `drop ` offers
only `table` (not the DSL `column`/`relationship`/`index`/`constraint`)
and a partial keyword like `drop rel` returns an *empty* list (a
mid-word dead end), even though the DSL drops still parse + execute via
fallback. Merge the expected sets of all candidate nodes for a shared
entry word so advanced completion offers every valid continuation
(`drop ` → table + column + relationship + index + constraint; `drop
rel` → relationship); verify `create`/`insert`/`update`/`delete`
completion stays sensible. **4d widened this:** `create` and `drop`
now each have *two* advanced nodes (table + index), so a shared entry
word's continuations now span two SQL shapes as well as the DSL ones —
the merge matters more. (e) **Discussion flag (user, 2026-05-25):**
before/with (d), discuss **visually distinguishing simple- vs
advanced-mode completions in the hint UI (likely by colour)** so a
learner can see which continuations are DSL and which are SQL — a UX
design conversation, not just the mechanical merge.
- **4i — Verification sweep (completes Phase 4).** *(Implemented
2026-05-26 — plan `docs/plans/20260526-adr-0035-sql-ddl-4i.md`.)*
- **(a) `CREATE TABLE` help/usage skeleton** refreshed for the 4a.2
`DEFAULT`/`CHECK`/composite-`UNIQUE`, 4a.3 table-`CHECK`, and 4b FK
forms (the index forms already carried their own since 4d).
- **(b) `describe` of table-level constraints** — `TableDescription`
gained `unique_constraints` + `check_constraints`, rendered in a
"Table constraints:" section (composite `UNIQUE`, table `CHECK`
incl. **named** CHECKs). The per-column `[unique]`-index marker
shipped in 4d.
- **(c) self-ref FK indicator** — `schema_existence_diagnostics`
collects the `CREATE TABLE` target(s) (`IdentSource::NewName`, role
`table_name`) and exempts a `Tables` reference matching one from the
unknown-table flag, so a self-referencing FK no longer pre-flags the
not-yet-created table; a FK to a genuinely-unknown *other* table
still flags.
- **(d) shared-entry-word completion merge** — at the advanced-mode
entry-word boundary, `completion_probe_in_mode` walks every candidate
node and unions the viable (`Incomplete`) ones' continuations, so
`drop ` offers `table·index·column·relationship·constraint` and `drop
rel` → `relationship` (was an empty dead-end). Completion-only (the
parse path is untouched); deeper positions keep the committed walk.
- **(e) simple-vs-advanced completion colour** — each continuation is
classified `Both`/`Advanced`/`Simple` and, **only when the candidate
list mixes modes**, coloured (`mode_advanced`/`mode_simple`, `Both` =
token-kind) and block-ordered `Both → Advanced → Simple` (user-chosen
design, 2026-05-26). Single-mode lists keep the token-kind colours.
- **Staples:** matrix/typing-surface coverage extended (completion +
describe tests); engine-neutral wording held (the vocab audit covers
the new strings); undo-parity is **N/A for 4i** — every change is
read-side (completion / diagnostics / describe / help), so no undo
steps are introduced.
## Consequences