-- Ajoute itop_id à applications
ALTER TABLE applications ADD COLUMN IF NOT EXISTS itop_id INTEGER;
CREATE UNIQUE INDEX IF NOT EXISTS applications_itop_id_unique ON applications (itop_id) WHERE itop_id IS NOT NULL;

-- Ajoute criticite status si besoin
ALTER TABLE applications ADD COLUMN IF NOT EXISTS status VARCHAR(30);

-- Vide les données applicatives actuelles côté serveurs
UPDATE servers SET application_id = NULL, application_name = NULL WHERE application_id IS NOT NULL OR application_name IS NOT NULL;

-- Vide la table applications (on repart de zéro depuis iTop)
DELETE FROM applications;

SELECT 'applications vidée' as msg;
SELECT COUNT(*) as servers_cleared FROM servers WHERE application_id IS NULL AND application_name IS NULL;
