"""add_keyword_themes_and_keywords_tables

Revision ID: 98ab619418bc
Revises: 9790f482da06
Create Date: 2026-02-19 12:01:38.174653

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '98ab619418bc'
down_revision: Union[str, Sequence[str], None] = '9790f482da06'
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('keyword_themes',
    sa.Column('id', sa.String(length=32), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=False),
    sa.Column('color', sa.String(length=16), nullable=False),
    sa.Column('enabled', sa.Boolean(), nullable=False),
    sa.Column('is_builtin', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('keyword_themes', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_keyword_themes_name'), ['name'], unique=True)

    op.create_table('keywords',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('theme_id', sa.String(length=32), nullable=False),
    sa.Column('value', sa.String(length=256), nullable=False),
    sa.Column('is_regex', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['theme_id'], ['keyword_themes.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('keywords', schema=None) as batch_op:
        batch_op.create_index('ix_keywords_theme', ['theme_id'], unique=False)
        batch_op.create_index('ix_keywords_value', ['value'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('keywords', schema=None) as batch_op:
        batch_op.drop_index('ix_keywords_value')
        batch_op.drop_index('ix_keywords_theme')

    op.drop_table('keywords')
    with op.batch_alter_table('keyword_themes', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_keyword_themes_name'))

    op.drop_table('keyword_themes')
    # ### end Alembic commands ###
