-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat!: add location #114
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
Merged
Merged
feat!: add location #114
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cdb8ed9
feat(location): add location data
sthelemann 897c7c0
Merge branch 'master' into feat/gps-coordinates
dargmuesli 6a75845
refactor(location): cleanup
dargmuesli b1cd432
Merge remote-tracking branch 'maevsi/beta' into feat/gps-coordinates
sthelemann db84b7b
feat(location): make use of PostGIS extension
sthelemann 65198bb
feat(location): grant execute permissions on postgis functions
dargmuesli 9e29604
feat(location): switch to geography
dargmuesli 7815eea
Merge branch 'beta' into t
dargmuesli fc87b97
chore(location): remove table
dargmuesli 0bc2686
fix(postgis): correct execution grant
dargmuesli 7091a2e
feat(location): add verifications for indexes
sthelemann b60511e
Merge branch 'beta' into feat/gps-coordinates
dargmuesli c8f1a9f
refactor: work in feedback
dargmuesli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,7 @@ | ||
| BEGIN; | ||
|
|
||
| CREATE INDEX idx_account_private_location ON maevsi_private.account USING GIST (location); | ||
|
|
||
| COMMENT ON INDEX maevsi_private.idx_account_private_location IS 'Spatial index on column location in maevsi_private.account.'; | ||
|
|
||
| COMMIT; |
This file contains hidden or 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,7 @@ | ||
| BEGIN; | ||
|
|
||
| CREATE INDEX idx_event_location ON maevsi.event USING GIST (location_geography); | ||
|
|
||
| COMMENT ON INDEX maevsi.idx_event_location IS 'Spatial index on column location in maevsi.event.'; | ||
|
|
||
| COMMIT; |
This file contains hidden or 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 hidden or 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 hidden or 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,162 @@ | ||
| BEGIN; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.account_filter_radius_event( | ||
| _event_id UUID, | ||
| _distance_max DOUBLE PRECISION | ||
| ) | ||
| RETURNS TABLE ( | ||
| account_id UUID, | ||
| distance DOUBLE PRECISION | ||
| ) AS $$ | ||
| BEGIN | ||
| RETURN QUERY | ||
| WITH event AS ( | ||
| SELECT location_geography | ||
| FROM maevsi.event | ||
| WHERE id = _event_id | ||
| ) | ||
| SELECT | ||
| a.id AS account_id, | ||
| ST_Distance(e.location_geography, a.location) AS distance | ||
| FROM | ||
| event e, | ||
| maevsi_private.account a | ||
| WHERE | ||
| ST_DWithin(e.location_geography, a.location, _distance_max * 1000); | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT STABLE SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.account_filter_radius_event(UUID, DOUBLE PRECISION) IS 'Returns account locations within a given radius around the location of an event.'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.account_filter_radius_event(UUID, DOUBLE PRECISION) TO maevsi_account; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.event_filter_radius_account( | ||
| _account_id UUID, | ||
| _distance_max DOUBLE PRECISION | ||
| ) | ||
| RETURNS TABLE ( | ||
| event_id UUID, | ||
| distance DOUBLE PRECISION | ||
| ) AS $$ | ||
| BEGIN | ||
| RETURN QUERY | ||
| WITH account AS ( | ||
| SELECT location | ||
| FROM maevsi_private.account | ||
| WHERE id = _account_id | ||
| ) | ||
| SELECT | ||
| e.id AS event_id, | ||
| ST_Distance(a.location, e.location_geography) AS distance | ||
| FROM | ||
| account a, | ||
| maevsi.event e | ||
| WHERE | ||
| ST_DWithin(a.location, e.location_geography, _distance_max * 1000); | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT STABLE SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.event_filter_radius_account(UUID, DOUBLE PRECISION) IS 'Returns event locations within a given radius around the location of an account.'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.event_filter_radius_account(UUID, DOUBLE PRECISION) TO maevsi_account; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.account_location_update( | ||
| _account_id UUID, | ||
| _latitude DOUBLE PRECISION, | ||
| _longitude DOUBLE PRECISION | ||
| ) | ||
| RETURNS VOID AS $$ | ||
| BEGIN | ||
| UPDATE maevsi_private.account | ||
| SET | ||
| location = ST_Point(_longitude, _latitude, 4326) | ||
| WHERE | ||
| id = _account_id; | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.account_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION) IS 'Updates an account''s location based on latitude and longitude (GPS coordinates).'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.account_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION) TO maevsi_account; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.event_location_update( | ||
| _event_id UUID, | ||
| _latitude DOUBLE PRECISION, | ||
| _longitude DOUBLE PRECISION | ||
| ) | ||
| RETURNS VOID AS $$ | ||
| BEGIN | ||
| UPDATE maevsi.event | ||
| SET | ||
| location_geography = ST_Point(_longitude, _latitude, 4326) | ||
| WHERE | ||
| id = _event_id; | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.event_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION) IS 'Updates an event''s location based on latitude and longitude (GPS coordinates).'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.event_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION) TO maevsi_account; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.account_location_coordinates( | ||
| _account_id UUID | ||
| ) | ||
| RETURNS DOUBLE PRECISION[] AS $$ | ||
| DECLARE | ||
| _latitude DOUBLE PRECISION; | ||
| _longitude DOUBLE PRECISION; | ||
| BEGIN | ||
| SELECT | ||
| ST_Y(location::geometry), | ||
| ST_X(location::geometry) | ||
| INTO | ||
| _latitude, | ||
| _longitude | ||
| FROM | ||
| maevsi_private.account | ||
| WHERE | ||
| id = _account_id; | ||
|
|
||
| RETURN ARRAY[_latitude, _longitude]; | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT STABLE SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.account_location_coordinates(UUID) IS 'Returns an array with latitude and longitude of the account''s current location data'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.account_location_coordinates(UUID) TO maevsi_account; | ||
|
|
||
|
|
||
| CREATE FUNCTION maevsi.event_location_coordinates( | ||
| _event_id UUID | ||
| ) | ||
| RETURNS DOUBLE PRECISION[] AS $$ | ||
| DECLARE | ||
| _latitude DOUBLE PRECISION; | ||
| _longitude DOUBLE PRECISION; | ||
| BEGIN | ||
| SELECT | ||
| ST_Y(location_geography::geometry), | ||
| ST_X(location_geography::geometry) | ||
| INTO | ||
| _latitude, | ||
| _longitude | ||
| FROM | ||
| maevsi.event | ||
| WHERE | ||
| id = _event_id; | ||
|
|
||
| RETURN ARRAY[_latitude, _longitude]; | ||
| END; | ||
| $$ LANGUAGE PLPGSQL STRICT STABLE SECURITY DEFINER; | ||
|
|
||
| COMMENT ON FUNCTION maevsi.event_location_coordinates(UUID) IS 'Returns an array with latitude and longitude of the event''s current location data.'; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION maevsi.event_location_coordinates(UUID) TO maevsi_account; | ||
|
|
||
|
|
||
| COMMIT; |
This file contains hidden or 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,5 +1,16 @@ | ||
| BEGIN; | ||
|
|
||
| REVOKE EXECUTE ON FUNCTION | ||
| st_srid(geography), | ||
| st_geomfromgeojson(text), | ||
| st_coorddim(geometry), | ||
| st_asgeojson(geography, integer, integer), | ||
| postgis_type_name(character varying, integer, boolean), | ||
| geometrytype(geography), | ||
| geometry(text), | ||
| geography(geometry) | ||
| FROM maevsi_anonymous, maevsi_account; | ||
|
|
||
| DROP EXTENSION postgis; | ||
|
|
||
| COMMIT; |
This file contains hidden or 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,5 @@ | ||
| BEGIN; | ||
|
|
||
| DROP INDEX maevsi_private.idx_account_private_location; | ||
|
|
||
| COMMIT; |
This file contains hidden or 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,5 @@ | ||
| BEGIN; | ||
|
|
||
| DROP INDEX maevsi.idx_event_location; | ||
|
|
||
| COMMIT; |
This file contains hidden or 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,12 @@ | ||
| BEGIN; | ||
|
|
||
| DROP FUNCTION maevsi.account_filter_radius_event(UUID, DOUBLE PRECISION); | ||
| DROP FUNCTION maevsi.event_filter_radius_account(UUID, DOUBLE PRECISION); | ||
|
|
||
| DROP FUNCTION maevsi.account_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION); | ||
| DROP FUNCTION maevsi.event_location_update(UUID, DOUBLE PRECISION, DOUBLE PRECISION); | ||
|
|
||
| DROP FUNCTION maevsi.account_location_coordinates(UUID); | ||
| DROP FUNCTION maevsi.event_location_coordinates(UUID); | ||
|
|
||
| COMMIT; |
This file contains hidden or 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 hidden or 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,6 +1,33 @@ | ||
| BEGIN; | ||
|
|
||
| SELECT 1/count(*) FROM pg_extension WHERE extname = 'postgis'; | ||
| SELECT has_function_privilege('public.ST_DWithin(public.geometry, public.geometry, double precision)', 'EXECUTE'); | ||
| SELECT has_function_privilege('ST_DWithin(geometry, geometry, double precision)', 'EXECUTE'); | ||
|
|
||
| SAVEPOINT function_privileges_for_roles; | ||
| DO $$ | ||
| DECLARE | ||
| functions TEXT[] := ARRAY[ | ||
| 'geography(geometry)', | ||
| 'geometry(TEXT)', | ||
| 'geometrytype(GEOGRAPHY)', | ||
| 'postgis_type_name(CHARACTER VARYING, INTEGER, BOOLEAN)', | ||
| 'st_asgeojson(GEOGRAPHY, INTEGER, INTEGER)', | ||
| 'st_coorddim(GEOMETRY)', | ||
| 'st_geomfromgeojson(TEXT)', | ||
| 'st_srid(GEOGRAPHY)' | ||
| ]; | ||
| roles TEXT[] := ARRAY['maevsi_account', 'maevsi_anonymous']; | ||
| function TEXT; | ||
| role TEXT; | ||
| BEGIN | ||
| FOREACH role IN ARRAY roles LOOP | ||
| FOREACH function IN ARRAY functions LOOP | ||
| IF NOT (SELECT pg_catalog.has_function_privilege(role, function, 'EXECUTE')) THEN | ||
| RAISE EXCEPTION 'Test function_privileges_for_roles failed: % does not have EXECUTE privilege on function %', role, function; | ||
| END IF; | ||
| END LOOP; | ||
| END LOOP; | ||
| END $$; | ||
| ROLLBACK TO SAVEPOINT function_privileges_for_roles; | ||
|
|
||
| ROLLBACK; |
This file contains hidden or 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,9 @@ | ||
| BEGIN; | ||
|
|
||
| SELECT 1/COUNT(*) | ||
| FROM pg_class c | ||
| JOIN pg_namespace n ON n.oid = c.relnamespace | ||
| WHERE c.relname = 'idx_account_private_location' | ||
| AND n.nspname = 'maevsi_private'; | ||
|
|
||
| ROLLBACK; |
This file contains hidden or 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,9 @@ | ||
| BEGIN; | ||
|
|
||
| SELECT 1/COUNT(*) | ||
| FROM pg_class c | ||
| JOIN pg_namespace n ON n.oid = c.relnamespace | ||
| WHERE c.relname = 'idx_event_location' | ||
| AND n.nspname = 'maevsi'; | ||
|
|
||
| ROLLBACK; |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ SELECT id, | |
| is_in_person, | ||
| is_remote, | ||
| location, | ||
| location_geography, | ||
| name, | ||
| slug, | ||
| start, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.