Skip to content

Commit

Permalink
Fix/synchro on synthese (#288)
Browse files Browse the repository at this point in the history
* remove silented errors when insert in synthese 

* add migration for trigger delete in synthese
---------

Co-authored-by: amandine-sahl <[email protected]>
  • Loading branch information
TheoLechemia and amandine-sahl committed Jul 29, 2024
1 parent f1a2616 commit ae4ebc8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""trigger drop synthese monitoring
Revision ID: 7fbcdd93626a
Revises: f3413cccdfa8
Create Date: 2024-01-11 17:25:05.135068
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "7fbcdd93626a"
down_revision = "f3413cccdfa8"
branch_labels = None
depends_on = None


def upgrade():
op.execute(
"""
DROP TRIGGER IF EXISTS trg_delete_synthese_observations ON gn_monitoring.t_observations;
DROP FUNCTION IF EXISTS gn_synthese.fct_trg_delete_synthese_observations();
CREATE FUNCTION gn_synthese.fct_trg_delete_synthese_observations() RETURNS trigger AS $$
BEGIN
--Suppression des données dans la synthèse
DELETE FROM gn_synthese.synthese WHERE unique_id_sinp = OLD.uuid_observation;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_delete_synthese_observations AFTER DELETE ON gn_monitoring.t_observations
FOR EACH ROW EXECUTE PROCEDURE gn_synthese.fct_trg_delete_synthese_observations();
DROP TRIGGER IF EXISTS trg_delete_synthese_visits ON gn_monitoring.t_base_visits;
DROP FUNCTION IF EXISTS gn_synthese.fct_trg_delete_synthese_visits() CASCADE;
CREATE FUNCTION gn_synthese.fct_trg_delete_synthese_visits() RETURNS trigger AS $$
BEGIN
--Suppression des données dans la synthèse
DELETE FROM gn_synthese.synthese WHERE unique_id_sinp = OLD.uuid_base_visit;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_delete_synthese_visits AFTER DELETE ON gn_monitoring.t_base_visits
FOR EACH ROW EXECUTE PROCEDURE gn_synthese.fct_trg_delete_synthese_visits();
"""
)


def downgrade():
op.execute(
"""
DROP TRIGGER trg_delete_synthese_observations ON gn_monitoring.t_observations;
DROP FUNCTION gn_synthese.fct_trg_delete_synthese_observations();
DROP TRIGGER trg_delete_synthese_visits ON gn_monitoring.t_base_visits;
DROP FUNCTION gn_synthese.fct_trg_delete_synthese_visits();
"""
)
32 changes: 7 additions & 25 deletions backend/gn_module_monitoring/monitoring/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,13 @@ def process_synthese(self, process_module=False, limit=1000):
return

table_name = "v_synthese_{}".format(self._module_code)
try:
import_from_table(
"gn_monitoring",
table_name,
self.config_param("id_field_name"),
self.config_value("id_field_name"),
limit,
)
except ValueError as e:
# warning
log.warning(
"""Error in module monitoring, process_synthese.
Function import_from_table with parameters({}, {}, {}) raises the following error :
{}
""".format(
table_name,
self.config_param("id_field_name"),
self.config_value("id_field_name"),
e,
)
)
return {"message": "{}".format(e)}, 500
except Exception as e:
return {"message": "{}".format(e)}, 500

import_from_table(
"gn_monitoring",
table_name,
self.config_param("id_field_name"),
self.config_value("id_field_name"),
limit,
)
return True

def create_or_update(self, post_data):
Expand Down
32 changes: 0 additions & 32 deletions data/delete_synthese.sql

This file was deleted.

0 comments on commit ae4ebc8

Please sign in to comment.