"""Initial migration

Revision ID: fb190ac6937f
Revises: 
Create Date: 2025-07-17 15:33:43.435587

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'fb190ac6937f'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('newsletters',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('move_to_folder', sa.String(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('extract_content', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_newsletters_id'), 'newsletters', ['id'], unique=False)
    op.create_table('settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('imap_server', sa.String(), nullable=True),
    sa.Column('imap_username', sa.String(), nullable=True),
    sa.Column('imap_password', sa.String(), nullable=True),
    sa.Column('search_folder', sa.String(), nullable=True),
    sa.Column('move_to_folder', sa.String(), nullable=True),
    sa.Column('mark_as_read', sa.Boolean(), nullable=True),
    sa.Column('email_check_interval', sa.Integer(), nullable=True),
    sa.Column('auto_add_new_senders', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_settings_id'), 'settings', ['id'], unique=False)
    op.create_index(op.f('ix_settings_imap_server'), 'settings', ['imap_server'], unique=False)
    op.create_table('entries',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('newsletter_id', sa.String(), nullable=True),
    sa.Column('subject', sa.String(), nullable=True),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('received_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('message_id', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['newsletter_id'], ['newsletters.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_entries_id'), 'entries', ['id'], unique=False)
    op.create_index(op.f('ix_entries_message_id'), 'entries', ['message_id'], unique=True)
    op.create_table('senders',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('email', sa.String(), nullable=False),
    sa.Column('newsletter_id', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['newsletter_id'], ['newsletters.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_senders_email'), 'senders', ['email'], unique=True)
    op.create_index(op.f('ix_senders_id'), 'senders', ['id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_senders_id'), table_name='senders')
    op.drop_index(op.f('ix_senders_email'), table_name='senders')
    op.drop_table('senders')
    op.drop_index(op.f('ix_entries_message_id'), table_name='entries')
    op.drop_index(op.f('ix_entries_id'), table_name='entries')
    op.drop_table('entries')
    op.drop_index(op.f('ix_settings_imap_server'), table_name='settings')
    op.drop_index(op.f('ix_settings_id'), table_name='settings')
    op.drop_table('settings')
    op.drop_index(op.f('ix_newsletters_id'), table_name='newsletters')
    op.drop_table('newsletters')
    # ### end Alembic commands ###
