77 lines
3.0 KiB
Python
77 lines
3.0 KiB
Python
"""add member notifications
|
|
|
|
Revision ID: 9d3c5b7a1f2e
|
|
Revises: e2a1f9c4b6d3, f25d0f745a17
|
|
Create Date: 2026-04-01 11:30:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "9d3c5b7a1f2e"
|
|
down_revision: Union[str, tuple[str, str], None] = ("e2a1f9c4b6d3", "f25d0f745a17")
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("members", sa.Column("notifications_enabled", sa.Boolean(), nullable=False, server_default=sa.true()))
|
|
|
|
op.add_column(
|
|
"site_settings",
|
|
sa.Column("automatic_member_notifications_enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
|
|
)
|
|
op.add_column(
|
|
"site_settings",
|
|
sa.Column("nz_public_holiday_notifications_enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
|
|
)
|
|
op.add_column(
|
|
"site_settings",
|
|
sa.Column("invoice_reminder_notifications_enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
|
|
)
|
|
op.add_column(
|
|
"site_settings",
|
|
sa.Column("invoice_day_of_week", sa.Integer(), nullable=False, server_default="1"),
|
|
)
|
|
|
|
op.create_table(
|
|
"member_notification_dispatches",
|
|
sa.Column("member_id", sa.Uuid(), nullable=False),
|
|
sa.Column("notification_type", sa.String(length=64), nullable=False),
|
|
sa.Column("dispatch_key", sa.String(length=255), nullable=False),
|
|
sa.Column("metadata", sa.JSON(), nullable=True),
|
|
sa.Column("id", sa.Uuid(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.ForeignKeyConstraint(["member_id"], ["members.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("member_id", "dispatch_key", name="uq_member_notification_dispatches_member_key"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_member_notification_dispatches_member_id"),
|
|
"member_notification_dispatches",
|
|
["member_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
op.f("ix_member_notification_dispatches_notification_type"),
|
|
"member_notification_dispatches",
|
|
["notification_type"],
|
|
unique=False,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_member_notification_dispatches_notification_type"), table_name="member_notification_dispatches")
|
|
op.drop_index(op.f("ix_member_notification_dispatches_member_id"), table_name="member_notification_dispatches")
|
|
op.drop_table("member_notification_dispatches")
|
|
|
|
op.drop_column("site_settings", "invoice_day_of_week")
|
|
op.drop_column("site_settings", "invoice_reminder_notifications_enabled")
|
|
op.drop_column("site_settings", "nz_public_holiday_notifications_enabled")
|
|
op.drop_column("site_settings", "automatic_member_notifications_enabled")
|
|
op.drop_column("members", "notifications_enabled")
|