Skip to content

Commit 6d21c1c

Browse files
authored
Merge pull request #7 from lpoaura/develop
v1.2.0
2 parents 9053eb7 + ca635fd commit 6d21c1c

25 files changed

+3449
-44727
lines changed

00_init_db.sql

Lines changed: 171 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
/*
2-
Child table with specific datas from:
3-
- VisioNature
4-
- dbChiroWeb
2+
INIT DB
3+
-------
4+
Generate extended data table to store specific datas not in GeoNature Synthese table.
5+
Adapted to store data from VisioNature and dbChiroWeb
56
*/
6-
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION gnadm;
77

8-
DROP TABLE IF EXISTS .t_c_synthese_extended;
98

10-
CREATE TABLE IF NOT EXISTS .t_c_synthese_extended
9+
BEGIN
10+
;
11+
12+
CREATE SCHEMA IF NOT EXISTS src_lpodatas
13+
;
14+
15+
DROP TABLE IF EXISTS src_lpodatas.t_c_synthese_extended
16+
;
17+
18+
CREATE TABLE IF NOT EXISTS src_lpodatas.t_c_synthese_extended
1119
(
1220
id_synthese INTEGER PRIMARY KEY REFERENCES gn_synthese.synthese (id_synthese),
1321
id_sp_source INTEGER,
1422
taxo_group VARCHAR(50),
1523
taxo_real BOOLEAN,
1624
common_name VARCHAR(250),
1725
pseudo_observer_uid VARCHAR(200),
26+
observers VARCHAR(200),
1827
bird_breed_code INTEGER,
1928
bird_breed_status VARCHAR(20),
2029
bat_breed_colo BOOLEAN,
@@ -36,42 +45,160 @@ CREATE TABLE IF NOT EXISTS .t_c_synthese_extended
3645
is_valid BOOLEAN,
3746
private_comment TEXT,
3847
is_hidden BOOLEAN DEFAULT FALSE
39-
);
40-
41-
COMMENT ON COLUMN .t_c_synthese_extended.id_sp_source IS 'Code espèce de la source (VisioNature/dbChiroWeb)';
42-
COMMENT ON COLUMN .t_c_synthese_extended.taxo_group IS 'Groupe taxonomique VisioNature';
43-
COMMENT ON COLUMN .t_c_synthese_extended.taxo_real IS 'True si Taxon Vrai';
44-
COMMENT ON COLUMN .t_c_synthese_extended.common_name IS 'Nom vernaculaire';
45-
COMMENT ON COLUMN .t_c_synthese_extended.pseudo_observer_uid IS 'Identifiant chiffré de l''Observateur pour anonymisation';
46-
COMMENT ON COLUMN .t_c_synthese_extended.bird_breed_code IS 'Codes "Biolovision" de nidification https://wiki.biolovision.net/Correspondance_codes_atlas';
47-
COMMENT ON COLUMN .t_c_synthese_extended.bird_breed_status IS 'Statut de nidification simplifié (Nicheur possible, probable, certain) d''après oiso_code_nidif';
48-
COMMENT ON COLUMN .t_c_synthese_extended.bat_breed_colo IS 'Colonie de reproduction de chauves-souris';
49-
COMMENT ON COLUMN .t_c_synthese_extended.bat_is_gite IS 'Gite à chauves-souris';
50-
COMMENT ON COLUMN .t_c_synthese_extended.bat_period IS 'Période du cycle annuel des chauves-souris (hivernage, transit printanier ou automnal, estivage)';
51-
COMMENT ON COLUMN .t_c_synthese_extended.estimation_code IS 'Code caractérisant le type d''estimation du comptage';
52-
COMMENT ON COLUMN .t_c_synthese_extended.date_year IS 'Année de l''observation';
53-
COMMENT ON COLUMN .t_c_synthese_extended.mortality IS 'Est une donnée de mortalité';
54-
COMMENT ON COLUMN .t_c_synthese_extended.mortality_cause IS 'Cause identifiée de la mortalité';
55-
COMMENT ON COLUMN .t_c_synthese_extended.export_excluded IS 'A exclure des exports';
56-
COMMENT ON COLUMN .t_c_synthese_extended.project_code IS 'Code étude';
57-
COMMENT ON COLUMN .t_c_synthese_extended.juridical_person IS 'Personne morale';
58-
COMMENT ON COLUMN .t_c_synthese_extended.behaviour IS 'Liste (format ARRAY) des comportements observés';
59-
COMMENT ON COLUMN .t_c_synthese_extended.geo_accuracy IS 'Précision géographique de la donnée';
60-
COMMENT ON COLUMN .t_c_synthese_extended.details IS 'Détails de la donnée (format JSON)';
61-
COMMENT ON COLUMN .t_c_synthese_extended.id_place IS 'Identifiant du lieu-dit';
62-
COMMENT ON COLUMN .t_c_synthese_extended.place IS 'Nom du Lieu-dit';
63-
COMMENT ON COLUMN .t_c_synthese_extended.id_form IS 'identifiant du formulaire';
64-
COMMENT ON COLUMN .t_c_synthese_extended.is_valid IS 'Donnée validée';
65-
COMMENT ON COLUMN .t_c_synthese_extended.private_comment IS 'Commentaire privé';
66-
COMMENT ON COLUMN .t_c_synthese_extended.is_hidden IS 'Donnée cachée';
67-
68-
CREATE INDEX i_t_c_synthese_extended_id_sp_source ON .t_c_synthese_extended (id_sp_source);
69-
CREATE INDEX i_t_c_synthese_extended_taxo_group ON .t_c_synthese_extended (taxo_group);
70-
CREATE INDEX i_t_c_synthese_extended_common_name ON .t_c_synthese_extended (common_name);
71-
CREATE INDEX i_t_c_synthese_extended_id_place ON .t_c_synthese_extended (id_place);
72-
CREATE INDEX i_t_c_synthese_extended_is_valid ON .t_c_synthese_extended (is_valid);
73-
CREATE INDEX i_t_c_synthese_extended_is_hidden ON .t_c_synthese_extended (is_hidden);
74-
CREATE INDEX i_t_c_synthese_extended_bird_breed_code_txt ON .t_c_synthese_extended (cast(bird_breed_code AS TEXT));
75-
CREATE INDEX i_t_c_synthese_extended_bird_breed_code ON .t_c_synthese_extended (bird_breed_code);
76-
CREATE INDEX i_t_c_synthese_extended_project_code ON .t_c_synthese_extended (project_code);
48+
)
49+
;
50+
51+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.id_sp_source IS 'Code espèce de la source (VisioNature/dbChiroWeb)'
52+
;
53+
54+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.taxo_group IS 'Groupe taxonomique VisioNature'
55+
;
56+
57+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.taxo_real IS 'True si Taxon Vrai'
58+
;
59+
60+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.common_name IS 'Nom vernaculaire'
61+
;
62+
63+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.pseudo_observer_uid IS 'Identifiant chiffré de l''Observateur pour anonymisation'
64+
;
65+
66+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.bird_breed_code IS 'Codes "Biolovision" de nidification https://wiki.biolovision.net/Correspondance_codes_atlas'
67+
;
68+
69+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.bird_breed_status IS 'Statut de nidification simplifié (Nicheur possible, probable, certain) d''après oiso_code_nidif'
70+
;
71+
72+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.bat_breed_colo IS 'Colonie de reproduction de chauves-souris'
73+
;
74+
75+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.bat_is_gite IS 'Gite à chauves-souris'
76+
;
77+
78+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.bat_period IS 'Période du cycle annuel des chauves-souris (hivernage, transit printanier ou automnal, estivage)'
79+
;
80+
81+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.estimation_code IS 'Code caractérisant le type d''estimation du comptage'
82+
;
83+
84+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.date_year IS 'Année de l''observation'
85+
;
86+
87+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.mortality IS 'Est une donnée de mortalité'
88+
;
89+
90+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.mortality_cause IS 'Cause identifiée de la mortalité'
91+
;
92+
93+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.export_excluded IS 'A exclure des exports'
94+
;
95+
96+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.project_code IS 'Code étude'
97+
;
98+
99+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.juridical_person IS 'Personne morale'
100+
;
101+
102+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.behaviour IS 'Liste (format ARRAY) des comportements observés'
103+
;
104+
105+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.geo_accuracy IS 'Précision géographique de la donnée'
106+
;
107+
108+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.details IS 'Détails de la donnée (format JSON)'
109+
;
110+
111+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.id_place IS 'Identifiant du lieu-dit'
112+
;
113+
114+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.place IS 'Nom du Lieu-dit'
115+
;
116+
117+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.id_form IS 'identifiant du formulaire'
118+
;
119+
120+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.is_valid IS 'Donnée validée'
121+
;
122+
123+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.private_comment IS 'Commentaire privé'
124+
;
125+
126+
COMMENT ON COLUMN src_lpodatas.t_c_synthese_extended.is_hidden IS 'Donnée cachée'
127+
;
128+
129+
CREATE INDEX i_t_c_synthese_extended_id_sp_source ON src_lpodatas.t_c_synthese_extended (id_sp_source)
130+
;
131+
132+
CREATE INDEX i_t_c_synthese_extended_taxo_group ON src_lpodatas.t_c_synthese_extended (taxo_group)
133+
;
134+
135+
CREATE INDEX i_t_c_synthese_extended_common_name ON src_lpodatas.t_c_synthese_extended (common_name)
136+
;
137+
138+
CREATE INDEX i_t_c_synthese_extended_id_place ON src_lpodatas.t_c_synthese_extended (id_place)
139+
;
140+
141+
CREATE INDEX i_t_c_synthese_extended_is_valid ON src_lpodatas.t_c_synthese_extended (is_valid)
142+
;
143+
144+
CREATE INDEX i_t_c_synthese_extended_is_hidden ON src_lpodatas.t_c_synthese_extended (is_hidden)
145+
;
146+
147+
CREATE INDEX i_t_c_synthese_extended_bird_breed_code_txt ON src_lpodatas.t_c_synthese_extended (cast(bird_breed_code AS TEXT))
148+
;
149+
150+
CREATE INDEX i_t_c_synthese_extended_bird_breed_code ON src_lpodatas.t_c_synthese_extended (bird_breed_code)
151+
;
152+
153+
CREATE INDEX i_t_c_synthese_extended_project_code ON src_lpodatas.t_c_synthese_extended (project_code)
154+
;
155+
156+
157+
CREATE TABLE src_lpodatas.t_c_rules_diffusion_level
158+
(
159+
id_rule_diffusion_level SERIAL PRIMARY KEY,
160+
cd_nom INT REFERENCES taxonomie.taxref,
161+
id_nomenclature_diffusion_level INTEGER
162+
CONSTRAINT fk_synthese_id_nomenclature_diffusion_level
163+
REFERENCES ref_nomenclatures.t_nomenclatures
164+
ON UPDATE CASCADE
165+
CONSTRAINT check_synthese_diffusion_level
166+
CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_diffusion_level,
167+
'NIV_PRECIS'::CHARACTER VARYING)),
168+
meta_create_date TIMESTAMP DEFAULT now(),
169+
meta_update_date TIMESTAMP DEFAULT now()
170+
)
171+
;
172+
173+
CREATE UNIQUE INDEX ON src_lpodatas.t_c_rules_diffusion_level (cd_nom, id_nomenclature_diffusion_level)
174+
;
175+
176+
COMMENT ON TABLE src_lpodatas.t_c_rules_diffusion_level IS 'Table de règle de niveau de diffusion par taxon'
177+
;
178+
179+
180+
CREATE TRIGGER tri_meta_dates_change_synthese
181+
BEFORE INSERT OR UPDATE
182+
ON src_lpodatas.t_c_rules_diffusion_level
183+
FOR EACH ROW
184+
EXECUTE PROCEDURE fct_trg_meta_dates_change()
185+
;
186+
187+
188+
INSERT INTO
189+
src_lpodatas.t_c_rules_diffusion_level(cd_nom, id_nomenclature_diffusion_level)
190+
SELECT
191+
cd_nom
192+
, ref_nomenclatures.get_id_nomenclature('NIV_PRECIS', '4')
193+
FROM
194+
taxonomie.taxref
195+
WHERE
196+
lb_nom IN ('Canis lupus', 'Lynx lynx')
197+
AND cd_nom = cd_ref
198+
;
199+
200+
CREATE UNIQUE INDEX ON src_lpodatas.t_c_rules_diffusion_level (cd_nom, id_nomenclature_diffusion_level)
201+
;
77202

203+
COMMIT
204+
;

01_nomenclatures.sql

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
NOMENCLATURES
3+
-------------
4+
Nomenclatures synonyms management.
5+
*/
6+
7+
BEGIN;
8+
19
DROP TABLE IF EXISTS ref_nomenclatures.t_c_synonyms CASCADE;
210

311
CREATE TABLE ref_nomenclatures.t_c_synonyms (
@@ -15,7 +23,7 @@ CREATE TABLE ref_nomenclatures.t_c_synonyms (
1523
id_source integer CONSTRAINT fk_t_synonymes_id_source REFERENCES gn_synthese.t_sources
1624
);
1725

18-
ALTER TABLE ref_nomenclatures.t_c_synonyms OWNER TO gnadm;
26+
ALTER TABLE ref_nomenclatures.t_c_synonyms OWNER TO geonatadmin;
1927

2028
COMMENT ON TABLE ref_nomenclatures.t_c_synonyms IS 'Table de correspondances des nomenclatures avec une source tierce';
2129

@@ -51,8 +59,6 @@ FROM
5159
JOIN ref_nomenclatures.t_nomenclatures ON t_c_synonyms.id_nomenclature = t_nomenclatures.id_nomenclature
5260
JOIN gn_synthese.t_sources ON t_c_synonyms.id_source = t_sources.id_source;
5361

54-
ALTER TABLE ref_nomenclatures.v_c_synonyms OWNER TO gnadm;
55-
5662

5763
/* Function permettant de retrouver l'id_nomenclature à partir des données VisioNature */
5864
DROP FUNCTION IF EXISTS ref_nomenclatures.fct_c_get_synonyms_nomenclature (_type CHARACTER VARYING, _value CHARACTER VARYING);
@@ -80,6 +86,6 @@ BEGIN
8086
END;
8187
$$;
8288

83-
ALTER FUNCTION ref_nomenclatures.fct_c_get_synonyms_nomenclature (_type CHARACTER VARYING, _value CHARACTER VARYING) OWNER TO gnadm;
84-
8589
COMMENT ON FUNCTION ref_nomenclatures.fct_c_get_synonyms_nomenclature (_type CHARACTER VARYING, _value CHARACTER VARYING) IS 'Fonction de recherche des id_nomenclatures'
90+
91+
COMMIT;

0 commit comments

Comments
 (0)