ALTER TABLE inventario_variantes_resolucion_log
    ALTER COLUMN precio_final DROP NOT NULL;

ALTER TABLE inventario_variantes_categoria
    DROP CONSTRAINT IF EXISTS chk_ivc_tipo_item;

ALTER TABLE inventario_variantes_categoria
    ADD CONSTRAINT chk_ivc_tipo_item
    CHECK (tipo_item IS NULL OR tipo_item = ANY (ARRAY[1,2,3,4,5,6,7,8]));

ALTER TABLE entity_category_links
    ALTER COLUMN payload_jsonb SET DEFAULT '{}'::jsonb;

ALTER TABLE entity_category_links
    ALTER COLUMN payload_jsonb SET NOT NULL;

ALTER TABLE entity_category_links
    ALTER COLUMN source_mode SET DEFAULT 'MANUAL';

ALTER TABLE entity_category_links
    ALTER COLUMN is_active SET DEFAULT TRUE;

ALTER TABLE entity_category_links
    ALTER COLUMN prioridad SET DEFAULT 100;

CREATE INDEX IF NOT EXISTS idx_ecl_active_window
    ON entity_category_links (business_id, entity_type, entity_id, vigencia_inicio, vigencia_fin)
    WHERE soft_delete IS NOT TRUE;
