Repository navigation
Workspaces phase 3b: schema for workspace management (#277) - #334
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andaccepted_at/accepted_bymark it used.workspaces.suspended_at: can be undone.deleted_atstays what closes a workspace.workspaces.platform_features: a JSON list ofmodels.PLATFORM_FEATURES(code,server_credentials,email). The default workspace gets all three, which is what 1.x does; others get[].projects.nameis unique per workspace (uq_projects_workspace_name) instead of across the installation.projects_name_key.namein oneALTER.projects.workspace_idthe 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 projectsfirst deletes every project and cascades: every agent, memory block, trigger and widget key goes with it.MigrationSystem._sqlite_foreign_keys_offturns 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_rowmigrates on such an engine. Without the guard it fails withagents_config6 → 0 andmemory_blocks7 → 0. Other databases are untouched.Code
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:
create_allon MySQL and PostgreSQL also builds the schema with the default workspace's features.Tests
TestManagementSchemaintest_workspaces_schema.py.TestProjects(test_cross_workspace.py): a project name in two workspaces, and the template import.test_client_contract.pyis 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 driftalso listswizard.md,agent-wizard.md,alerts.mdandtemplate-format.md. They still hold: none describes project-name uniqueness or the code changed here.