-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix empty additional field on export
- Loading branch information
1 parent
88bc90e
commit 3806dbb
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
175 changes: 175 additions & 0 deletions
175
contrib/occtax/backend/occtax/migrations/b66d30f4e3d1_fix_additionnal_fields_emmpty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
"""fix additionnal fields emmpty | ||
Revision ID: b66d30f4e3d1 | ||
Revises: e170d1902137 | ||
Create Date: 2023-12-19 14:46:28.208303 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b66d30f4e3d1" | ||
down_revision = "e170d1902137" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute( | ||
""" | ||
CREATE OR REPLACE VIEW pr_occtax.v_export_occtax | ||
AS SELECT rel.unique_id_sinp_grp AS "idSINPRegroupement", | ||
ref_nomenclatures.get_cd_nomenclature(rel.id_nomenclature_grp_typ) AS "typGrp", | ||
rel.grp_method AS "methGrp", | ||
ccc.unique_id_sinp_occtax AS "permId", | ||
ccc.id_counting_occtax AS "idOrigine", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_observation_status) AS "statObs", | ||
occ.nom_cite AS "nomCite", | ||
to_char(rel.date_min, 'YYYY-MM-DD'::text) AS "dateDebut", | ||
to_char(rel.date_max, 'YYYY-MM-DD'::text) AS "dateFin", | ||
rel.hour_min AS "heureDebut", | ||
rel.hour_max AS "heureFin", | ||
rel.altitude_max AS "altMax", | ||
rel.altitude_min AS "altMin", | ||
rel.depth_min AS "profMin", | ||
rel.depth_max AS "profMax", | ||
occ.cd_nom AS "cdNom", | ||
tax.cd_ref AS "cdRef", | ||
ref_nomenclatures.get_nomenclature_label(d.id_nomenclature_data_origin) AS "dSPublique", | ||
d.unique_dataset_id AS "jddMetaId", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_source_status) AS "statSource", | ||
d.dataset_name AS "jddCode", | ||
d.unique_dataset_id AS "jddId", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_obs_technique) AS "obsTech", | ||
ref_nomenclatures.get_nomenclature_label(rel.id_nomenclature_tech_collect_campanule) AS "techCollect", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_bio_condition) AS "ocEtatBio", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_naturalness) AS "ocNat", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_sex) AS "ocSex", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_life_stage) AS "ocStade", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_bio_status) AS "ocStatBio", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_exist_proof) AS "preuveOui", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_determination_method) AS "ocMethDet", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_behaviour) AS "occComp", | ||
occ.digital_proof AS "preuvNum", | ||
occ.non_digital_proof AS "preuvNoNum", | ||
rel.comment AS "obsCtx", | ||
occ.comment AS "obsDescr", | ||
rel.unique_id_sinp_grp AS "permIdGrp", | ||
ccc.count_max AS "denbrMax", | ||
ccc.count_min AS "denbrMin", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_obj_count) AS "objDenbr", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_type_count) AS "typDenbr", | ||
COALESCE(string_agg(DISTINCT (r.nom_role::text || ' '::text) || r.prenom_role::text, ','::text), rel.observers_txt::text) AS "obsId", | ||
COALESCE(string_agg(DISTINCT o.nom_organisme::text, ','::text), 'NSP'::text) AS "obsNomOrg", | ||
COALESCE(occ.determiner, 'Inconnu'::character varying) AS "detId", | ||
ref_nomenclatures.get_nomenclature_label(rel.id_nomenclature_geo_object_nature) AS "natObjGeo", | ||
st_astext(rel.geom_4326) AS "WKT", | ||
tax.lb_nom AS "nomScienti", | ||
tax.nom_vern AS "nomVern", | ||
hab.lb_code AS "codeHab", | ||
hab.lb_hab_fr AS "nomHab", | ||
hab.cd_hab, | ||
rel.date_min, | ||
rel.date_max, | ||
rel.id_dataset, | ||
rel.id_releve_occtax, | ||
occ.id_occurrence_occtax, | ||
rel.id_digitiser, | ||
rel.geom_4326, | ||
rel.place_name AS "nomLieu", | ||
rel."precision", | ||
(COALESCE(rel.additional_fields, '{}'::jsonb) || COALESCE(occ.additional_fields, '{}'::jsonb)) || COALESCE(ccc.additional_fields, '{}'::jsonb) AS additional_data | ||
FROM pr_occtax.t_releves_occtax rel | ||
LEFT JOIN pr_occtax.t_occurrences_occtax occ ON rel.id_releve_occtax = occ.id_releve_occtax | ||
LEFT JOIN pr_occtax.cor_counting_occtax ccc ON ccc.id_occurrence_occtax = occ.id_occurrence_occtax | ||
LEFT JOIN taxonomie.taxref tax ON tax.cd_nom = occ.cd_nom | ||
LEFT JOIN gn_meta.t_datasets d ON d.id_dataset = rel.id_dataset | ||
LEFT JOIN pr_occtax.cor_role_releves_occtax cr ON cr.id_releve_occtax = rel.id_releve_occtax | ||
LEFT JOIN utilisateurs.t_roles r ON r.id_role = cr.id_role | ||
LEFT JOIN utilisateurs.bib_organismes o ON o.id_organisme = r.id_organisme | ||
LEFT JOIN ref_habitats.habref hab ON hab.cd_hab = rel.cd_hab | ||
GROUP BY ccc.id_counting_occtax, occ.id_occurrence_occtax, rel.id_releve_occtax, d.id_dataset, tax.cd_ref, tax.lb_nom, tax.nom_vern, hab.cd_hab, hab.lb_code, hab.lb_hab_fr; | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute( | ||
""" | ||
CREATE OR REPLACE VIEW pr_occtax.v_export_occtax | ||
AS SELECT rel.unique_id_sinp_grp AS "idSINPRegroupement", | ||
ref_nomenclatures.get_cd_nomenclature(rel.id_nomenclature_grp_typ) AS "typGrp", | ||
rel.grp_method AS "methGrp", | ||
ccc.unique_id_sinp_occtax AS "permId", | ||
ccc.id_counting_occtax AS "idOrigine", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_observation_status) AS "statObs", | ||
occ.nom_cite AS "nomCite", | ||
to_char(rel.date_min, 'YYYY-MM-DD'::text) AS "dateDebut", | ||
to_char(rel.date_max, 'YYYY-MM-DD'::text) AS "dateFin", | ||
rel.hour_min AS "heureDebut", | ||
rel.hour_max AS "heureFin", | ||
rel.altitude_max AS "altMax", | ||
rel.altitude_min AS "altMin", | ||
rel.depth_min AS "profMin", | ||
rel.depth_max AS "profMax", | ||
occ.cd_nom AS "cdNom", | ||
tax.cd_ref AS "cdRef", | ||
ref_nomenclatures.get_nomenclature_label(d.id_nomenclature_data_origin) AS "dSPublique", | ||
d.unique_dataset_id AS "jddMetaId", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_source_status) AS "statSource", | ||
d.dataset_name AS "jddCode", | ||
d.unique_dataset_id AS "jddId", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_obs_technique) AS "obsTech", | ||
ref_nomenclatures.get_nomenclature_label(rel.id_nomenclature_tech_collect_campanule) AS "techCollect", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_bio_condition) AS "ocEtatBio", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_naturalness) AS "ocNat", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_sex) AS "ocSex", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_life_stage) AS "ocStade", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_bio_status) AS "ocStatBio", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_exist_proof) AS "preuveOui", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_determination_method) AS "ocMethDet", | ||
ref_nomenclatures.get_nomenclature_label(occ.id_nomenclature_behaviour) AS "occComp", | ||
occ.digital_proof AS "preuvNum", | ||
occ.non_digital_proof AS "preuvNoNum", | ||
rel.comment AS "obsCtx", | ||
occ.comment AS "obsDescr", | ||
rel.unique_id_sinp_grp AS "permIdGrp", | ||
ccc.count_max AS "denbrMax", | ||
ccc.count_min AS "denbrMin", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_obj_count) AS "objDenbr", | ||
ref_nomenclatures.get_nomenclature_label(ccc.id_nomenclature_type_count) AS "typDenbr", | ||
COALESCE(string_agg(DISTINCT (r.nom_role::text || ' '::text) || r.prenom_role::text, ','::text), rel.observers_txt::text) AS "obsId", | ||
COALESCE(string_agg(DISTINCT o.nom_organisme::text, ','::text), 'NSP'::text) AS "obsNomOrg", | ||
COALESCE(occ.determiner, 'Inconnu'::character varying) AS "detId", | ||
ref_nomenclatures.get_nomenclature_label(rel.id_nomenclature_geo_object_nature) AS "natObjGeo", | ||
st_astext(rel.geom_4326) AS "WKT", | ||
tax.lb_nom AS "nomScienti", | ||
tax.nom_vern AS "nomVern", | ||
hab.lb_code AS "codeHab", | ||
hab.lb_hab_fr AS "nomHab", | ||
hab.cd_hab, | ||
rel.date_min, | ||
rel.date_max, | ||
rel.id_dataset, | ||
rel.id_releve_occtax, | ||
occ.id_occurrence_occtax, | ||
rel.id_digitiser, | ||
rel.geom_4326, | ||
rel.place_name AS "nomLieu", | ||
rel."precision", | ||
(occ.additional_fields || rel.additional_fields) || ccc.additional_fields AS additional_data | ||
FROM pr_occtax.t_releves_occtax rel | ||
LEFT JOIN pr_occtax.t_occurrences_occtax occ ON rel.id_releve_occtax = occ.id_releve_occtax | ||
LEFT JOIN pr_occtax.cor_counting_occtax ccc ON ccc.id_occurrence_occtax = occ.id_occurrence_occtax | ||
LEFT JOIN taxonomie.taxref tax ON tax.cd_nom = occ.cd_nom | ||
LEFT JOIN gn_meta.t_datasets d ON d.id_dataset = rel.id_dataset | ||
LEFT JOIN pr_occtax.cor_role_releves_occtax cr ON cr.id_releve_occtax = rel.id_releve_occtax | ||
LEFT JOIN utilisateurs.t_roles r ON r.id_role = cr.id_role | ||
LEFT JOIN utilisateurs.bib_organismes o ON o.id_organisme = r.id_organisme | ||
LEFT JOIN ref_habitats.habref hab ON hab.cd_hab = rel.cd_hab | ||
GROUP BY ccc.id_counting_occtax, occ.id_occurrence_occtax, rel.id_releve_occtax, d.id_dataset, tax.cd_ref, tax.lb_nom, tax.nom_vern, hab.cd_hab, hab.lb_code, hab.lb_hab_fr; | ||
""" | ||
) |