-- V9__Fix_TypesReference_Categorie_Nullable.sql
-- The entity TypeReference was redesigned to use 'domaine' instead of 'categorie'.
-- V1 created types_reference with categorie VARCHAR(50) NOT NULL, but the entity
-- no longer includes this column, causing INSERT to fail with NOT NULL violation.
-- Also drop the old unique constraint on (categorie, code) which references the old design.

-- categorie is already nullable in V1 (updated schema), these are idempotent safety guards
DO $$ BEGIN
    IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='types_reference' AND column_name='categorie' AND is_nullable='NO') THEN
        ALTER TABLE types_reference ALTER COLUMN categorie DROP NOT NULL;
    END IF;
END $$;

ALTER TABLE types_reference DROP CONSTRAINT IF EXISTS uk_type_ref;
