-- Migration: Renommer la colonne 'note' en 'num_manuel' dans bonlivr et facturec
-- pour standardiser avec bretourc.N_Manuel

-- bonlivr
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'bonlivr' AND COLUMN_NAME = 'note')
   AND NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'bonlivr' AND COLUMN_NAME = 'num_manuel')
BEGIN
    EXEC sp_rename 'bonlivr.note', 'num_manuel', 'COLUMN'
    PRINT 'Colonne bonlivr.note renommee en num_manuel'
END

-- facturec
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'facturec' AND COLUMN_NAME = 'note')
   AND NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'facturec' AND COLUMN_NAME = 'num_manuel')
BEGIN
    EXEC sp_rename 'facturec.note', 'num_manuel', 'COLUMN'
    PRINT 'Colonne facturec.note renommee en num_manuel'
END

-- bretourc : renommer N_Manuel en num_manuel pour uniformiser la casse
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'bretourc' AND COLUMN_NAME = 'N_Manuel')
   AND NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'bretourc' AND COLUMN_NAME = 'num_manuel')
BEGIN
    EXEC sp_rename 'bretourc.N_Manuel', 'num_manuel', 'COLUMN'
    PRINT 'Colonne bretourc.N_Manuel renommee en num_manuel'
END
