-- Event'Go 2.0.0
-- Les imports restent archivés mais ne sont plus exécutés ni lus publiquement.
-- Cette migration n'efface aucune donnée et peut être annulée.

SET @index_exists := (
  SELECT COUNT(*) FROM information_schema.statistics
  WHERE table_schema = DATABASE()
    AND table_name = 'events'
    AND index_name = 'idx_events_public_domain_date'
);
SET @sql := IF(
  @index_exists = 0,
  'CREATE INDEX idx_events_public_domain_date ON events (visibility_status, domain, date)',
  'SELECT 1'
);
PREPARE eventgo_stmt FROM @sql;
EXECUTE eventgo_stmt;
DEALLOCATE PREPARE eventgo_stmt;

UPDATE events
SET domain = 'eventgo'
WHERE domain IS NULL
   OR TRIM(domain) = ''
   OR LOWER(domain) NOT IN ('eventgo','spiritgo','artgo','spectaclego','jobgo');
