sprint8: plugin entities owner_id migration 0054 + calendar owned_mixin
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""Add owner_id to plugin entity tables for row-level ownership.
|
||||
|
||||
Revision ID: 0054
|
||||
Revises: 0053
|
||||
Create Date: 2026-07-29
|
||||
|
||||
This migration adds owner_id to plugin entity tables (files, folders,
|
||||
calendar_entries, calendars, tasks, subtasks) so that the universal
|
||||
visibility/permission system can be used for plugin entities.
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
||||
|
||||
revision = "0054"
|
||||
down_revision = "0053"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
# Plugin entity tables that need owner_id
|
||||
TABLES = [
|
||||
"files",
|
||||
"folders",
|
||||
"calendar_entries",
|
||||
"calendars",
|
||||
"tasks",
|
||||
"subtasks",
|
||||
]
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
for table in TABLES:
|
||||
op.add_column(
|
||||
table,
|
||||
sa.Column(
|
||||
"owner_id",
|
||||
PGUUID(as_uuid=True),
|
||||
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
op.create_index(f"ix_{table}_owner", table, ["owner_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for table in TABLES:
|
||||
op.drop_index(f"ix_{table}_owner", table_name=table)
|
||||
op.drop_column(table, "owner_id")
|
||||
@@ -21,7 +21,7 @@ from app.core.db import Base, TenantMixin
|
||||
from app.models.owned_mixin import OwnedMixin
|
||||
|
||||
|
||||
class Calendar(Base, TenantMixin):
|
||||
class Calendar(Base, TenantMixin, OwnedMixin):
|
||||
"""Calendar entity — tenant-scoped, soft-deletable, owned by a user."""
|
||||
|
||||
__tablename__ = "calendars"
|
||||
|
||||
Reference in New Issue
Block a user