docs: ADR-0035 4a — refine scope (CHECK/DEFAULT to constraint slice; double-precision; serial-inline)

Three design questions settled during 4a implementation (plan + ADR §13
+ README in lockstep):
- CHECK/DEFAULT defer to the 4a.2 constraint slice: sql_expr is
  validate-only (no Expr AST), so they need raw-SQL-text storage on a
  separate path, not do_create_table's Expr->compile reuse. 4a.2 now
  also covers composite UNIQUE / multi-column table CHECK.
- double precision (the lone two-word alias) handled via a keyword-pair
  branch; single-word aliases + discarded (len) cover the rest.
- serial sole-PK in a multi-column table must inline PRIMARY KEY to keep
  autoincrement (worker-step do_create_table extension).
4a core narrows to columns + types + NOT NULL/UNIQUE/PRIMARY KEY +
IF NOT EXISTS; everything else errors "not yet supported".
This commit is contained in:
claude@clouddev1
2026-05-25 07:55:22 +00:00
parent 093496fe6b
commit 94ec87b2ff
3 changed files with 127 additions and 84 deletions
+22 -14
View File
@@ -305,20 +305,28 @@ with an explicit exit gate + a written Devil's-Advocate gate, mirroring
ADR-0033's structure:
- **4a — Dispatch + `CREATE TABLE` core.** Advanced `create`
dispatch; `SqlCreateTable` for columns + types (the §3 map) +
column constraints + single/compound `PRIMARY KEY`, plus
`IF NOT EXISTS` (no-op-with-note, §4). Single-column table-level
`UNIQUE`/`CHECK` normalise into the column; **no FK** (4b). Reuses
`do_create_table`.
- **4a.2 — Composite `UNIQUE(a,b)` / multi-column table `CHECK`.**
Split out (2026-05-24, user-confirmed) because these are the first
structures the data model cannot already represent: `TableSchema`
has no slot for them. A self-contained slice that extends
`TableSchema` + the YAML round-trip + `read_schema` detection +
`do_create_table` DDL emission, with save/load/rebuild tests. (The
general rule: a DDL feature needs data-model work only when it
introduces a structure simple mode could never produce — cf. the
`UNIQUE`-index flag in 4d and the new rename op in 4h.)
dispatch; `SqlCreateTable` for columns + types (the §3 map, incl. the
two-word `double precision` and discarded length args) + the
**clean-reuse column constraints only** — `NOT NULL` / `UNIQUE` /
column-level `PRIMARY KEY` — + single/compound table-level
`PRIMARY KEY`, plus `IF NOT EXISTS` (no-op-with-note, §4). Reuses
`do_create_table` (extended so a `serial` sole-PK inlines `PRIMARY
KEY` in a multi-column table, preserving autoincrement). **No FK**
(4b); **no `DEFAULT`/`CHECK`/table-level `UNIQUE`** (4a.2).
- **4a.2 — The constraint slice.** Split out (2026-05-24,
user-confirmed) for the constraints that are *not* a clean reuse:
(1) **`CHECK`/`DEFAULT`** via the full `sql_expr` surface stored as
**raw SQL text** — needed because `sql_expr` is validate-only and
yields no `Expr` AST for `compile_check_sql`/`ColumnSpec`, so it is a
separate execution path; (2) **composite `UNIQUE(a,b)` and
multi-column table `CHECK`** — the first structures `TableSchema`
cannot already represent, needing a model + YAML round-trip +
`read_schema` detection + `do_create_table` emission extension, with
save/load/rebuild tests. Until then 4a rejects all of these
"not yet supported". (The general rule: a DDL feature needs new
model/execution work only when it introduces a structure simple mode
could never produce, or an expression the structural helper cannot
consume — cf. the `UNIQUE`-index flag in 4d and the rename op in 4h.)
- **4b — Foreign keys in `CREATE TABLE`.** Inline `REFERENCES` +
table-level `FOREIGN KEY` → relationship metadata, one undo step.
- **4c — `DROP TABLE [IF EXISTS]`** → `SqlDropTable` (cascade parity;
+1 -1
View File
File diff suppressed because one or more lines are too long