"""initial schema

Revision ID: 000000000000
Revises:
Create Date: 2025-12-12 22:35:45.345088

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '000000000000'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('list',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('display', sa.String(), nullable=True),
    sa.Column('address', sa.String(), nullable=False),
    sa.Column('from_addr', sa.String(), nullable=True),
    sa.Column('avoid_duplicates', sa.Boolean(), nullable=True),
    sa.Column('mode', sa.String(), nullable=False),
    sa.Column('only_subscribers_send', sa.Boolean(), nullable=True),
    sa.Column('allowed_senders', sa.JSON(), nullable=True),
    sa.Column('sender_auth', sa.JSON(), nullable=True),
    sa.Column('imap_host', sa.String(), nullable=False),
    sa.Column('imap_port', sa.Integer(), nullable=False),
    sa.Column('imap_user', sa.String(), nullable=False),
    sa.Column('imap_pass', sa.String(), nullable=False),
    sa.Column('deleted', sa.Boolean(), nullable=True),
    sa.Column('deleted_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_list')),
    sa.UniqueConstraint('address', name=op.f('uq_list_address'))
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=100), nullable=False),
    sa.Column('password', sa.String(), nullable=False),
    sa.Column('api_key', sa.String(), nullable=True),
    sa.Column('role', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_user')),
    sa.UniqueConstraint('username', name=op.f('uq_user_username'))
    )
    op.create_table('email_in',
    sa.Column('message_id', sa.String(), nullable=False),
    sa.Column('list_id', sa.String(), nullable=False),
    sa.Column('subject', sa.String(), nullable=True),
    sa.Column('from_addr', sa.String(), nullable=True),
    sa.Column('headers', sa.Text(), nullable=False),
    sa.Column('raw', sa.Text(), nullable=True),
    sa.Column('received_at', sa.DateTime(), nullable=True),
    sa.Column('status', sa.String(), nullable=True),
    sa.Column('error_info', sa.JSON(), nullable=True),
    sa.ForeignKeyConstraint(['list_id'], ['list.id'], name=op.f('fk_email_in_list_id_list'), onupdate='CASCADE'),
    sa.PrimaryKeyConstraint('message_id', name=op.f('pk_email_in')),
    sa.UniqueConstraint('message_id', name=op.f('uq_email_in_message_id'))
    )
    op.create_table('logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('level', sa.String(), nullable=False),
    sa.Column('event', sa.String(), nullable=False),
    sa.Column('message', sa.Text(), nullable=False),
    sa.Column('details', sa.JSON(), nullable=True),
    sa.Column('list_id', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['list_id'], ['list.id'], name=op.f('fk_logs_list_id_list'), onupdate='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_logs'))
    )
    op.create_table('subscriber',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('list_id', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('email', sa.String(), nullable=False),
    sa.Column('comment', sa.String(), nullable=True),
    sa.Column('subscriber_type', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['list_id'], ['list.id'], name=op.f('fk_subscriber_list_id_list'), onupdate='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_subscriber'))
    )
    op.create_table('email_out',
    sa.Column('message_id', sa.String(), nullable=False),
    sa.Column('email_in_mid', sa.String(), nullable=False),
    sa.Column('list_id', sa.String(), nullable=True),
    sa.Column('subject', sa.String(), nullable=True),
    sa.Column('recipients', sa.JSON(), nullable=True),
    sa.Column('raw', sa.Text(), nullable=True),
    sa.Column('sent_at', sa.DateTime(), nullable=True),
    sa.Column('sent_successful', sa.JSON(), nullable=True),
    sa.Column('sent_failed', sa.JSON(), nullable=True),
    sa.ForeignKeyConstraint(['email_in_mid'], ['email_in.message_id'], name=op.f('fk_email_out_email_in_mid_email_in')),
    sa.ForeignKeyConstraint(['list_id'], ['list.id'], name=op.f('fk_email_out_list_id_list'), onupdate='CASCADE'),
    sa.PrimaryKeyConstraint('message_id', name=op.f('pk_email_out')),
    sa.UniqueConstraint('message_id', name=op.f('uq_email_out_message_id'))
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('email_out')
    op.drop_table('subscriber')
    op.drop_table('logs')
    op.drop_table('email_in')
    op.drop_table('user')
    op.drop_table('list')
    # ### end Alembic commands ###
