/**
 * @author DBU
 * @date 18/06/21
 * @version 1.0.0
 * @project SIEAU
 * @table public.utilisateurs_habilitations
 */

# --- !Ups
insert into utilisateurs_habilitations select login, 'MAT' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'MAT_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'MAT');
insert into utilisateurs_habilitations select login, 'SITUATION' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'SITUATION_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'SITUATION');
insert into utilisateurs_habilitations select login, 'PRODUCTION' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'PRODUCTION_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'PRODUCTION');
insert into utilisateurs_habilitations select login, 'QUALITO' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'QUALITO_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'QUALITO');
insert into utilisateurs_habilitations select login, 'PIEZO' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'PIEZO_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'PIEZO');
insert into utilisateurs_habilitations select login, 'HYDRO' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'HYDRO_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'HYDRO');
insert into utilisateurs_habilitations select login, 'PLUVIO' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'PLUVIO_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'PLUVIO');
insert into utilisateurs_habilitations select login, 'INSTALLATION' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'INSTALLATION_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'INSTALLATION');
insert into utilisateurs_habilitations select login, 'DISTRIBUTION' from utilisateurs where login not in (select login from utilisateurs_habilitations where habilitation = 'DISTRIBUTION_FORBIDEN') and login not in (select login from utilisateurs_habilitations where habilitation = 'DISTRIBUTION');
delete from utilisateurs_habilitations where habilitation like '%_FORBIDEN';
# --- !Downs
delete from utilisateurs_habilitations where habilitation like '%_FORBIDEN';