
# Alembic migration script template

"""Add calendar_entry_posts association table

Revision ID: 6cb124491c9d
Revises: 0011_add_entry_tickets
Create Date: 2025-12-07 03:40:49.194068

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import TIMESTAMP

# revision identifiers, used by Alembic.
revision = '6cb124491c9d'
down_revision = '0011_add_entry_tickets'
branch_labels = None
depends_on = None

def upgrade() -> None:
    op.create_table(
        'calendar_entry_posts',
        sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
        sa.Column('entry_id', sa.Integer(), sa.ForeignKey('calendar_entries.id', ondelete='CASCADE'), nullable=False),
        sa.Column('post_id', sa.Integer(), sa.ForeignKey('posts.id', ondelete='CASCADE'), nullable=False),
        sa.Column('created_at', TIMESTAMP(timezone=True), nullable=False, server_default=sa.func.now()),
        sa.Column('deleted_at', TIMESTAMP(timezone=True), nullable=True),
    )
    op.create_index('ix_entry_posts_entry_id', 'calendar_entry_posts', ['entry_id'])
    op.create_index('ix_entry_posts_post_id', 'calendar_entry_posts', ['post_id'])

def downgrade() -> None:
    op.drop_index('ix_entry_posts_post_id', 'calendar_entry_posts')
    op.drop_index('ix_entry_posts_entry_id', 'calendar_entry_posts')
    op.drop_table('calendar_entry_posts')
