Indexes: add index / drop index, persistence, display (ADR-0025)

Implement ADR-0025 — indexes as a DSL DDL feature.

- Grammar: `add index [as <name>] on <T> (<cols>)`, `drop index
  <name>` / `drop index on <T> (<cols>)`, plus a `--cascade`
  flag on `drop column`.
- db.rs: index operations over the engine's native index
  catalog (no metadata table). The rebuild-table primitive now
  captures and recreates indexes, so `change column` and the
  relationship operations no longer silently drop them.
- `drop column` refuses an indexed column unless `--cascade`,
  which drops the covering indexes and reports each.
- Persistence: additive `indexes:` list in `project.yaml`
  (version unchanged); round-trips through rebuild/export/import.
- Display: an `Indexes:` section in the structure view and a
  nested tables/indexes items panel (S2).

Reconciles requirements.md (C3 index portion, S2 satisfied)
and CLAUDE.md. 1038 tests passing (+31), clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-16 00:15:55 +00:00
parent 41043d686b
commit 0dc159fd7e
35 changed files with 2155 additions and 73 deletions
+3
View File
@@ -198,11 +198,13 @@ pub const KEYS_AND_PLACEHOLDERS: &[(&str, &[&str])] = &[
// code, not the catalog, because spacing is alignment-
// sensitive in the multi-entry case.
("parse.usage.add_column", &[]),
("parse.usage.add_index", &[]),
("parse.usage.add_relationship", &[]),
("parse.usage.change_column", &[]),
("parse.usage.create_table", &[]),
("parse.usage.delete", &[]),
("parse.usage.drop_column", &[]),
("parse.usage.drop_index", &[]),
("parse.usage.drop_relationship", &[]),
("parse.usage.drop_table", &[]),
("parse.usage.insert", &[]),
@@ -394,6 +396,7 @@ pub const KEYS_AND_PLACEHOLDERS: &[(&str, &[&str])] = &[
&["table", "column", "src_ty", "target_ty", "total"],
),
// ---- DSL command success summaries (ADR-0019 §9 sweep) ----
("ok.index_dropped_with_column", &["index"]),
("ok.rows_deleted", &["count"]),
("ok.rows_inserted", &["count"]),
("ok.rows_updated", &["count"]),
+12 -1
View File
@@ -251,13 +251,17 @@ help:
create table <T> with pk [<col>:<type>, ...] — create a table
drop: |-
drop table <T> — remove a table
drop column [from] [table] <T>: <col> — remove a column
drop column [from] [table] <T>: <col> [--cascade] — remove a column
(--cascade also drops any index that covers the column)
drop relationship <name> — remove a relationship
drop index <name> — remove an index
drop index on <T> (<col>, ...) — remove an index by its columns
add: |-
add column [to] [table] <T>: <col> (<type>) — add a column
(for serial/shortid on a non-empty table: existing rows auto-filled)
add 1:n relationship [as <name>] from <P>.<col> to <C>.<col>
[on delete <action>] [on update <action>] [--create-fk] — declare a relationship
add index [as <name>] on <T> (<col>, ...) — create an index
rename: |-
rename column [in] [table] <T>: <old> to <new> — rename a column
change: |-
@@ -412,12 +416,16 @@ parse:
drop_relationship: |-
drop relationship <Name>
drop relationship from <Parent>.<col> to <Child>.<col>
drop_index: |-
drop index <Name>
drop index on <Table> (<col>[, ...])
add_column: "add column [to] [table] <Table>: <Name> (<Type>)"
add_relationship: |-
add 1:n relationship [as <Name>]
from <Parent>.<col> to <Child>.<col>
[on delete <action>] [on update <action>]
[--create-fk]
add_index: "add index [as <Name>] on <Table> (<col>[, ...])"
rename_column: "rename column [in] [table] <Table>: <Old> to <New>"
change_column: |-
change column [in] [table] <Table>: <Name> (<Type>)
@@ -700,6 +708,9 @@ ok:
rows_inserted: " {count} row(s) inserted"
rows_updated: " {count} row(s) updated"
rows_deleted: " {count} row(s) deleted"
# Shown beneath a `drop column --cascade` summary, once per
# index removed because it covered the dropped column.
index_dropped_with_column: " also dropped index `{index}` (it covered the column)"
# ---- Client-side success notes (ADR-0017 §6, ADR-0018 §9) ------------
client_side:
+4
View File
@@ -65,6 +65,8 @@ pub enum Operation {
ChangeColumnType,
AddRelationship,
DropRelationship,
AddIndex,
DropIndex,
Query,
Rebuild,
Replay,
@@ -92,6 +94,8 @@ impl Operation {
Self::ChangeColumnType => "change column",
Self::AddRelationship => "add relationship",
Self::DropRelationship => "drop relationship",
Self::AddIndex => "add index",
Self::DropIndex => "drop index",
Self::Query => "query",
Self::Rebuild => "rebuild",
Self::Replay => "replay",