"""Add note_embeddings table for semantic note search."""

from alembic import op

revision = "0014"
down_revision = "0013"


def upgrade() -> None:
    op.execute("""
        CREATE TABLE IF NOT EXISTS note_embeddings (
            note_id     INTEGER PRIMARY KEY REFERENCES notes(id) ON DELETE CASCADE,
            user_id     INTEGER NOT NULL,
            embedding   JSONB NOT NULL,
            updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
        )
    """)
    op.execute(
        "CREATE INDEX IF NOT EXISTS ix_note_embeddings_user_id ON note_embeddings(user_id)"
    )


def downgrade() -> None:
    op.execute("DROP TABLE IF EXISTS note_embeddings")
