Skip to content
Snippets Groups Projects
Commit dcb50893 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

BDDADMIN

parent c209497c
No related branches found
No related tags found
No related merge requests found
Showing
with 295 additions and 21 deletions
CREATE OR REPLACE FUNCTION public.create_import_metarequest_for_structure(src_id text, src_code text, src_libelle_court text, src_libelle_long text, src_type text, dest_id text, dest_code text, dest_libelle_court text, dest_libelle_long text, dest_type text, dest_deleted_on timestamp with time zone, import_hash character varying)
CREATE OR REPLACE FUNCTION public.create_import_metarequest_for_structure(src_id text, src_code text, src_libelle_court text, src_libelle_long text, src_type text, src_histo text, dest_id text, dest_code text, dest_libelle_court text, dest_libelle_long text, dest_type text, dest_histo text, dest_deleted_on timestamp with time zone, import_hash character varying)
RETURNS character varying
LANGUAGE plpgsql
AS $function$
......@@ -8,20 +8,22 @@ DECLARE
sql TEXT;
BEGIN
-- normalisation des valeurs d'entrée
src_CODE = coalesce(src_CODE, 'null');
src_LIBELLE_COURT = coalesce(src_LIBELLE_COURT, 'null');
src_LIBELLE_LONG = coalesce(src_LIBELLE_LONG, 'null');
src_TYPE = coalesce(src_TYPE, 'null');
dest_CODE = coalesce(dest_CODE, 'null');
dest_LIBELLE_COURT = coalesce(dest_LIBELLE_COURT, 'null');
dest_LIBELLE_LONG = coalesce(dest_LIBELLE_LONG, 'null');
dest_TYPE = coalesce(dest_TYPE, 'null');
src_CODE = coalesce(quote_literal(src_CODE), 'NULL');
src_LIBELLE_COURT = coalesce(quote_literal(src_LIBELLE_COURT), 'NULL');
src_LIBELLE_LONG = coalesce(quote_literal(src_LIBELLE_LONG), 'NULL');
src_TYPE = coalesce(quote_literal(src_TYPE), 'NULL');
src_HISTO = coalesce(quote_literal(src_HISTO), 'NULL');
dest_CODE = coalesce(quote_literal(dest_CODE), 'NULL');
dest_LIBELLE_COURT = coalesce(quote_literal(dest_LIBELLE_COURT), 'NULL');
dest_LIBELLE_LONG = coalesce(quote_literal(dest_LIBELLE_LONG), 'NULL');
dest_TYPE = coalesce(quote_literal(dest_TYPE), 'NULL');
dest_HISTO = coalesce(quote_literal(dest_HISTO), 'NULL');
-- l'enregistrement existe dans la source mais pas dans la destination : il devra être ajouté
IF (src_ID IS NOT NULL AND dest_ID IS NULL) THEN
operation = 'insert';
hash = src_ID || '-' || import_hash;
sql = 'INSERT INTO structure(ID, CODE, LIBELLE_COURT, LIBELLE_LONG, TYPE, created_on) VALUES (' || quote_literal(src_ID) || ', ' || quote_literal(src_CODE) || ', ' || quote_literal(src_LIBELLE_COURT) || ', ' || quote_literal(src_LIBELLE_LONG) || ', ' || quote_literal(src_TYPE) || ', ' || 'LOCALTIMESTAMP(0)) ;' ;
sql = 'INSERT INTO structure(ID, CODE, LIBELLE_COURT, LIBELLE_LONG, TYPE, HISTO, created_on) VALUES (' || quote_literal(src_ID) || ', ' || src_CODE || ', ' || src_LIBELLE_COURT || ', ' || src_LIBELLE_LONG || ', ' || src_TYPE || ', ' || src_HISTO || ', ' || 'LOCALTIMESTAMP(0)) ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('insert', 'structure', src_ID, null, null, null, sql, LOCALTIMESTAMP(0), hash);
END IF;
......@@ -32,7 +34,7 @@ BEGIN
IF (src_CODE <> dest_CODE) THEN
operation = 'update';
hash = dest_ID || '-' || dest_CODE || '-' || import_hash;
sql = 'UPDATE structure SET CODE = ' || quote_literal(src_CODE) || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = 'UPDATE structure SET CODE = ' || src_CODE || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('update', 'structure', src_ID, 'CODE', src_CODE, dest_CODE, sql, LOCALTIMESTAMP(0), hash);
END IF;
......@@ -40,7 +42,7 @@ BEGIN
IF (src_LIBELLE_COURT <> dest_LIBELLE_COURT) THEN
operation = 'update';
hash = dest_ID || '-' || dest_LIBELLE_COURT || '-' || import_hash;
sql = 'UPDATE structure SET LIBELLE_COURT = ' || quote_literal(src_LIBELLE_COURT) || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = 'UPDATE structure SET LIBELLE_COURT = ' || src_LIBELLE_COURT || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('update', 'structure', src_ID, 'LIBELLE_COURT', src_LIBELLE_COURT, dest_LIBELLE_COURT, sql, LOCALTIMESTAMP(0), hash);
END IF;
......@@ -48,7 +50,7 @@ BEGIN
IF (src_LIBELLE_LONG <> dest_LIBELLE_LONG) THEN
operation = 'update';
hash = dest_ID || '-' || dest_LIBELLE_LONG || '-' || import_hash;
sql = 'UPDATE structure SET LIBELLE_LONG = ' || quote_literal(src_LIBELLE_LONG) || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = 'UPDATE structure SET LIBELLE_LONG = ' || src_LIBELLE_LONG || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('update', 'structure', src_ID, 'LIBELLE_LONG', src_LIBELLE_LONG, dest_LIBELLE_LONG, sql, LOCALTIMESTAMP(0), hash);
END IF;
......@@ -56,10 +58,18 @@ BEGIN
IF (src_TYPE <> dest_TYPE) THEN
operation = 'update';
hash = dest_ID || '-' || dest_TYPE || '-' || import_hash;
sql = 'UPDATE structure SET TYPE = ' || quote_literal(src_TYPE) || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = 'UPDATE structure SET TYPE = ' || src_TYPE || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('update', 'structure', src_ID, 'TYPE', src_TYPE, dest_TYPE, sql, LOCALTIMESTAMP(0), hash);
END IF;
-- 'HISTO' doit être mis à jour
IF (src_HISTO <> dest_HISTO) THEN
operation = 'update';
hash = dest_ID || '-' || dest_HISTO || '-' || import_hash;
sql = 'UPDATE structure SET HISTO = ' || src_HISTO || ', updated_on = LOCALTIMESTAMP(0) WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('update', 'structure', src_ID, 'HISTO', src_HISTO, dest_HISTO, sql, LOCALTIMESTAMP(0), hash);
END IF;
END IF;
......@@ -67,7 +77,7 @@ BEGIN
IF (src_ID IS NOT NULL AND dest_ID IS NOT NULL and dest_deleted_on IS NOT NULL) THEN
operation = 'undelete';
hash = dest_ID || '-' || import_hash;
sql = 'UPDATE structure SET ' || 'CODE = ' || quote_literal(src_CODE) || ', ' || 'LIBELLE_COURT = ' || quote_literal(src_LIBELLE_COURT) || ', ' || 'LIBELLE_LONG = ' || quote_literal(src_LIBELLE_LONG) || ', ' || 'TYPE = ' || quote_literal(src_TYPE) || ', ' || 'updated_on = LOCALTIMESTAMP(0), deleted_on = null WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = 'UPDATE structure SET ' || 'CODE = ' || src_CODE || ', ' || 'LIBELLE_COURT = ' || src_LIBELLE_COURT || ', ' || 'LIBELLE_LONG = ' || src_LIBELLE_LONG || ', ' || 'TYPE = ' || src_TYPE || ', ' || 'HISTO = ' || src_HISTO || ', ' || 'updated_on = LOCALTIMESTAMP(0), deleted_on = null WHERE ID = ' || quote_literal(dest_ID) || ' ;' ;
sql = sql || ' UPDATE import_reg SET executed_on = LOCALTIMESTAMP(0) WHERE import_hash = ' || quote_literal(hash) || ' ;' ;
INSERT INTO import_reg(operation, table_name, source_code, field_name, to_value, from_value, sql, created_on, import_hash) VALUES ('undelete', 'structure', src_ID, null, null, null, sql, LOCALTIMESTAMP(0), hash);
END IF;
......
<?php
//@formatter:off
return [
'name' => 'formation_demande_externe_id_uindex',
'unique' => TRUE,
'type' => 'btree',
'table' => 'formation_demande_externe',
'schema' => 'public',
'columns' => [
'id',
],
];
//@formatter:on
<?php
//@formatter:off
return [
'name' => 'ix_unicaen_privilege_categorie',
'unique' => FALSE,
'type' => 'btree',
'table' => 'unicaen_privilege_privilege',
'schema' => 'public',
'columns' => [
'categorie_id',
],
];
//@formatter:on
<?php
//@formatter:off
return [
'name' => 'privilege_code_uindex',
'unique' => TRUE,
'type' => 'btree',
'table' => 'unicaen_privilege_privilege',
'schema' => 'public',
'columns' => [
'code',
],
];
//@formatter:on
<?php
//@formatter:off
return [
'name' => 'un_unicaen_privilege_categorie_code',
'unique' => TRUE,
'type' => 'btree',
'table' => 'unicaen_privilege_categorie',
'schema' => 'public',
'columns' => [
'code',
],
];
//@formatter:on
SELECT abo.formation_id AS id,
max(f.libelle::text) AS libelle,
count(*) AS nombre,
array_agg(DISTINCT concat(a.prenom, ' ', a.nom_usage, ' <', a.email, '>')) AS listing
FROM formation_formation_abonnement abo
JOIN formation f ON abo.formation_id = f.id
JOIN agent a ON abo.agent_id::text = a.c_individu::text
WHERE abo.histo_destruction IS NULL
GROUP BY abo.formation_id
\ No newline at end of file
SELECT a.c_individu,
a.utilisateur_id,
a.prenom,
a.nom_usage,
a.created_on,
a.updated_on,
a.deleted_on,
a.octo_id,
a.preecog_id,
a.harp_id,
a.login,
a.email,
a.sexe,
a.t_contrat_long,
a.date_naissance,
a.nom_famille,
a.id,
a.histo_createur_id,
a.histo_modificateur_id,
a.histo_destructeur_id,
a.source_id,
a.id_orig
FROM agent a
WHERE a.deleted_on IS NULL
\ No newline at end of file
WITH periode AS (
SELECT to_date('01-01-2024'::text, 'dd-mm-yyyy'::text) AS debut,
to_date('31-12-2024'::text, 'dd-mm-yyyy'::text) AS fin
)
SELECT max((a.prenom::text || ' '::text) || COALESCE(a.nom_usage, a.nom_famille)::text) AS denomination,
max(a.sexe::text) AS genre,
CASE
WHEN max(acs.t_administratif::text) = 'O'::text THEN 'BIATSS'::text
WHEN max(acs.t_enseignant::text) = 'O'::text AND max(acs.t_chercheur::text) = 'O'::text THEN 'ENSEIGNANT-CHERCHEUR'::text
WHEN max(acs.t_enseignant::text) = 'O'::text THEN 'ENSEIGNANT'::text
WHEN max(acs.t_chercheur::text) = 'O'::text THEN 'CHERCHEUR'::text
ELSE NULL::text
END AS statut,
CASE
WHEN max(acs.t_titulaire::text) = 'O'::text THEN 'TITULAIRE'::text
WHEN max(acs.t_cdi::text) = 'O'::text THEN 'CDI'::text
WHEN max(acs.t_cdd::text) = 'O'::text THEN 'CDD'::text
ELSE NULL::text
END AS contrat,
CASE
WHEN max(niv2.id) = max(s.id) THEN max(niv2.libelle_court::text)
ELSE max((niv2.libelle_court::text || ' > '::text) || s.libelle_court::text)
END AS structure,
max(f.libelle::text) AS action,
max(fd.libelle::text) AS domaine,
CASE
WHEN max(fa.libelle::text) = 'Formations externes'::text THEN 'O'::text
ELSE 'N'::text
END AS stage_externe
FROM formation_inscription i
JOIN agent a ON i.agent_id::text = a.c_individu::text
JOIN agent_carriere_statut acs ON acs.agent_id::text = a.c_individu::text
JOIN agent_carriere_affectation aca ON aca.agent_id::text = a.c_individu::text
JOIN structure s ON aca.structure_id = s.id
JOIN structure niv2 ON s.niv2_id = niv2.id
JOIN formation_instance fi ON i.session_id = fi.id
JOIN formation_seance fs ON fi.id = fs.instance_id
JOIN formation f ON f.id = fi.formation_id
LEFT JOIN formation_axe fa ON fa.id = f.axe_id
LEFT JOIN formation_formation_domaine ffd ON f.id = ffd.formation_id
LEFT JOIN formation_domaine fd ON ffd.domaine_id = fd.id
JOIN periode p ON 1 = 1
WHERE i.liste::text = 'principale'::text AND i.histo_destruction IS NULL AND acs.d_debut <= p.debut AND (acs.d_fin IS NULL OR acs.d_fin >= p.fin) AND aca.date_debut <= p.debut AND (aca.date_fin IS NULL OR aca.date_fin >= p.fin) AND (fs.jour >= p.debut AND fs.jour <= p.fin OR fs.volume_debut >= p.debut AND fs.volume_fin <= p.fin)
GROUP BY i.id
\ No newline at end of file
SELECT i.id AS sessio_id,
max(f.libelle::text) AS libelle,
i.date_cloture_inscription AS cloture_inscription,
count(n.*) AS nb_inscription,
array_agg(concat(a.prenom, ' ', COALESCE(a.nom_famille, a.nom_famille))) AS liste
FROM formation_instance i
LEFT JOIN formation_session_etat e ON i.id = e.session_id
JOIN formation f ON i.formation_id = f.id
LEFT JOIN formation_inscription n ON i.id = n.session_id
LEFT JOIN agent a ON n.agent_id::text = a.c_individu::text
WHERE e.etat_id IS NULL
GROUP BY i.id
HAVING count(n.*) > 0
ORDER BY (max(f.libelle::text))
\ No newline at end of file
SELECT i.id AS inscription_id,
max(a.c_individu::text) AS agent_id,
concat(max(a.nom_usage::text), ' ', max(a.prenom::text)) AS agent,
max(s.id) AS session_id,
max(f.libelle::text) AS session_libelle
FROM formation_inscription i
LEFT JOIN formation_inscription_etat ie ON i.id = ie.inscription_id
JOIN agent a ON i.agent_id::text = a.c_individu::text
JOIN formation_instance s ON i.session_id = s.id
JOIN formation f ON s.formation_id = f.id
GROUP BY i.id
HAVING count(ie.etat_id) = 0
\ No newline at end of file
SELECT min(i.id) AS inscription_id,
concat(COALESCE(min(a.nom_usage::text), min(a.nom_famille::text)), ' ', min(a.prenom::text)) AS denomination,
min(f.libelle::text) AS formation,
min(t.libelle_court::text) AS structure,
min(t.id) AS perimetre_structure_id
FROM formation_inscription i
JOIN agent a ON i.agent_id::text = a.c_individu::text
JOIN formation_instance s ON i.session_id = s.id
JOIN formation f ON s.formation_id = f.id
JOIN formation_seance j ON j.instance_id = s.id
LEFT JOIN agent_carriere_affectation aca ON aca.agent_id::text = a.c_individu::text
LEFT JOIN structure t ON aca.structure_id = t.id
WHERE i.id IS NOT NULL AND (aca.date_debut IS NULL OR aca.date_debut < COALESCE(j.jour, j.volume_debut)) AND (aca.date_fin IS NULL OR aca.date_fin >= COALESCE(j.jour, j.volume_fin))
GROUP BY s.id
\ No newline at end of file
SELECT unicaen_utilisateur_user.id,
unicaen_utilisateur_user.username,
unicaen_utilisateur_user.display_name,
unicaen_utilisateur_user.email,
unicaen_utilisateur_user.password,
unicaen_utilisateur_user.state,
unicaen_utilisateur_user.password_reset_token,
unicaen_utilisateur_user.last_role_id
FROM unicaen_utilisateur_user
\ No newline at end of file
SELECT agent.c_individu,
agent.utilisateur_id,
agent.prenom,
agent.nom_usage,
agent.created_on,
agent.updated_on,
agent.deleted_on,
agent.octo_id,
agent.preecog_id,
agent.harp_id,
agent.login,
agent.email,
agent.sexe,
agent.t_contrat_long,
agent.date_naissance,
agent.nom_famille,
agent.id,
agent.histo_createur_id,
agent.histo_modificateur_id,
agent.histo_destructeur_id,
agent.source_id,
agent.id_orig
FROM agent
WHERE agent.utilisateur_id IS NOT NULL
\ No newline at end of file
SELECT a.c_individu AS agent_id,
concat(a.prenom, ' ', a.nom_usage) AS agent_denomination,
v.c_individu AS valideur_id,
concat(v.prenom, ' ', v.nom_usage) AS valideur_denomination,
ahv.date_debut AS debut,
ahv.date_fin AS fin,
ahv.source_id AS source
FROM agent_hierarchie_validateur ahv
JOIN agent a ON a.c_individu::text = ahv.agent_id::text
JOIN agent v ON v.c_individu::text = ahv.validateur_id::text
WHERE ahv.deleted_on IS NULL AND ahv.histo_destruction IS NULL AND ahv.date_debut < now() AND ahv.date_fin IS NULL OR ahv.date_fin > now()
\ No newline at end of file
SELECT max(a.c_individu::text) AS agent_id,
max(concat(a.prenom, ' ', COALESCE(a.nom_usage, a.nom_famille))) AS agent_denomination,
array_agg(s.id) AS structure_id,
array_agg(s.libelle_court) AS structure_libelle,
array_agg(s2.id) AS niv2_id,
array_agg(s2.libelle_court) AS niv2_libelle
FROM agent a
JOIN agent_carriere_affectation aa ON a.c_individu::text = aa.agent_id::text
JOIN agent_carriere_statut at ON a.c_individu::text = at.agent_id::text
JOIN structure s ON aa.structure_id = s.id
LEFT JOIN structure s2 ON s.niv2_id = s2.id
LEFT JOIN agent_hierarchie_validateur v ON a.c_individu::text = v.agent_id::text
WHERE v.* IS NULL AND v.deleted_on IS NULL AND v.histo_destruction IS NULL AND aa.deleted_on IS NULL AND aa.date_debut < now() AND (aa.date_fin IS NULL OR aa.date_fin > now()) AND at.deleted_on IS NULL AND at.d_debut < now() AND (at.d_fin IS NULL OR at.d_fin > now()) AND (at.t_enseignant::text = 'O'::text OR at.t_administratif::text = 'O'::text)
GROUP BY a.*
\ No newline at end of file
SELECT max(f.libelle::text) AS max,
array_agg(DISTINCT d.libelle) AS array_agg,
count(*) AS count
FROM formation_formation_abonnement ffa
JOIN formation f ON ffa.formation_id = f.id
JOIN formation_formation_domaine fd ON f.id = fd.formation_id
JOIN formation_domaine d ON d.id = fd.domaine_id
JOIN agent a ON ffa.agent_id::text = a.c_individu::text
WHERE ffa.histo_destruction IS NULL AND a.deleted_on IS NULL
GROUP BY f.id
ORDER BY (count(*))
\ No newline at end of file
SELECT a.c_individu AS agent_id,
(a.prenom::text || ' '::text) || COALESCE(a.nom_usage, a.nom_famille)::text AS agent_denomination,
f.libelle AS formation_libelle,
session.id AS session_id,
fi.histo_modification AS date,
fi.justification_desistement AS justification
FROM formation_inscription fi
JOIN formation_inscription_etat fie ON fi.id = fie.inscription_id
JOIN unicaen_etat_instance uei ON fie.etat_id = uei.id
JOIN unicaen_etat_type uet ON uei.type_id = uet.id
JOIN agent a ON fi.agent_id::text = a.c_individu::text
JOIN formation_instance session ON fi.session_id = session.id
JOIN formation f ON session.formation_id = f.id
WHERE uet.code::text = 'FORMATION_INSCRIPTION_DESISTEMENT'::text AND uei.histo_destruction IS NULL
\ No newline at end of file
......@@ -4,9 +4,9 @@
return [
'schema' => 'public',
'name' => 'agent_affectation_pk',
'name' => 'agent_carriere_affectation_pk',
'table' => 'agent_carriere_affectation',
'index' => 'agent_affectation_pk',
'index' => 'agent_carriere_affectation_pk',
'columns' => [
'id',
],
......
......@@ -4,9 +4,9 @@
return [
'schema' => 'public',
'name' => 'unicaen_privilege_categorie_pkey',
'name' => 'categorie_privilege_pkey',
'table' => 'unicaen_privilege_categorie',
'index' => 'unicaen_privilege_categorie_pkey',
'index' => 'categorie_privilege_pkey',
'columns' => [
'id',
],
......
......@@ -4,9 +4,9 @@
return [
'schema' => 'public',
'name' => 'carriere_emploitype_pk',
'name' => 'emploitype_pk',
'table' => 'carriere_emploitype',
'index' => 'carriere_emploitype_pk',
'index' => 'emploitype_pk',
'columns' => [
'id',
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment