From 8efbb2f9e5f23da5b048137132aa6a6d1b086fe1 Mon Sep 17 00:00:00 2001 From: 1445043649 <> Date: Tue, 12 May 2026 22:08:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(persistence):=20alembic=200001=20=E2=80=94?= =?UTF-8?q?=20users.default=5Fworkspace=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First Alembic revision for the DeerFlow application schema. Adds a nullable users.default_workspace_id column with an ON DELETE SET NULL FK to workspaces(id), so newly-registered users can be routed back to their default workspace on next login without consulting memberships. Uses op.batch_alter_table for SQLite ALTER compatibility (sqlite is still a supported dev fallback). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../versions/0001_users_default_workspace.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 backend/packages/harness/deerflow/persistence/migrations/versions/0001_users_default_workspace.py diff --git a/backend/packages/harness/deerflow/persistence/migrations/versions/0001_users_default_workspace.py b/backend/packages/harness/deerflow/persistence/migrations/versions/0001_users_default_workspace.py new file mode 100644 index 00000000..df949e1b --- /dev/null +++ b/backend/packages/harness/deerflow/persistence/migrations/versions/0001_users_default_workspace.py @@ -0,0 +1,44 @@ +"""users.default_workspace_id column + FK to workspaces + +Revision ID: 0001_users_default_workspace +Revises: None +Create Date: 2026-05-12 + +First Alembic revision for the DeerFlow application schema. Adds +`users.default_workspace_id` so a newly-registered user can be sent +back to their default workspace on next login without consulting the +memberships table. + +Existing deployments created `users` via `metadata.create_all()` without +this column; running `alembic upgrade head` on those DBs will simply add +the column (ON DELETE SET NULL FK), no data backfill needed. +""" + +from __future__ import annotations + +import sqlalchemy as sa +from alembic import op + +# Alembic identifiers. +revision: str = "0001_users_default_workspace" +down_revision: str | None = None +branch_labels: str | None = None +depends_on: str | None = None + + +def upgrade() -> None: + with op.batch_alter_table("users") as batch: + batch.add_column(sa.Column("default_workspace_id", sa.String(36), nullable=True)) + batch.create_foreign_key( + "fk_users_default_workspace", + "workspaces", + ["default_workspace_id"], + ["id"], + ondelete="SET NULL", + ) + + +def downgrade() -> None: + with op.batch_alter_table("users") as batch: + batch.drop_constraint("fk_users_default_workspace", type_="foreignkey") + batch.drop_column("default_workspace_id")