Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Make storage_backends workspace_id nullable

将 storage_backends 表的 workspace_id 字段设置为可选

Revision ID: 3c3d09cd858f
Revises: b14d95497d4f
Create Date: 2026-01-31 17:16:54.726838

"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
# 修订标识符,由 Alembic 使用
revision: str = "3c3d09cd858f"
down_revision: Union[str, Sequence[str], None] = "b14d95497d4f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Upgrade schema.

升级数据库架构:将 storage_backends 表的 workspace_id 字段改为可空
允许存储后端不绑定到特定工作空间
"""
# ### commands auto generated by Alembic - please adjust! ###
# 修改 storage_backends 表的 workspace_id 列,允许为空
op.alter_column(
"storage_backends",
"workspace_id",
existing_type=sa.VARCHAR(length=36),
nullable=True,
)
# ### end Alembic commands ###


def downgrade() -> None:
"""Downgrade schema.

降级数据库架构:将 storage_backends 表的 workspace_id 字段改为不可空
回退到要求存储后端必须绑定到工作空间的状态
"""
# ### commands auto generated by Alembic - please adjust! ###
# 修改 storage_backends 表的 workspace_id 列,设置为不可空
op.alter_column(
"storage_backends",
"workspace_id",
existing_type=sa.VARCHAR(length=36),
nullable=False,
)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion api/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class StorageBackendConfig(Base):
id = Column(
String(36), primary_key=True, index=True, default=lambda: str(uuid.uuid4())
)
workspace_id = Column(String(36), ForeignKey("workspaces.id"), nullable=False)
workspace_id = Column(String(36), ForeignKey("workspaces.id"), nullable=True)
name: Mapped[str] = mapped_column(String, unique=True, nullable=False, index=True)
backend_type: Mapped[str] = mapped_column(String, nullable=False) # local or s3
is_active: Mapped[bool] = mapped_column(Integer, default=0) # 0: False, 1: True
Expand Down