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
+35 -3
View File
@@ -14,7 +14,7 @@ use tracing::{trace, warn};
use crate::action::Action;
use crate::db::{
AddColumnResult, CascadeEffect, ChangeColumnTypeResult, DataResult, DeleteResult,
InsertResult, TableDescription, UpdateResult,
DropColumnResult, InsertResult, TableDescription, UpdateResult,
};
use crate::dsl::{Command, ParseError, parse_command};
use crate::event::AppEvent;
@@ -341,6 +341,10 @@ impl App {
self.handle_dsl_add_column_success(&command, result);
Vec::new()
}
AppEvent::DslDropColumnSucceeded { command, result } => {
self.handle_dsl_drop_column_success(&command, result);
Vec::new()
}
AppEvent::DslFailed {
command,
error,
@@ -1146,6 +1150,26 @@ impl App {
self.current_table = Some(result.description);
}
fn handle_dsl_drop_column_success(
&mut self,
command: &Command,
result: DropColumnResult,
) {
self.note_ok_summary(command);
// ADR-0025: when `--cascade` removed covering indexes,
// name each one so the learner sees the side effect.
for index in &result.dropped_indexes {
self.note_system(crate::t!(
"ok.index_dropped_with_column",
index = index,
));
}
for line in crate::output_render::render_structure(&result.description) {
self.note_system(line);
}
self.current_table = Some(result.description);
}
fn handle_dsl_change_column_success(
&mut self,
command: &Command,
@@ -1250,7 +1274,7 @@ impl App {
command: &Command,
facts: crate::friendly::FailureContext,
) -> crate::friendly::TranslateContext {
use crate::dsl::{Command as C, RelationshipSelector};
use crate::dsl::{Command as C, IndexSelector, RelationshipSelector};
use crate::friendly::{Operation, TranslateContext};
let (operation, fallback_table, fallback_column) = match command {
C::CreateTable { name, .. } => (Operation::CreateTable, Some(name.as_str()), None),
@@ -1260,7 +1284,7 @@ impl App {
Some(table.as_str()),
Some(column.as_str()),
),
C::DropColumn { table, column } => (
C::DropColumn { table, column, .. } => (
Operation::DropColumn,
Some(table.as_str()),
Some(column.as_str()),
@@ -1292,6 +1316,13 @@ impl App {
),
RelationshipSelector::Named { .. } => (Operation::DropRelationship, None, None),
},
C::AddIndex { table, .. } => (Operation::AddIndex, Some(table.as_str()), None),
C::DropIndex { selector } => match selector {
IndexSelector::Columns { table, .. } => {
(Operation::DropIndex, Some(table.as_str()), None)
}
IndexSelector::Named { .. } => (Operation::DropIndex, None, None),
},
C::Insert { table, .. } => (Operation::Insert, Some(table.as_str()), None),
C::Update { table, .. } => (Operation::Update, Some(table.as_str()), None),
C::Delete { table, .. } => (Operation::Delete, Some(table.as_str()), None),
@@ -2023,6 +2054,7 @@ mod tests {
}],
outbound_relationships: Vec::new(),
inbound_relationships: Vec::new(),
indexes: Vec::new(),
}
}