--
-- BEGIN / #1130 — Gestion du connecteur Parapheur
--

-- Modification de la table instruction
ALTER TABLE instruction
    ADD COLUMN id_parapheur_signature character varying(255) NULL,
    ADD COLUMN statut_signature character varying(255) NULL,
    ADD COLUMN historique_signature text NULL;
COMMENT ON COLUMN instruction.id_parapheur_signature IS 'Identifiant du parapheur lié à l''instruction';
COMMENT ON COLUMN instruction.statut_signature IS 'Statut du parapheur';
COMMENT ON COLUMN instruction.historique_signature IS 'Historique de traitement du parapheur';

-- Modification de la table signataire_arrete
ALTER TABLE signataire_arrete
    ADD COLUMN email character varying(255) NULL;
COMMENT ON COLUMN signataire_arrete.email IS 'E-mail du signataire';

-- Ajout des permissions aux profils pour l'action d'envoi en signature
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'TECHNICIEN') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'TECHNICIEN'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'RESPONSABLE DIVISION INFRACTION') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'RESPONSABLE DIVISION INFRACTION'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR FONCTIONNEL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR FONCTIONNEL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'instruction_envoyer_a_signature', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'instruction_envoyer_a_signature' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));

--
-- END / #1130 — Gestion du connecteur Parapheur
--

--
-- BEGIN / Permissions pour les types de demandeurs architecte_lc, paysagiste et propriétaire
--

INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'architecte_lc_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'architecte_lc_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));

INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'paysagiste_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'paysagiste_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));

INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET UNIQUE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'QUALIFICATEUR'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'DIVISIONNAIRE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR SERVICE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'GUICHET ET SUIVI'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ADMINISTRATEUR GENERAL'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT COMMUNE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'INSTRUCTEUR POLYVALENT'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'ASSISTANTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'CHEF DE SERVICE CONTENTIEUX'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_ajouter', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_ajouter' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));
INSERT INTO om_droit (om_droit, libelle, om_profil) SELECT nextval('om_droit_seq'), 'proprietaire_modifier', (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE') WHERE NOT EXISTS (SELECT om_droit FROM om_droit WHERE libelle = 'proprietaire_modifier' AND om_profil = (SELECT om_profil FROM om_profil WHERE libelle = 'JURISTE'));

--
-- END / Permissions pour les types de demandeurs architecte_lc, paysagiste et propriétaire
--
