"""add user_journal_subscriptions

Revision ID: e116d0ac314d
Revises: f98b3d2bd7b5
Create Date: 2026-07-14 08:15:54.246083
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa


revision: str = 'e116d0ac314d'
down_revision: Union[str, None] = 'f98b3d2bd7b5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_journal_subscriptions',
    sa.Column('id', sa.Uuid(), nullable=False),
    sa.Column('user_id', sa.Uuid(), nullable=False),
    sa.Column('tenant_id', sa.Uuid(), nullable=False),
    sa.Column('journal_id', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), 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(['journal_id'], ['global_journals.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_ujs_journal', 'user_journal_subscriptions', ['journal_id'], unique=False)
    op.create_index('ix_ujs_user_active', 'user_journal_subscriptions', ['user_id', 'is_active'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_ujs_user_active', table_name='user_journal_subscriptions')
    op.drop_index('ix_ujs_journal', table_name='user_journal_subscriptions')
    op.drop_table('user_journal_subscriptions')
    # ### end Alembic commands ###
