"""add_notifications_table

Revision ID: 444d76da74ba
Revises: c770e08966b4
Create Date: 2025-06-02 08:25:48.241102

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

# revision identifiers, used by Alembic.
revision = '444d76da74ba'
down_revision = 'c770e08966b4'
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 'template_variables' in tables:
        op.drop_table('template_variables')
    
    op.create_table('notification',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(length=200), nullable=False),
        sa.Column('message', sa.Text(), nullable=False),
        sa.Column('type', sa.String(length=50), nullable=False),
        sa.Column('read', sa.Boolean(), nullable=False, server_default='false'),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    tables = inspector.get_table_names()
    
    if 'notification' in tables:
        op.drop_table('notification')
    
    if 'template_variables' not in tables:
        op.create_table('template_variables',
            sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
            sa.Column('notification_type', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
            sa.Column('variable_name', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
            sa.Column('description', sa.VARCHAR(length=200), autoincrement=False, nullable=False),
            sa.Column('example_value', sa.VARCHAR(length=200), autoincrement=False, nullable=True),
            sa.Column('created_at', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
            sa.PrimaryKeyConstraint('id', name=op.f('template_variables_pkey'))
        )
    # ### end Alembic commands ### 