Skip to content

Commit 0d55557

Browse files
committed
structure: full Columns / Indexes / FKs / SQL Preview UI (DDL UI #6)
Replace the placeholder StatusPage with the working ViewSwitcher editor. The Structure tab now provides the full DDL editing surface the audit asked for. UI layout (adw::ToolbarView): - Top: AdwHeaderBar with table-name Entry + driver badge. - Content: AdwViewSwitcher + AdwViewStack with four pages: Columns — one editable row per column: Name (Entry), Type (ComboBoxText with curated per-driver suggestions + free-text), Nullable / PK / Auto (CheckButtons), Default (Entry), Remove (trash icon). Add Column button trailing the rows. Indexes — read-only ColumnView-like rows with Name / Cols / UNIQUE/PRIMARY badge / Remove. Primary index is non-removable (it's owned by the PK column constraint). Foreign Keys — read-only rows with Name / Cols / "→ ref" pointer / Remove. Add Foreign Key button opens an AdwAlertDialog form for name + col multiselect + ref table + ref cols + ON DELETE / UPDATE drop-downs. SQL Preview — sourceview5::View read-only with sql syntax highlighting. Regenerates on every tracker OpsChanged event by calling materialize(). - Bottom: existing ActionBar with Discard / Save / Drop Table. Editing flow: - ColumnEdited / TableNameEdited / Add* / Remove* events mutate the in-memory model (Rc<RefCell<Vec<…>>>) and then push the matching StructureOp + inverse onto the per-tab tracker. - New mode collapses everything into a single CreateTable op which is rebuilt on every mutation; Edit mode pushes per-attribute AlterColumn / AddColumn / DropColumn / AddIndex / DropIndex / AddForeignKey / DropForeignKey / RenameTable / RenameColumn ops. materialize() in StructureChangeTracker handles dialect quirks (MySQL alter-grouping, statement ordering). - StructureTabInput::Refresh tears down the three list views and rebuilds them after every mutation. The lists are short enough (a handful of columns / indexes / FKs) that full rebuild is cheaper than per-row diffing. - Save runs validate_save() first: rejects empty table name on New mode, missing column types, duplicate column names, nullable PK columns. Validation errors surface as toasts; structural errors from materialize() (e.g. SqliteNotSupported) surface as alerts. - Discard restores the original DraftColumns from ColumnInfo.original (Edit mode) or empties the model (New mode). SQLite limit handling: rows with original.is_some() get sensitive=false + tooltip on the Type / Nullable / Default cells when the driver is sqlite. The trash icon stays enabled (DROP COLUMN landed in 3.35; older SQLite errors at execute time). Drop Foreign Key buttons are disabled across the board for SQLite. What's still deferred to follow-ups: - MySQL drag-reorder of columns (driver_supports_reorder helper is in place; the gtk::DragSource + DropTarget wiring is non-trivial and benefits from manual GUI verification). - update_added_columns_ops surgical replace — for now multiple AddColumn ops on the same column may stack; materialize-time ordering keeps the final SQL correct, but dirty-count is slightly inflated. - Live drop-down of available tables in the Add Foreign Key dialog (today the user types "schema.table" free-text into the entry). 136 tests still green, clippy clean, build green.
1 parent 0a532d5 commit 0d55557

1 file changed

Lines changed: 1319 additions & 129 deletions

File tree

0 commit comments

Comments
 (0)