Skip to content

Workspaces phase 3b: schema for workspace management (#277) - #334

Merged
antiv merged 1 commit into
mainfrom
workspaces-phase-3b
Nov 11, 2026
Merged

antiv merged 1 commit into
mainfrom
workspaces-phase-3b

Conversation

@antiv

@antiv antiv commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Second PR of phase 3 (plan: documents/design/2.0-plan.md, #332).

V048, all three dialects

  • workspace_invitations: one email, one workspace, a role. Only the token's SHA-256 is stored, and accepted_at / accepted_by mark it used.
  • workspaces.suspended_at: can be undone. deleted_at stays what closes a workspace.
  • workspaces.platform_features: a JSON list of models.PLATFORM_FEATURES (code, server_credentials, email). The default workspace gets all three, which is what 1.x does; others get [].
  • projects.name is unique per workspace (uq_projects_workspace_name) instead of across the installation.
    • PostgreSQL drops projects_name_key.
    • MySQL adds the new key and drops name in one ALTER.
    • SQLite rebuilds the table, which also gives projects.workspace_id the foreign key SQLite couldn't add in V046.

Nothing reads the new columns yet; 3c does.

The SQLite rebuild and foreign keys

The database client runs migrations on its own engine, whose connections set PRAGMA foreign_keys=ON. With that on, DROP TABLE projects first deletes every project and cascades: every agent, memory block, trigger and widget key goes with it. MigrationSystem._sqlite_foreign_keys_off turns foreign keys off on the connection for each SQLite migration and restores them after, as SQLite's procedure for table rebuilds does (the pragma is a no-op inside a transaction).

test_rebuilding_projects_keeps_every_child_row migrates on such an engine. Without the guard it fails with agents_config 6 → 0 and memory_blocks 7 → 0. Other databases are untouched.

Code

  • The seeded "Default Project" and the wizard's rename clash check look the name up in the workspace.
  • Template import: it now refuses agent names that are taken anywhere (409) before it creates the project. Before, an import into the default workspace whose agent names another workspace held made an empty project and answered success with agents_created: 0. This was reachable in phase 2 too; per-workspace project names make it easy to hit. The plan proposed prefixing the workspace slug instead (D1). I didn't, because a template sync derives the agent names from the project name again and would lose the prefix. The plan now says so.

Tried on real databases

V045→V048 on MySQL 8.0 and PostgreSQL 15.8 in Docker, and on SQLite through the suite:

  • migrated from V047;
  • agents kept;
  • the default workspace has the features;
  • the same project name works in two workspaces and is refused twice in one;
  • an invitation row inserts.

create_all on MySQL and PostgreSQL also builds the schema with the default workspace's features.

Tests

  • TestManagementSchema in test_workspaces_schema.py.
  • Two tests in TestProjects (test_cross_workspace.py): a project name in two workspaces, and the template import.
  • Full suite: 1914 tests pass. test_client_contract.py is unchanged.

Docs

  • docs/dev/database-and-migrations.md: table rebuilds and phase 3's columns.
  • docs/user/templates.md: the 409.
  • docs/reference/database.md: regenerated.
  • gen_docs.py drift also lists wizard.md, agent-wizard.md, alerts.md and template-format.md. They still hold: none describes project-name uniqueness or the code changed here.

V048 on all three databases: workspace_invitations, workspaces.suspended_at
and platform_features (all three for the default workspace), and project
names unique per workspace. SQLite rebuilds projects, so the migration
runner turns foreign keys off around a SQLite migration: with them on, as
the database client has them, DROP TABLE cascaded to every agent.

Project lookups by name take the workspace. A template import whose agent
names are taken anywhere is refused before it makes the project, which it
made empty in the default workspace.
@antiv
antiv merged commit a771324 into main Nov 11, 2026
@antiv
antiv deleted the workspaces-phase-3b branch November 11, 2026 20:53
@antiv antiv mentioned this pull request Nov 13, 2026
22 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant