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

3.2 db patch adjustments #2031

Draft
wants to merge 3 commits into
base: Development
Choose a base branch
from
Draft
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
20 changes: 12 additions & 8 deletions config/schema/3.0/patches/db_schema_patch-3.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,20 @@ END$$
CREATE TRIGGER `omoccurrences_update` AFTER UPDATE ON `omoccurrences`
FOR EACH ROW BEGIN
IF NEW.`decimalLatitude` IS NOT NULL AND NEW.`decimalLongitude` IS NOT NULL THEN
IF EXISTS (SELECT `occid` FROM omoccurpoints WHERE `occid`=NEW.`occid`) THEN
UPDATE omoccurpoints
SET `point` = Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`)
WHERE `occid` = NEW.`occid`;
ELSE
INSERT INTO omoccurpoints (`occid`,`point`)
VALUES (NEW.`occid`,Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`));
IF OLD.`decimalLatitude` IS NULL OR (NEW.`decimalLatitude` != OLD.`decimalLatitude` AND NEW.`decimalLongitude` != OLD.`decimalLongitude`) THEN
IF EXISTS (SELECT `occid` FROM omoccurpoints WHERE `occid`=NEW.`occid`) THEN
UPDATE omoccurpoints
SET `point` = Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add this to update set section

, `lngLatPoint` = Point(NEW.`decimalLongitude`, NEW.`decimalLatitude`)

And Alter the insert to look like

INSERT INTO omoccurpoints (`occid`,`point`, `latLngPoint`) 
	VALUES (NEW.`occid`,Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`), Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`));

WHERE `occid` = NEW.`occid`;
ELSE
INSERT INTO omoccurpoints (`occid`,`point`)
VALUES (NEW.`occid`,Point(NEW.`decimalLatitude`, NEW.`decimalLongitude`));
END IF;
END IF;
ELSE
DELETE FROM omoccurpoints WHERE `occid` = NEW.`occid`;
IF OLD.`decimalLatitude` IS NOT NULL THEN
DELETE FROM omoccurpoints WHERE `occid` = NEW.`occid`;
END IF;
END IF;
END$$

Expand Down