-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updtae trigger * update * test_migration update * Update function trigger calcul_point_voie * Adding tests * test_migration update * Apply suggestions from code review Co-authored-by: rldhont <rldhont@gmail.com> * test_migration update * 0.5.0 Co-authored-by: rldhont <rldhont@gmail.com>
- Loading branch information
Showing
5 changed files
with
104 additions
and
2 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
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
43 changes: 43 additions & 0 deletions
43
gestion_base_adresse/install/sql/upgrade/upgrade_to_0.5.0.sql
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,43 @@ | ||
BEGIN; | ||
|
||
CREATE OR REPLACE FUNCTION adresse.calcul_point_voie() RETURNS trigger | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
nb integer; | ||
BEGIN | ||
IF TG_OP = 'DELETE' THEN | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; | ||
ELSIF TG_OP = 'INSERT' THEN | ||
IF NEW.id_voie IS NOT NULL THEN | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; | ||
END IF; | ||
ELSIF TG_OP = 'UPDATE' AND NEW.id_voie IS DISTINCT FROM OLD.id_voie THEN | ||
IF NEW.id_voie IS NULL THEN | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; | ||
ELSIF OLD.id_voie IS NULL THEN | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; | ||
ELSE | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = NEW.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = NEW.id_voie; | ||
SELECT COUNT(id_point) into nb FROM adresse.point_adresse WHERE id_voie = OLD.id_voie; | ||
UPDATE adresse.voie SET nb_point = nb WHERE id_voie = OLD.id_voie; | ||
END IF; | ||
END IF; | ||
|
||
RETURN NEW; | ||
END; | ||
$$; | ||
|
||
DROP TRIGGER IF EXISTS nb_point ON adresse.point_adresse; | ||
CREATE TRIGGER nb_point | ||
AFTER INSERT OR UPDATE | ||
ON adresse.point_adresse | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE adresse.calcul_point_voie(); | ||
|
||
COMMIT; |
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