feat: ADR-0035 4a — SQL CREATE TABLE command, worker, and exit gate

Command + builder + worker for advanced-mode SQL CREATE TABLE
(sub-phase 4a), executed structurally through do_create_table:

- Command::SqlCreateTable + build_sql_create_table (ddl.rs): aliases via
  from_sql_name (incl. double precision), column- and table-level
  PRIMARY KEY, redundant-flag de-dup off a sole PK, IF NOT EXISTS.
  Advanced REGISTRY entry on the shared `create` word (SQL-first, DSL
  fallback); no-PK tables allowed (user-confirmed).
- Worker (db.rs): Request::SqlCreateTable + CreateOutcome + snapshot_then
  (one undo step); IF NOT EXISTS no-op (no snapshot, but journalled, like
  read-only commands). do_create_table inline-PK rule aligned with the
  rebuild generator schema_to_ddl — no round-trip DDL drift; serial
  autoincrement is independent of inline-PK (verified by round-trip
  tests).
- Runtime/App: dispatch + CommandOutcome::SchemaSkipped +
  AppEvent::DslCreateSkipped (structure + "already exists — skipped"
  note). Friendly catalog keys added (engine-neutral).

DEFAULT/CHECK/table-level UNIQUE are absent from the 4a grammar (parse
error with usage skeleton; friendly message + support land in the 4a.2
constraint slice) — user-confirmed.

Tests: type resolver, grammar shape, builder (incl. the PK
detection bug they caught), and tests/sql_create_table.rs (worker
round-trip, serial autoincrement first/non-first across rebuild, IF NOT
EXISTS no-op + journalling, no-PK table, one undo step) + a replay-as-
write test. 1739 pass / 0 fail / 1 ignored; clippy clean.

Exit gate: ADR-0035 Proposed -> Accepted (validated end-to-end by 4a);
README + requirements.md Q1 updated.
This commit is contained in:
claude@clouddev1
2026-05-25 10:04:28 +00:00
parent 80310929d7
commit 631074ff9c
18 changed files with 961 additions and 47 deletions
+32
View File
@@ -88,6 +88,38 @@ fn assert_failed_at(events: &[AppEvent], expected_line: usize) -> &AppEvent {
}
}
#[test]
fn replay_runs_advanced_sql_create_table_as_a_write() {
// ADR-0035 §10: `create` is a schema-write entry word (not in the
// ADR-0034 app-lifecycle skip set), so an advanced-mode SQL
// `CREATE TABLE` line replays as a write — re-applied, not skipped
// — and executes structurally (the table is rebuilt from the line).
let data = tempdir();
let (project, db) = open_project_db(data.path());
write_script(
project.path(),
"ddl.commands",
"create table Widget (id serial primary key, name text)\n\
insert into Widget (name) values ('gadget')\n",
);
let events = rt().block_on(async { run_replay(&db, project.path(), "ddl.commands").await });
assert_completed(&events, 2);
// The SQL DDL line actually created the structural table…
let desc = rt()
.block_on(async { db.describe_table("Widget".to_string(), None).await })
.expect("describe");
let names: Vec<String> = desc.columns.iter().map(|c| c.name.clone()).collect();
assert_eq!(names, vec!["id".to_string(), "name".to_string()]);
// …and the following insert (serial id auto-filled) ran against it.
let rows = rt()
.block_on(async { db.query_data("Widget".to_string(), None, None, None).await })
.expect("query")
.rows;
assert_eq!(rows.len(), 1);
}
#[test]
fn replay_three_lines_dispatches_three_commands() {
let data = tempdir();