Turns the four synthetic tree containers into a real migration path.
Clicking any of them ("My Workspace", "Teams", "Direct",
"Ungrouped") opens a dialog that creates a real
org → company → team chain and re-parents every orphan into it, all
in one DB transaction.
cm-db (new module structure_reify)
- orphan_agents / orphan_teams / orphan_companies: workspace-scoped
SELECTs of entities without a parent binding in team_members /
company_teams / org_companies. Used both by the dialog's counter
and internally by the migration.
- count_orphans: cheap combined-count via three subqueries in a
single SELECT so the dialog only round-trips once for the header.
- reify_orphans(pool, ws, org_name, company_name, team_name):
1. begins a tx
2. inserts a new org + company + team (all `flat`, empty graphs
— user can shape them later via the existing PATCH endpoints)
3. binds company under org (org_companies "n0")
4. binds team under company (company_teams "n0")
5. inserts team_members rows for every orphan agent (n1, n2, …)
6. inserts company_teams rows for every orphan team
7. inserts org_companies rows for every orphan company
8. commits, returns the created ids + moved counts
cm-api (routes/structure)
- GET /api/structure/orphan-counts → { agents, teams, companies }
- POST /api/structure/reify-orphans → { org_id, company_id, team_id,
moved_* }. Trims + rejects any empty name; validates before
starting the transaction so a 400 never rolls anything back.
Frontend
- New OrphanMigrationDialog: fetches counts on open, three name
fields (defaults: Organization "My Workspace", Company "General",
Team "Everyone"), POSTs on save. "Nothing to migrate" state
disables the save button when the workspace is already fully
wired. Copy explicitly notes that everything is renameable in the
sidebar afterward.
- Dashboard: onTreeSelect now branches on SYNTHETIC_TREE_IDS —
clicking a synthetic node opens the dialog instead of falling
through to the (nonexistent) selection. On successful reify,
router.refresh() so the sidebar + world viz reflect the new real
chain.
What this doesn't do yet (next commit)
- Wizard auto-materialize: when creating a team/company via wizard,
auto-create parent placeholders if they don't exist. Deferred so
this commit stays focused.
39 lines
752 B
Rust
39 lines
752 B
Rust
pub mod agent_containers;
|
|
pub mod agents;
|
|
pub mod audit;
|
|
pub mod cleanup;
|
|
pub mod companies;
|
|
pub mod connections;
|
|
pub mod credits;
|
|
pub mod files;
|
|
pub mod fleet_beszel;
|
|
pub mod fleet_tailscale;
|
|
pub mod loops;
|
|
pub mod messages;
|
|
pub mod node_metrics;
|
|
pub mod node_rules;
|
|
pub mod node_tools;
|
|
pub mod nodes;
|
|
pub mod orgs;
|
|
pub mod outbox;
|
|
pub mod repo_connections;
|
|
pub mod repos;
|
|
pub mod research_outcomes;
|
|
pub mod research_publish_approvals;
|
|
pub mod research_topics;
|
|
pub mod routine_runs;
|
|
pub mod routines;
|
|
pub mod run_events;
|
|
pub mod runs;
|
|
pub mod sessions;
|
|
pub mod skills;
|
|
pub mod steps;
|
|
pub mod structure_reify;
|
|
pub mod teams;
|
|
pub mod terminal_tabs;
|
|
pub mod threads;
|
|
pub mod topology_runs;
|
|
pub mod users;
|
|
pub mod workspace_placement;
|
|
pub mod workspaces;
|