-- Migration: Étendre convention_mere_type dans avenants
-- Date: 2025-01-XX
-- Description: Ajoute 'Programmation' et 'Avenant' à l'enum convention_mere_type pour permettre
--              la création d'avenants depuis des programmations et d'autres avenants

SET @dbname = DATABASE();
SET @tablename = 'avenants';
SET @column = 'convention_mere_type';

-- Vérifier le type actuel de la colonne
SET @currentType = (
    SELECT COLUMN_TYPE 
    FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE TABLE_SCHEMA = @dbname 
    AND TABLE_NAME = @tablename 
    AND COLUMN_NAME = @column
);

-- Modifier l'enum pour inclure 'Programmation' et 'Avenant'
SET @preparedStatement = CONCAT(
    'ALTER TABLE `', @tablename, '` ',
    'MODIFY COLUMN `', @column, '` ',
    'ENUM(\'Cadre\', \'Specifique\', \'Generique\', \'Programmation\', \'Avenant\') ',
    'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL'
);

PREPARE alterEnum FROM @preparedStatement;
EXECUTE alterEnum;
DEALLOCATE PREPARE alterEnum;

-- Message de confirmation
SELECT "Migration 055: Extension de convention_mere_type dans avenants terminée avec succès." AS message;

