-- V31__doc_embedding_clustering_enum_constraints.sql
-- Updates check constraints for clustering run enums after adding new algorithms and statuses.

ALTER TABLE doc.doc_embedding_cluster_run
    DROP CONSTRAINT IF EXISTS doc_embedding_cluster_run_algorithm_check;

ALTER TABLE doc.doc_embedding_cluster_run
    ADD CONSTRAINT doc_embedding_cluster_run_algorithm_check
    CHECK (algorithm IN (
        'KMEANS',
        'MINI_BATCH_KMEANS',
        'DBSCAN',
        'HDBSCAN',
        'AGGLOMERATIVE'
    ));

ALTER TABLE doc.doc_embedding_cluster_run
    DROP CONSTRAINT IF EXISTS doc_embedding_cluster_run_status_check;

ALTER TABLE doc.doc_embedding_cluster_run
    ADD CONSTRAINT doc_embedding_cluster_run_status_check
    CHECK (status IN (
        'CREATED',
        'QUEUED',
        'RUNNING',
        'CANCEL_REQUESTED',
        'COMPLETED',
        'FAILED',
        'CANCELLED'
    ));

-- Optional hardening in case these columns were also created with check constraints.
ALTER TABLE doc.doc_embedding_cluster_run
    DROP CONSTRAINT IF EXISTS doc_embedding_cluster_run_execution_backend_check;

ALTER TABLE doc.doc_embedding_cluster_run
    ADD CONSTRAINT doc_embedding_cluster_run_execution_backend_check
    CHECK (execution_backend IN (
        'JAVA_LOCAL',
        'PYTHON_REMOTE'
    ));

ALTER TABLE doc.doc_embedding_cluster_run
    DROP CONSTRAINT IF EXISTS doc_embedding_cluster_run_reduction_method_check;

ALTER TABLE doc.doc_embedding_cluster_run
    ADD CONSTRAINT doc_embedding_cluster_run_reduction_method_check
    CHECK (reduction_method IN (
        'NONE',
        'PCA',
        'UMAP'
    ));
