-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1712 from PnX-SI/hotfixes
Release 2.9.2
- Loading branch information
Showing
13 changed files
with
828 additions
and
89 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1 @@ | ||
2.9.1 | ||
2.9.2 |
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
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
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,14 @@ | ||
import click | ||
from flask import Blueprint, current_app | ||
|
||
from geonature.utils.env import db | ||
|
||
|
||
routes = Blueprint("sensitivity", __name__) | ||
|
||
|
||
@routes.cli.command() | ||
def update_synthese(): | ||
count = db.session.execute("SELECT gn_synthese.update_sensitivity()").scalar() | ||
db.session.commit() | ||
click.echo(f"Sensitivity updated for {count} rows") |
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
69 changes: 69 additions & 0 deletions
69
backend/geonature/migrations/versions/61e46813d621_update_synthese_sensitivity.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,69 @@ | ||
"""Update synthese sensitivity | ||
Revision ID: 61e46813d621 | ||
Revises: dde31e76ce45 | ||
Create Date: 2022-02-15 15:23:08.732729 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '61e46813d621' | ||
down_revision = 'dde31e76ce45' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute(""" | ||
CREATE OR REPLACE FUNCTION gn_synthese.update_sensitivity() | ||
RETURNS int4 | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
DECLARE | ||
affected_rows_count int; | ||
BEGIN | ||
WITH cte AS ( | ||
SELECT | ||
id_synthese, | ||
id_nomenclature_sensitivity AS old_sensitivity, | ||
gn_sensitivity.get_id_nomenclature_sensitivity( | ||
date_min::date, | ||
taxonomie.find_cdref(cd_nom), | ||
the_geom_local, | ||
jsonb_build_object( | ||
'STATUT_BIO', id_nomenclature_bio_status, | ||
'OCC_COMPORTEMENT', id_nomenclature_behaviour | ||
) | ||
) AS new_sensitivity | ||
FROM | ||
gn_synthese.synthese | ||
WHERE | ||
id_nomenclature_sensitivity != ref_nomenclatures.get_id_nomenclature('SENSIBILITE', '0') -- non sensible | ||
OR | ||
taxonomie.find_cdref(cd_nom) IN (SELECT DISTINCT cd_ref FROM gn_sensitivity.t_sensitivity_rules_cd_ref) | ||
) | ||
UPDATE | ||
gn_synthese.synthese s | ||
SET | ||
id_nomenclature_sensitivity = new_sensitivity | ||
FROM | ||
cte | ||
WHERE | ||
s.id_synthese = cte.id_synthese | ||
AND | ||
old_sensitivity != new_sensitivity; | ||
GET DIAGNOSTICS affected_rows_count = ROW_COUNT; | ||
RETURN affected_rows_count; | ||
END; | ||
$function$ | ||
; | ||
""") | ||
|
||
|
||
def downgrade(): | ||
op.execute(""" | ||
DROP FUNCTION gn_synthese.update_sensitivity; | ||
""") |
Oops, something went wrong.