From d81dc666fabfce0818daf2619fe5aac658d4394c Mon Sep 17 00:00:00 2001 From: Andria Capai Date: Mon, 20 Nov 2023 16:33:55 +0100 Subject: [PATCH] refact: use same way to replace review Use current way to replace view Reviewed-by: andriacap --- .../data/core/gn_synthese/__init__.py | 0 .../initial_v_synthese_for_web_app_v1.0.0.sql | 69 ------- ...hese_for_web_app_add_group_inpn_v1.0.2.sql | 73 ------- ...these_for_web_app_add_id_module_v1.0.1.sql | 72 ------- ...add_id_module_to_v_synthese_for_web_app.py | 183 ++++++++++++++++-- ...dd_column_group_inpn_to_v_synthese_for_.py | 176 +++++++++++++++-- 6 files changed, 327 insertions(+), 246 deletions(-) delete mode 100644 backend/geonature/migrations/data/core/gn_synthese/__init__.py delete mode 100644 backend/geonature/migrations/data/core/gn_synthese/initial_v_synthese_for_web_app_v1.0.0.sql delete mode 100644 backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_group_inpn_v1.0.2.sql delete mode 100644 backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_id_module_v1.0.1.sql diff --git a/backend/geonature/migrations/data/core/gn_synthese/__init__.py b/backend/geonature/migrations/data/core/gn_synthese/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/backend/geonature/migrations/data/core/gn_synthese/initial_v_synthese_for_web_app_v1.0.0.sql b/backend/geonature/migrations/data/core/gn_synthese/initial_v_synthese_for_web_app_v1.0.0.sql deleted file mode 100644 index 9476bb01b9..0000000000 --- a/backend/geonature/migrations/data/core/gn_synthese/initial_v_synthese_for_web_app_v1.0.0.sql +++ /dev/null @@ -1,69 +0,0 @@ -SELECT s.id_synthese, - s.unique_id_sinp, - s.unique_id_sinp_grp, - s.id_source, - s.entity_source_pk_value, - s.count_min, - s.count_max, - s.nom_cite, - s.meta_v_taxref, - s.sample_number_proof, - s.digital_proof, - s.non_digital_proof, - s.altitude_min, - s.altitude_max, - s.depth_min, - s.depth_max, - s.place_name, - s.precision, - s.the_geom_4326, - public.ST_asgeojson(the_geom_4326), - s.date_min, - s.date_max, - s.validator, - s.validation_comment, - s.observers, - s.id_digitiser, - s.determiner, - s.comment_context, - s.comment_description, - s.meta_validation_date, - s.meta_create_date, - s.meta_update_date, - s.last_action, - d.id_dataset, - d.dataset_name, - d.id_acquisition_framework, - s.id_nomenclature_geo_object_nature, - s.id_nomenclature_info_geo_type, - s.id_nomenclature_grp_typ, - s.grp_method, - s.id_nomenclature_obs_technique, - s.id_nomenclature_bio_status, - s.id_nomenclature_bio_condition, - s.id_nomenclature_naturalness, - s.id_nomenclature_exist_proof, - s.id_nomenclature_valid_status, - s.id_nomenclature_diffusion_level, - s.id_nomenclature_life_stage, - s.id_nomenclature_sex, - s.id_nomenclature_obj_count, - s.id_nomenclature_type_count, - s.id_nomenclature_sensitivity, - s.id_nomenclature_observation_status, - s.id_nomenclature_blurring, - s.id_nomenclature_source_status, - s.id_nomenclature_determination_method, - s.id_nomenclature_behaviour, - s.reference_biblio, - sources.name_source, - sources.url_source, - t.cd_nom, - t.cd_ref, - t.nom_valide, - t.lb_nom, - t.nom_vern -FROM gn_synthese.synthese s - JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom - JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset - JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; \ No newline at end of file diff --git a/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_group_inpn_v1.0.2.sql b/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_group_inpn_v1.0.2.sql deleted file mode 100644 index 20bcf4fc44..0000000000 --- a/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_group_inpn_v1.0.2.sql +++ /dev/null @@ -1,73 +0,0 @@ -SELECT s.id_synthese, - s.unique_id_sinp, - s.unique_id_sinp_grp, - s.id_source, - s.entity_source_pk_value, - s.count_min, - s.count_max, - s.nom_cite, - s.meta_v_taxref, - s.sample_number_proof, - s.digital_proof, - s.non_digital_proof, - s.altitude_min, - s.altitude_max, - s.depth_min, - s.depth_max, - s.place_name, - s."precision", - s.the_geom_4326, - st_asgeojson(s.the_geom_4326) AS st_asgeojson, - s.date_min, - s.date_max, - s.validator, - s.validation_comment, - s.observers, - s.id_digitiser, - s.determiner, - s.comment_context, - s.comment_description, - s.meta_validation_date, - s.meta_create_date, - s.meta_update_date, - s.last_action, - d.id_dataset, - d.dataset_name, - d.id_acquisition_framework, - s.id_nomenclature_geo_object_nature, - s.id_nomenclature_info_geo_type, - s.id_nomenclature_grp_typ, - s.grp_method, - s.id_nomenclature_obs_technique, - s.id_nomenclature_bio_status, - s.id_nomenclature_bio_condition, - s.id_nomenclature_naturalness, - s.id_nomenclature_exist_proof, - s.id_nomenclature_valid_status, - s.id_nomenclature_diffusion_level, - s.id_nomenclature_life_stage, - s.id_nomenclature_sex, - s.id_nomenclature_obj_count, - s.id_nomenclature_type_count, - s.id_nomenclature_sensitivity, - s.id_nomenclature_observation_status, - s.id_nomenclature_blurring, - s.id_nomenclature_source_status, - s.id_nomenclature_determination_method, - s.id_nomenclature_behaviour, - s.reference_biblio, - sources.name_source, - sources.url_source, - t.cd_nom, - t.cd_ref, - t.nom_valide, - t.lb_nom, - t.nom_vern, - s.id_module, - t.group1_inpn, - t.group2_inpn, - t.group3_inpn -FROM gn_synthese.synthese s - JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom - JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset - JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; \ No newline at end of file diff --git a/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_id_module_v1.0.1.sql b/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_id_module_v1.0.1.sql deleted file mode 100644 index 104d1b1308..0000000000 --- a/backend/geonature/migrations/data/core/gn_synthese/v_synthese_for_web_app_add_id_module_v1.0.1.sql +++ /dev/null @@ -1,72 +0,0 @@ --- DROP VIEW gn_synthese.v_synthese_for_web_app; --- CREATE OR REPLACE VIEW gn_synthese.v_synthese_for_web_app AS -SELECT s.id_synthese, - s.unique_id_sinp, - s.unique_id_sinp_grp, - s.id_source, - s.entity_source_pk_value, - s.count_min, - s.count_max, - s.nom_cite, - s.meta_v_taxref, - s.sample_number_proof, - s.digital_proof, - s.non_digital_proof, - s.altitude_min, - s.altitude_max, - s.depth_min, - s.depth_max, - s.place_name, - s.precision, - s.the_geom_4326, - public.ST_asgeojson(the_geom_4326), - s.date_min, - s.date_max, - s.validator, - s.validation_comment, - s.observers, - s.id_digitiser, - s.determiner, - s.comment_context, - s.comment_description, - s.meta_validation_date, - s.meta_create_date, - s.meta_update_date, - s.last_action, - d.id_dataset, - d.dataset_name, - d.id_acquisition_framework, - s.id_nomenclature_geo_object_nature, - s.id_nomenclature_info_geo_type, - s.id_nomenclature_grp_typ, - s.grp_method, - s.id_nomenclature_obs_technique, - s.id_nomenclature_bio_status, - s.id_nomenclature_bio_condition, - s.id_nomenclature_naturalness, - s.id_nomenclature_exist_proof, - s.id_nomenclature_valid_status, - s.id_nomenclature_diffusion_level, - s.id_nomenclature_life_stage, - s.id_nomenclature_sex, - s.id_nomenclature_obj_count, - s.id_nomenclature_type_count, - s.id_nomenclature_sensitivity, - s.id_nomenclature_observation_status, - s.id_nomenclature_blurring, - s.id_nomenclature_source_status, - s.id_nomenclature_determination_method, - s.id_nomenclature_behaviour, - s.reference_biblio, - sources.name_source, - sources.url_source, - t.cd_nom, - t.cd_ref, - t.nom_valide, - t.lb_nom, - t.nom_vern, - s.id_module -FROM gn_synthese.synthese s - JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom - JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset - JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; \ No newline at end of file diff --git a/backend/geonature/migrations/versions/446e902a14e7_add_id_module_to_v_synthese_for_web_app.py b/backend/geonature/migrations/versions/446e902a14e7_add_id_module_to_v_synthese_for_web_app.py index 43bf806f39..bbd8250046 100644 --- a/backend/geonature/migrations/versions/446e902a14e7_add_id_module_to_v_synthese_for_web_app.py +++ b/backend/geonature/migrations/versions/446e902a14e7_add_id_module_to_v_synthese_for_web_app.py @@ -5,11 +5,9 @@ Create Date: 2023-09-25 10:09:39.126531 """ -import importlib - from alembic import op -from sqlalchemy.sql import text -from geonature.utils import alembic_utils +import sqlalchemy as sa + # revision identifiers, used by Alembic. revision = "446e902a14e7" @@ -18,23 +16,168 @@ depends_on = None -view_name = "gn_synthese.v_synthese_for_web_app" - -path_synthese = "geonature.migrations.data.core.gn_synthese" -init_filename = "initial_v_synthese_for_web_app_v1.0.0.sql" -sql_text = text(importlib.resources.read_text(path_synthese, init_filename)) -v_synthese_for_web_app_init = alembic_utils.ReplaceableObject(view_name, sql_text) - -filename = "v_synthese_for_web_app_add_id_module_v1.0.1.sql" -sql_text = text(importlib.resources.read_text(path_synthese, filename)) -v_synthese_for_web_app = alembic_utils.ReplaceableObject(view_name, sql_text) - - def upgrade(): - op.drop_view(v_synthese_for_web_app_init) - op.create_view(v_synthese_for_web_app) + op.execute( + """ + DROP VIEW gn_synthese.v_synthese_for_web_app; + """ + ) + + op.execute( + """ + CREATE OR REPLACE VIEW gn_synthese.v_synthese_for_web_app AS + SELECT s.id_synthese, + s.unique_id_sinp, + s.unique_id_sinp_grp, + s.id_source, + s.entity_source_pk_value, + s.count_min, + s.count_max, + s.nom_cite, + s.meta_v_taxref, + s.sample_number_proof, + s.digital_proof, + s.non_digital_proof, + s.altitude_min, + s.altitude_max, + s.depth_min, + s.depth_max, + s.place_name, + s.precision, + s.the_geom_4326, + public.ST_asgeojson(the_geom_4326), + s.date_min, + s.date_max, + s.validator, + s.validation_comment, + s.observers, + s.id_digitiser, + s.determiner, + s.comment_context, + s.comment_description, + s.meta_validation_date, + s.meta_create_date, + s.meta_update_date, + s.last_action, + d.id_dataset, + d.dataset_name, + d.id_acquisition_framework, + s.id_nomenclature_geo_object_nature, + s.id_nomenclature_info_geo_type, + s.id_nomenclature_grp_typ, + s.grp_method, + s.id_nomenclature_obs_technique, + s.id_nomenclature_bio_status, + s.id_nomenclature_bio_condition, + s.id_nomenclature_naturalness, + s.id_nomenclature_exist_proof, + s.id_nomenclature_valid_status, + s.id_nomenclature_diffusion_level, + s.id_nomenclature_life_stage, + s.id_nomenclature_sex, + s.id_nomenclature_obj_count, + s.id_nomenclature_type_count, + s.id_nomenclature_sensitivity, + s.id_nomenclature_observation_status, + s.id_nomenclature_blurring, + s.id_nomenclature_source_status, + s.id_nomenclature_determination_method, + s.id_nomenclature_behaviour, + s.reference_biblio, + sources.name_source, + sources.url_source, + t.cd_nom, + t.cd_ref, + t.nom_valide, + t.lb_nom, + t.nom_vern, + s.id_module + FROM gn_synthese.synthese s + JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom + JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset + JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; + """ + ) def downgrade(): - op.drop_view(v_synthese_for_web_app) - op.create_view(v_synthese_for_web_app_init) + op.execute( + """ + DROP VIEW gn_synthese.v_synthese_for_web_app; + """ + ) + + op.execute( + """ + CREATE OR REPLACE VIEW gn_synthese.v_synthese_for_web_app AS + SELECT s.id_synthese, + s.unique_id_sinp, + s.unique_id_sinp_grp, + s.id_source, + s.entity_source_pk_value, + s.count_min, + s.count_max, + s.nom_cite, + s.meta_v_taxref, + s.sample_number_proof, + s.digital_proof, + s.non_digital_proof, + s.altitude_min, + s.altitude_max, + s.depth_min, + s.depth_max, + s.place_name, + s.precision, + s.the_geom_4326, + public.ST_asgeojson(the_geom_4326), + s.date_min, + s.date_max, + s.validator, + s.validation_comment, + s.observers, + s.id_digitiser, + s.determiner, + s.comment_context, + s.comment_description, + s.meta_validation_date, + s.meta_create_date, + s.meta_update_date, + s.last_action, + d.id_dataset, + d.dataset_name, + d.id_acquisition_framework, + s.id_nomenclature_geo_object_nature, + s.id_nomenclature_info_geo_type, + s.id_nomenclature_grp_typ, + s.grp_method, + s.id_nomenclature_obs_technique, + s.id_nomenclature_bio_status, + s.id_nomenclature_bio_condition, + s.id_nomenclature_naturalness, + s.id_nomenclature_exist_proof, + s.id_nomenclature_valid_status, + s.id_nomenclature_diffusion_level, + s.id_nomenclature_life_stage, + s.id_nomenclature_sex, + s.id_nomenclature_obj_count, + s.id_nomenclature_type_count, + s.id_nomenclature_sensitivity, + s.id_nomenclature_observation_status, + s.id_nomenclature_blurring, + s.id_nomenclature_source_status, + s.id_nomenclature_determination_method, + s.id_nomenclature_behaviour, + s.reference_biblio, + sources.name_source, + sources.url_source, + t.cd_nom, + t.cd_ref, + t.nom_valide, + t.lb_nom, + t.nom_vern + FROM gn_synthese.synthese s + JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom + JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset + JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; + """ + ) diff --git a/backend/geonature/migrations/versions/d99a7c22cc3c_add_column_group_inpn_to_v_synthese_for_.py b/backend/geonature/migrations/versions/d99a7c22cc3c_add_column_group_inpn_to_v_synthese_for_.py index edeffaaa05..6c69c2d288 100644 --- a/backend/geonature/migrations/versions/d99a7c22cc3c_add_column_group_inpn_to_v_synthese_for_.py +++ b/backend/geonature/migrations/versions/d99a7c22cc3c_add_column_group_inpn_to_v_synthese_for_.py @@ -18,19 +18,171 @@ depends_on = ("c4415009f164",) # Taxref v15 db structure -view_name = "gn_synthese.v_synthese_for_web_app" - -path_synthese = "geonature.migrations.data.core.gn_synthese" - - -filename = "v_synthese_for_web_app_add_group_inpn_v1.0.2.sql" -sql_text = text(importlib.resources.read_text(path_synthese, filename)) -v_synthese_for_web_app = alembic_utils.ReplaceableObject(view_name, sql_text) - - def upgrade(): - op.replace_view(v_synthese_for_web_app, replaces="446e902a14e7.v_synthese_for_web_app") + op.execute( + """ + DROP VIEW gn_synthese.v_synthese_for_web_app; + """ + ) + + op.execute( + """ + CREATE VIEW gn_synthese.v_synthese_for_web_app AS +SELECT s.id_synthese, + s.unique_id_sinp, + s.unique_id_sinp_grp, + s.id_source, + s.entity_source_pk_value, + s.count_min, + s.count_max, + s.nom_cite, + s.meta_v_taxref, + s.sample_number_proof, + s.digital_proof, + s.non_digital_proof, + s.altitude_min, + s.altitude_max, + s.depth_min, + s.depth_max, + s.place_name, + s."precision", + s.the_geom_4326, + st_asgeojson(s.the_geom_4326) AS st_asgeojson, + s.date_min, + s.date_max, + s.validator, + s.validation_comment, + s.observers, + s.id_digitiser, + s.determiner, + s.comment_context, + s.comment_description, + s.meta_validation_date, + s.meta_create_date, + s.meta_update_date, + s.last_action, + d.id_dataset, + d.dataset_name, + d.id_acquisition_framework, + s.id_nomenclature_geo_object_nature, + s.id_nomenclature_info_geo_type, + s.id_nomenclature_grp_typ, + s.grp_method, + s.id_nomenclature_obs_technique, + s.id_nomenclature_bio_status, + s.id_nomenclature_bio_condition, + s.id_nomenclature_naturalness, + s.id_nomenclature_exist_proof, + s.id_nomenclature_valid_status, + s.id_nomenclature_diffusion_level, + s.id_nomenclature_life_stage, + s.id_nomenclature_sex, + s.id_nomenclature_obj_count, + s.id_nomenclature_type_count, + s.id_nomenclature_sensitivity, + s.id_nomenclature_observation_status, + s.id_nomenclature_blurring, + s.id_nomenclature_source_status, + s.id_nomenclature_determination_method, + s.id_nomenclature_behaviour, + s.reference_biblio, + sources.name_source, + sources.url_source, + t.cd_nom, + t.cd_ref, + t.nom_valide, + t.lb_nom, + t.nom_vern, + s.id_module, + t.group1_inpn, + t.group2_inpn, + t.group3_inpn + FROM gn_synthese.synthese s + JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom + JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset + JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; + """ + ) def downgrade(): - op.replace_view(v_synthese_for_web_app, replace_with="446e902a14e7.v_synthese_for_web_app") + op.execute( + """ + DROP VIEW gn_synthese.v_synthese_for_web_app; + """ + ) + + op.execute( + """ + CREATE OR REPLACE VIEW gn_synthese.v_synthese_for_web_app AS +SELECT s.id_synthese, + s.unique_id_sinp, + s.unique_id_sinp_grp, + s.id_source, + s.entity_source_pk_value, + s.count_min, + s.count_max, + s.nom_cite, + s.meta_v_taxref, + s.sample_number_proof, + s.digital_proof, + s.non_digital_proof, + s.altitude_min, + s.altitude_max, + s.depth_min, + s.depth_max, + s.place_name, + s.precision, + s.the_geom_4326, + public.ST_asgeojson(the_geom_4326), + s.date_min, + s.date_max, + s.validator, + s.validation_comment, + s.observers, + s.id_digitiser, + s.determiner, + s.comment_context, + s.comment_description, + s.meta_validation_date, + s.meta_create_date, + s.meta_update_date, + s.last_action, + d.id_dataset, + d.dataset_name, + d.id_acquisition_framework, + s.id_nomenclature_geo_object_nature, + s.id_nomenclature_info_geo_type, + s.id_nomenclature_grp_typ, + s.grp_method, + s.id_nomenclature_obs_technique, + s.id_nomenclature_bio_status, + s.id_nomenclature_bio_condition, + s.id_nomenclature_naturalness, + s.id_nomenclature_exist_proof, + s.id_nomenclature_valid_status, + s.id_nomenclature_diffusion_level, + s.id_nomenclature_life_stage, + s.id_nomenclature_sex, + s.id_nomenclature_obj_count, + s.id_nomenclature_type_count, + s.id_nomenclature_sensitivity, + s.id_nomenclature_observation_status, + s.id_nomenclature_blurring, + s.id_nomenclature_source_status, + s.id_nomenclature_determination_method, + s.id_nomenclature_behaviour, + s.reference_biblio, + sources.name_source, + sources.url_source, + t.cd_nom, + t.cd_ref, + t.nom_valide, + t.lb_nom, + t.nom_vern, + s.id_module +FROM gn_synthese.synthese s + JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom + JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset + JOIN gn_synthese.t_sources sources ON sources.id_source = s.id_source; """ + )