Files
dodo/migrations/versions/0020_calendar_subscriptions.py
T
bboysoul f3ad1eec03
ci / gitleaks (push) Successful in 56s
ci / docker (push) Successful in 5m55s
feat: add iCal calendar subscriptions
2026-09-20 16:37:43 +08:00

53 lines
2.0 KiB
Python

"""restore calendar subscriptions after the reverted release
Revision ID: 0020_calendar_subscriptions
Revises: 0019_backup_imports
The original revision reached production before the feature was reverted. Existing
databases may therefore already contain the table while fresh databases do not.
Keep the revision id and make the schema operation idempotent for both cases.
"""
import sqlalchemy as sa
from alembic import op
revision = "0020_calendar_subscriptions"
down_revision = "0019_backup_imports"
branch_labels = None
depends_on = None
def upgrade() -> None:
bind = op.get_bind()
if "calendar_subscriptions" in sa.inspect(bind).get_table_names():
return
op.create_table(
"calendar_subscriptions",
sa.Column("id", sa.Uuid(), nullable=False),
sa.Column("user_id", sa.Uuid(), nullable=False),
sa.Column("name", sa.String(length=120), nullable=False),
sa.Column("url", sa.Text(), nullable=False),
sa.Column("color", sa.String(length=32), nullable=False),
sa.Column("enabled", sa.Boolean(), nullable=False),
sa.Column("ics_cache", sa.Text(), nullable=True),
sa.Column("etag", sa.String(length=512), nullable=True),
sa.Column("last_modified", sa.String(length=512), nullable=True),
sa.Column("refreshed_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("last_error", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
"ix_calendar_subscriptions_user_id", "calendar_subscriptions", ["user_id"]
)
def downgrade() -> None:
bind = op.get_bind()
if "calendar_subscriptions" not in sa.inspect(bind).get_table_names():
return
op.drop_index("ix_calendar_subscriptions_user_id", table_name="calendar_subscriptions")
op.drop_table("calendar_subscriptions")