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
+23 -2
View File
@@ -29,8 +29,8 @@ use crate::action::Action;
use crate::app::App;
use crate::cli::Args;
use crate::db::{
AddColumnResult, ChangeColumnTypeResult, DataResult, Database, DbError, DeleteResult,
DropColumnResult, InsertResult, QueryPlan, TableDescription, UpdateResult,
AddColumnResult, ChangeColumnTypeResult, CreateOutcome, DataResult, Database, DbError,
DeleteResult, DropColumnResult, InsertResult, QueryPlan, TableDescription, UpdateResult,
};
use crate::dsl::{Command, ColumnSpec};
use crate::dsl::walker::Severity;
@@ -1253,6 +1253,10 @@ fn spawn_dsl_dispatch(
command: command.clone(),
description,
},
Ok(CommandOutcome::SchemaSkipped(description)) => AppEvent::DslCreateSkipped {
command: command.clone(),
description,
},
Ok(CommandOutcome::Query(data)) => AppEvent::DslDataSucceeded {
command: command.clone(),
data,
@@ -1645,6 +1649,11 @@ fn parse_qualified_target(message: &str) -> Option<(String, String)> {
enum CommandOutcome {
Schema(Option<TableDescription>),
/// A SQL `CREATE TABLE IF NOT EXISTS` that matched an existing
/// table — a no-op (ADR-0035 §4). Carries the existing structure
/// so the App can render it alongside the "already exists —
/// skipped" note.
SchemaSkipped(TableDescription),
Query(DataResult),
QueryPlan(QueryPlan),
Insert(InsertResult),
@@ -1911,6 +1920,18 @@ async fn execute_command_typed(
.create_table(name, columns, primary_key, src)
.await
.map(|d| CommandOutcome::Schema(Some(d))),
Command::SqlCreateTable {
name,
columns,
primary_key,
if_not_exists,
} => database
.sql_create_table(name, columns, primary_key, if_not_exists, src)
.await
.map(|outcome| match outcome {
CreateOutcome::Created(d) => CommandOutcome::Schema(Some(d)),
CreateOutcome::Skipped(d) => CommandOutcome::SchemaSkipped(d),
}),
Command::DropTable { name } => database
.drop_table(name, src)
.await