103 lines
5.5 KiB
Python
103 lines
5.5 KiB
Python
"""Add delivery reliability and RSVP
|
|
|
|
Revision ID: 8c365be4d3a0
|
|
Revises: 5e84226bd650
|
|
Create Date: 2026-09-01 09:06:31.547215
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '8c365be4d3a0'
|
|
down_revision = '5e84226bd650'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
|
|
batch_op.create_index('ix_audit_logs_action', ['action'], unique=False)
|
|
batch_op.create_index('ix_audit_logs_created_at', ['created_at'], unique=False)
|
|
batch_op.create_index('ix_audit_logs_username', ['username'], unique=False)
|
|
|
|
op.execute(sa.text(
|
|
"DELETE FROM check_ins WHERE id NOT IN "
|
|
"(SELECT MIN(id) FROM check_ins GROUP BY guest_id)"
|
|
))
|
|
with op.batch_alter_table('check_ins', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('checked_in_by_id', sa.Integer(), nullable=True))
|
|
batch_op.create_index('ix_check_ins_event_time', ['event_id', 'checked_in_at'], unique=False)
|
|
batch_op.create_unique_constraint('uq_check_ins_guest_id', ['guest_id'])
|
|
batch_op.create_foreign_key('fk_check_ins_checked_in_by_id_users', 'users', ['checked_in_by_id'], ['id'])
|
|
|
|
with op.batch_alter_table('events', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('event_end_date', sa.DateTime(), nullable=True))
|
|
batch_op.add_column(sa.Column('rsvp_enabled', sa.Boolean(), nullable=False, server_default=sa.true()))
|
|
batch_op.add_column(sa.Column('rsvp_deadline', sa.DateTime(), nullable=True))
|
|
batch_op.add_column(sa.Column('invitation_subject', sa.String(length=255), nullable=True))
|
|
batch_op.add_column(sa.Column('invitation_message', sa.Text(), nullable=True))
|
|
batch_op.create_index('ix_events_created_by_active', ['created_by_id', 'is_active'], unique=False)
|
|
batch_op.create_index('ix_events_event_date', ['event_date'], unique=False)
|
|
|
|
with op.batch_alter_table('guests', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('invitation_status', sa.String(length=20), nullable=False, server_default='pending'))
|
|
batch_op.add_column(sa.Column('invitation_attempts', sa.Integer(), nullable=False, server_default='0'))
|
|
batch_op.add_column(sa.Column('invitation_last_error', sa.String(length=1000), nullable=True))
|
|
batch_op.add_column(sa.Column('invitation_last_attempt_at', sa.DateTime(), nullable=True))
|
|
batch_op.add_column(sa.Column('invitation_sent_at', sa.DateTime(), nullable=True))
|
|
batch_op.add_column(sa.Column('rsvp_status', sa.String(length=20), nullable=False, server_default='pending'))
|
|
batch_op.add_column(sa.Column('rsvp_responded_at', sa.DateTime(), nullable=True))
|
|
batch_op.add_column(sa.Column('rsvp_comment', sa.String(length=1000), nullable=True))
|
|
batch_op.add_column(sa.Column('dietary_requirements', sa.String(length=1000), nullable=True))
|
|
batch_op.create_index('ix_guests_event_active', ['event_id', 'is_active'], unique=False)
|
|
batch_op.create_index('ix_guests_event_email', ['event_id', 'email'], unique=False)
|
|
batch_op.create_index('ix_guests_event_full_name', ['event_id', 'full_name'], unique=False)
|
|
batch_op.create_index('ix_guests_event_rsvp', ['event_id', 'rsvp_status'], unique=False)
|
|
|
|
op.execute(sa.text("UPDATE guests SET invitation_status = 'sent' WHERE invitation_sent = true"))
|
|
with op.batch_alter_table('events', schema=None) as batch_op:
|
|
batch_op.alter_column('rsvp_enabled', server_default=None)
|
|
with op.batch_alter_table('guests', schema=None) as batch_op:
|
|
batch_op.alter_column('invitation_status', server_default=None)
|
|
batch_op.alter_column('invitation_attempts', server_default=None)
|
|
batch_op.alter_column('rsvp_status', server_default=None)
|
|
|
|
|
|
def downgrade():
|
|
with op.batch_alter_table('guests', schema=None) as batch_op:
|
|
batch_op.drop_index('ix_guests_event_rsvp')
|
|
batch_op.drop_index('ix_guests_event_full_name')
|
|
batch_op.drop_index('ix_guests_event_email')
|
|
batch_op.drop_index('ix_guests_event_active')
|
|
batch_op.drop_column('dietary_requirements')
|
|
batch_op.drop_column('rsvp_comment')
|
|
batch_op.drop_column('rsvp_responded_at')
|
|
batch_op.drop_column('rsvp_status')
|
|
batch_op.drop_column('invitation_sent_at')
|
|
batch_op.drop_column('invitation_last_attempt_at')
|
|
batch_op.drop_column('invitation_last_error')
|
|
batch_op.drop_column('invitation_attempts')
|
|
batch_op.drop_column('invitation_status')
|
|
|
|
with op.batch_alter_table('events', schema=None) as batch_op:
|
|
batch_op.drop_index('ix_events_event_date')
|
|
batch_op.drop_index('ix_events_created_by_active')
|
|
batch_op.drop_column('invitation_message')
|
|
batch_op.drop_column('invitation_subject')
|
|
batch_op.drop_column('rsvp_deadline')
|
|
batch_op.drop_column('rsvp_enabled')
|
|
batch_op.drop_column('event_end_date')
|
|
|
|
with op.batch_alter_table('check_ins', schema=None) as batch_op:
|
|
batch_op.drop_constraint('fk_check_ins_checked_in_by_id_users', type_='foreignkey')
|
|
batch_op.drop_constraint('uq_check_ins_guest_id', type_='unique')
|
|
batch_op.drop_index('ix_check_ins_event_time')
|
|
batch_op.drop_column('checked_in_by_id')
|
|
|
|
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
|
|
batch_op.drop_index('ix_audit_logs_username')
|
|
batch_op.drop_index('ix_audit_logs_created_at')
|
|
batch_op.drop_index('ix_audit_logs_action')
|