"""add_mails_table

Revision ID: 20519a2437c2
Revises: 444d76da74ba
Create Date: 2025-06-02 09:04:39.972021

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


# revision identifiers, used by Alembic.
revision = '20519a2437c2'
down_revision = '444d76da74ba'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    tables = inspector.get_table_names()
    
    if 'mails' not in tables:
        op.create_table('mails',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('recipient', sa.String(length=150), nullable=False),
            sa.Column('subject', sa.String(length=200), nullable=False),
            sa.Column('body', sa.Text(), nullable=False),
            sa.Column('status', sa.String(length=20), nullable=False),
            sa.Column('created_at', sa.DateTime(), nullable=True),
            sa.Column('sent_at', sa.DateTime(), nullable=True),
            sa.Column('template_id', sa.Integer(), nullable=True),
            sa.Column('notif_id', sa.Integer(), nullable=True),
            sa.ForeignKeyConstraint(['notif_id'], ['notifs.id'], ),
            sa.ForeignKeyConstraint(['template_id'], ['email_templates.id'], ),
            sa.PrimaryKeyConstraint('id')
        )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('mails')
    # ### end Alembic commands ### 