constraints: CHECK — check (<expr>) at create table & add column (ADR-0029)

The fourth constraint. `check ( <expr> )` reuses the ADR-0026
WHERE-expression grammar via `Subgrammar`, so a check is
written in the same language as a `where` filter.

- Grammar: a `CHECK_CONSTRAINT` arm joins the shared
  constraint-suffix Choice; `consume_check_expr` extracts the
  parenthesised expression (paren-depth aware) into
  `ColumnSpec.check` / `Command::AddColumn.check`.
- Storage: the parsed `Expr` is compiled once to inline SQL
  (`compile_check_sql` — `compile_expr` + ADR-0028's
  param-inliner) and stored in that form everywhere — a new
  `check_expr` column in `__rdbms_playground_columns`,
  `project.yaml`'s `ColumnSchema.check`, and the column DDL
  emitted by `do_create_table` / `schema_to_ddl`.
- `add column … check` routes through the rebuild primitive
  (SQLite's `ALTER … ADD COLUMN` cannot carry it); a CHECK on
  a serial/shortid column is create-table-only and refused at
  add-column with a friendly message.
- `describe` surfaces the CHECK. ADR-0029 §7/§8 updated to the
  SQL-form decision — double-quoted identifiers, consistent
  with ADR-0028's `explain` display SQL.

1201 tests pass (+8); clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-19 16:42:18 +00:00
parent 58d8958822
commit 942222bfc9
11 changed files with 421 additions and 73 deletions
+5
View File
@@ -152,6 +152,10 @@ pub struct ColumnSchema {
/// form SQLite reports and `schema_to_ddl` echoes verbatim.
/// `None` when the column has no default.
pub default: Option<String>,
/// `CHECK` constraint in compiled-SQL form (ADR-0029 §7),
/// echoed verbatim into the rebuilt DDL. `None` when the
/// column has no check.
pub check: Option<String>,
}
/// One index as recorded in `project.yaml` (ADR-0025).
@@ -383,6 +387,7 @@ mod tests {
unique: false,
not_null: false,
default: None,
check: None,
}],
rows: vec![vec![CellValue::Text("Alice".to_string())]],
};