Commit 2d2d7519 authored by Thomas Hamel's avatar Thomas Hamel
Browse files

maj sql : suppression de la création de vue v_diff_*

parent ac10e5ae
Loading
Loading
Loading
Loading
+0 −95
Changes for doc/release-notes/8.x.0/01_saisie_these.sql: 0 added lines, 95 removed lines.
Original line number Diff line number Diff line
@@ -108,101 +108,6 @@ FROM pre
         LEFT JOIN substit_individu isub ON isub.from_id = pre.individu_id
         LEFT JOIN substit_etablissement esub ON esub.from_id = pre.etablissement_id;

create view public.v_diff_acteur
            (source_code, source_id, operation, u_source_id, u_these_id, u_role_id, u_individu_id, u_etablissement_id,
             u_qualite, s_source_id, s_these_id, s_role_id, s_individu_id, s_etablissement_id,
             s_qualite, d_source_id, d_these_id, d_role_id, d_individu_id, d_etablissement_id,
             d_qualite)
as
WITH diff AS (SELECT COALESCE(s.source_code, d.source_code) AS source_code,
                     COALESCE(s.source_id, d.source_id)     AS source_id,
                     CASE
                         WHEN src.synchro_insert_enabled = true AND s.source_code IS NOT NULL AND d.source_code IS NULL
                             THEN 'insert'::text
                         WHEN src.synchro_undelete_enabled = true AND s.source_code IS NOT NULL AND
                              d.source_code IS NOT NULL AND d.histo_destruction IS NOT NULL AND
                              d.histo_destruction <= LOCALTIMESTAMP(0) THEN 'undelete'::text
                         WHEN src.synchro_update_enabled = true AND s.source_code IS NOT NULL AND
                              d.source_code IS NOT NULL AND
                              (d.histo_destruction IS NULL OR d.histo_destruction > LOCALTIMESTAMP(0)) THEN 'update'::text
                         WHEN src.synchro_delete_enabled = true AND s.source_code IS NULL AND
                              d.source_code IS NOT NULL AND
                              (d.histo_destruction IS NULL OR d.histo_destruction > LOCALTIMESTAMP(0)) THEN 'delete'::text
                         ELSE NULL::text
                         END                                AS operation,
                     CASE
                         WHEN d.source_id <> s.source_id OR d.source_id IS NULL AND s.source_id IS NOT NULL OR
                              d.source_id IS NOT NULL AND s.source_id IS NULL THEN 1
                         ELSE 0
                         END                                AS u_source_id,
                     CASE
                         WHEN d.these_id <> s.these_id OR d.these_id IS NULL AND s.these_id IS NOT NULL OR
                              d.these_id IS NOT NULL AND s.these_id IS NULL THEN 1
                         ELSE 0
                         END                                AS u_these_id,
                     CASE
                         WHEN d.role_id <> s.role_id OR d.role_id IS NULL AND s.role_id IS NOT NULL OR
                              d.role_id IS NOT NULL AND s.role_id IS NULL THEN 1
                         ELSE 0
                         END                                AS u_role_id,
                     CASE
                         WHEN d.individu_id <> s.individu_id OR d.individu_id IS NULL AND s.individu_id IS NOT NULL OR
                              d.individu_id IS NOT NULL AND s.individu_id IS NULL THEN 1
                         ELSE 0
                         END                                AS u_individu_id,
                     CASE
                         WHEN d.etablissement_id <> s.etablissement_id OR
                              d.etablissement_id IS NULL AND s.etablissement_id IS NOT NULL OR
                              d.etablissement_id IS NOT NULL AND s.etablissement_id IS NULL THEN 1
                         ELSE 0
                         END                                AS u_etablissement_id,
                     CASE
                         WHEN d.qualite::text <> s.qualite::text OR d.qualite IS NULL AND s.qualite IS NOT NULL OR
                     d.qualite IS NOT NULL AND s.qualite IS NULL THEN 1
        ELSE 0
END                                AS u_qualite,
                     s.source_id                            AS s_source_id,
                     s.these_id                             AS s_these_id,
                     s.role_id                              AS s_role_id,
                     s.individu_id                          AS s_individu_id,
                     s.etablissement_id                     AS s_etablissement_id,
                     s.qualite                              AS s_qualite,
                     d.source_id                            AS d_source_id,
                     d.these_id                             AS d_these_id,
                     d.role_id                              AS d_role_id,
                     d.individu_id                          AS d_individu_id,
                     d.etablissement_id                     AS d_etablissement_id,
                     d.qualite                              AS d_qualite
              FROM acteur d
                       FULL JOIN src_acteur s ON s.source_id = d.source_id AND s.source_code::text = d.source_code::text
                       JOIN source src ON src.id = COALESCE(s.source_id, d.source_id) AND src.importable = true)
SELECT diff.source_code,
       diff.source_id,
       diff.operation,
       diff.u_source_id,
       diff.u_these_id,
       diff.u_role_id,
       diff.u_individu_id,
       diff.u_etablissement_id,
       diff.u_qualite,
       diff.s_source_id,
       diff.s_these_id,
       diff.s_role_id,
       diff.s_individu_id,
       diff.s_etablissement_id,
       diff.s_qualite,
       diff.d_source_id,
       diff.d_these_id,
       diff.d_role_id,
       diff.d_individu_id,
       diff.d_etablissement_id,
       diff.d_qualite
FROM diff
WHERE diff.operation IS NOT NULL
  AND (diff.operation = 'undelete'::text OR 0 <
                                            (diff.u_source_id + diff.u_these_id + diff.u_role_id + diff.u_individu_id +
                                             diff.u_etablissement_id + diff.u_qualite));

--
-- Table THESE
--