B2/C2: column drop / rename / change-type DSL commands
Closes B2 (rebuild-table reused outside relationships) and
C2 (full add/drop/rename/change-type column operations).
* drop column [from] [table] <T>: <col>
- ALTER TABLE DROP COLUMN (SQLite 3.35+) + metadata
cleanup in __rdbms_playground_columns.
- Refuses PK columns and columns involved in a declared
relationship (drop the relationship first).
* rename column [in] [table] <T>: <old> to <new>
- ALTER TABLE RENAME COLUMN (SQLite 3.25+); SQLite
cascades the rename through FK declarations on other
tables.
- Mirrors the new name into both metadata tables
(__rdbms_playground_columns, __rdbms_playground_relationships)
so describes stay accurate after a rename.
- Refuses identity rename and name collisions.
* change column [in] [table] <T>: <col> (<newtype>)
- Routes through the rebuild_table primitive (ADR-0013)
since SQLite ALTER doesn't support type changes.
INSERT INTO new SELECT FROM old; STRICT typing enforces
cell compatibility, transaction rolls back on mismatch.
- Refuses PK columns, relationship-involved columns,
`serial` target, and no-op same-type changes.
Adds 20 tests (parser + db layer); updates the in-app help
listing. Both prepositions independently optional in each
new command, matching `add column`'s grammar shape.
Total: 449 passing, 0 failing, 0 skipped (up from 429).
Clippy clean.
Known spec gap: column-type-change conversion compatibility
is not yet documented (currently relies on SQLite STRICT
errors); follow-up will close this.
This commit is contained in:
@@ -44,6 +44,35 @@ pub enum Command {
|
||||
column: String,
|
||||
ty: Type,
|
||||
},
|
||||
/// Remove a column from a table. Refused if the column is
|
||||
/// part of the primary key or is involved in a declared
|
||||
/// relationship — drop the relationship first.
|
||||
DropColumn {
|
||||
table: String,
|
||||
column: String,
|
||||
},
|
||||
/// Rename a column. SQLite handles cascading renames in
|
||||
/// FK references on other tables; the executor mirrors
|
||||
/// the change into our `__rdbms_playground_columns` and
|
||||
/// `__rdbms_playground_relationships` metadata tables in
|
||||
/// the same transaction.
|
||||
RenameColumn {
|
||||
table: String,
|
||||
old: String,
|
||||
new: String,
|
||||
},
|
||||
/// Change a column's type. Implemented via the
|
||||
/// rebuild-table primitive (ADR-0013) since SQLite's
|
||||
/// ALTER TABLE does not support type changes. Refused
|
||||
/// for PK columns and for columns involved in a declared
|
||||
/// relationship — those would require cascading FK
|
||||
/// type updates the v1 surface deliberately doesn't
|
||||
/// expose.
|
||||
ChangeColumnType {
|
||||
table: String,
|
||||
column: String,
|
||||
ty: Type,
|
||||
},
|
||||
/// Establish a 1:n relationship: parent_table.parent_column
|
||||
/// is the primary-key side; child_table.child_column is the
|
||||
/// foreign-key side. `name` is optional — when `None`, the
|
||||
@@ -144,6 +173,9 @@ impl Command {
|
||||
Self::CreateTable { .. } => "create table",
|
||||
Self::DropTable { .. } => "drop table",
|
||||
Self::AddColumn { .. } => "add column",
|
||||
Self::DropColumn { .. } => "drop column",
|
||||
Self::RenameColumn { .. } => "rename column",
|
||||
Self::ChangeColumnType { .. } => "change column",
|
||||
Self::AddRelationship { .. } => "add relationship",
|
||||
Self::DropRelationship { .. } => "drop relationship",
|
||||
Self::ShowTable { .. } => "show table",
|
||||
@@ -166,6 +198,9 @@ impl Command {
|
||||
| Self::ShowTable { name }
|
||||
| Self::ShowData { name } => name,
|
||||
Self::AddColumn { table, .. }
|
||||
| Self::DropColumn { table, .. }
|
||||
| Self::RenameColumn { table, .. }
|
||||
| Self::ChangeColumnType { table, .. }
|
||||
| Self::Insert { table, .. }
|
||||
| Self::Update { table, .. }
|
||||
| Self::Delete { table, .. } => table,
|
||||
|
||||
Reference in New Issue
Block a user