Add migration 055: display_calendar_id on event_invitations
Adds nullable FK to calendars, index, and backfills accepted/tentative invitations with each user's default calendar. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a68ec0e23e
commit
d00d6d6d49
@ -0,0 +1,51 @@
|
||||
"""Add display_calendar_id to event_invitations.
|
||||
|
||||
Allows invitees to assign invited events to their own calendars
|
||||
for personal organization, color, and visibility control.
|
||||
|
||||
Revision ID: 055
|
||||
Revises: 054
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "055"
|
||||
down_revision = "054"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"event_invitations",
|
||||
sa.Column(
|
||||
"display_calendar_id",
|
||||
sa.Integer(),
|
||||
sa.ForeignKey("calendars.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_event_invitations_display_calendar",
|
||||
"event_invitations",
|
||||
["display_calendar_id"],
|
||||
)
|
||||
|
||||
# Backfill accepted/tentative invitations with each user's default calendar
|
||||
op.execute("""
|
||||
UPDATE event_invitations
|
||||
SET display_calendar_id = (
|
||||
SELECT c.id FROM calendars c
|
||||
WHERE c.user_id = event_invitations.user_id
|
||||
AND c.is_default = true
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE status IN ('accepted', 'tentative')
|
||||
AND display_calendar_id IS NULL
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_event_invitations_display_calendar", table_name="event_invitations")
|
||||
op.drop_column("event_invitations", "display_calendar_id")
|
||||
Loading…
x
Reference in New Issue
Block a user