Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GeoNature 2.14] fix errors in sample data #60

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/gn_module_zh/migrations/b4e1775f1e7c_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ def upgrade():


def downgrade():
pass
data = text(
importlib.resources.read_text("gn_module_zh.migrations.data", "delete_fake_data.sql")
)
op.get_bind().execute(data)
19 changes: 19 additions & 0 deletions backend/gn_module_zh/migrations/data/delete_fake_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN;

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;


DELETE FROM pr_zh.cor_zh_notes WHERE cor_rule_id > 1000000;
DELETE FROM pr_zh.t_items WHERE val_id > 1000000;
DELETE FROM pr_zh.cor_rb_rules WHERE rb_id > 1000000;

DELETE FROM pr_zh.cor_zh_rb WHERE id_rb > 1000000;
DELETE FROM pr_zh.t_river_basin WHERE id_rb > 1000000;
DELETE FROM pr_zh.t_hydro_area WHERE id_hydro > 1000000;

COMMIT;
281 changes: 124 additions & 157 deletions backend/gn_module_zh/migrations/data/insert_into_fake_data.sql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1435,5 +1435,21 @@ INSERT INTO pr_zh.cor_rule_nomenc VALUES
((SELECT rule_id FROM pr_zh.t_rules WHERE abbreviation = 'status'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'STATUT_PROTECTION') AND cd_nomenclature = '97'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY') AND cd_nomenclature = 'faible')),
((SELECT rule_id FROM pr_zh.t_rules WHERE abbreviation = 'status'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'STATUT_PROTECTION') AND cd_nomenclature = '98'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY') AND cd_nomenclature = 'faible')),
((SELECT rule_id FROM pr_zh.t_rules WHERE abbreviation = 'status'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'STATUT_PROTECTION') AND cd_nomenclature = '99'), (SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY') AND cd_nomenclature = 'faible'));


-- insert min and max values for rules which need quantifications
INSERT INTO pr_zh.cor_item_value VALUES
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = 'Aucun' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 0, 0),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '1 ou 2' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 1, 2),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '3 à 5' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 3, 5),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '>5' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 6, 999999999),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '1 à 4' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 1, 4),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '5 à 7' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 5, 7),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '8 ou 9' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 8, 9),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '>9' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 10, 999999999),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '1' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 1, 1),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '2' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 2, 2),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '3' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 3, 3),
((SELECT id_nomenclature FROM ref_nomenclatures.t_nomenclatures WHERE mnemonique = '>3' and id_type = (SELECT id_type FROM ref_nomenclatures.bib_nomenclatures_types WHERE mnemonique = 'HIERARCHY')), 4, 999999999);


COMMIT;
Loading