Skip to content

Commit

Permalink
Fix upgrade path to not require postgis, at this point we should prob…
Browse files Browse the repository at this point in the history
…ably consider removing some of the oldest upgrades
  • Loading branch information
zachasme committed Sep 20, 2022
1 parent 419c9af commit 75d5860
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 72 deletions.
1 change: 0 additions & 1 deletion .github/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ elif [ "$CMD" = "pgxn-v3" ]; then
else
ARGS="$@"
make install
su postgres -p -c "psql -c 'CREATE EXTENSION postgis'"
su postgres -p -c "$ARGS"
fi
70 changes: 35 additions & 35 deletions h3/sql/updates/h3--0.2.0--0.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,47 @@ CREATE OR REPLACE FUNCTION h3_h3_to_children_slow(index h3index, resolution inte
'Slower version of H3ToChildren but allocates less memory';

-- PostGIS
CREATE OR REPLACE FUNCTION h3_geo_to_h3(geometry, resolution integer) RETURNS h3index
AS $$ SELECT h3_geo_to_h3($1::point, $2); $$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_geo_to_h3(geography, resolution integer) RETURNS h3index
AS $$ SELECT h3_geo_to_h3($1::geometry, $2); $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_geo_to_h3(geometry, resolution integer) RETURNS h3index
-- AS $$ SELECT h3_geo_to_h3($1::point, $2); $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_geo_to_h3(geography, resolution integer) RETURNS h3index
-- AS $$ SELECT h3_geo_to_h3($1::geometry, $2); $$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION h3_h3_to_geometry(h3index) RETURNS geometry
AS $$ SELECT ST_SetSRID(h3_h3_to_geo($1)::geometry, 4326) $$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_h3_to_geography(h3index) RETURNS geography
AS $$ SELECT h3_h3_to_geometry($1)::geography $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geometry(h3index) RETURNS geometry
-- AS $$ SELECT ST_SetSRID(h3_h3_to_geo($1)::geometry, 4326) $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geography(h3index) RETURNS geography
-- AS $$ SELECT h3_h3_to_geometry($1)::geography $$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geometry(h3index) RETURNS geometry
AS $$ SELECT ST_SetSRID(h3_h3_to_geo_boundary($1)::geometry, 4326) $$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geography(h3index) RETURNS geography
AS $$ SELECT h3_h3_to_geo_boundary_geometry($1)::geography $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geometry(h3index) RETURNS geometry
-- AS $$ SELECT ST_SetSRID(h3_h3_to_geo_boundary($1)::geometry, 4326) $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geography(h3index) RETURNS geography
-- AS $$ SELECT h3_h3_to_geo_boundary_geometry($1)::geography $$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION h3_polyfill(multi geometry, resolution integer) RETURNS SETOF h3index
AS $$ SELECT h3_polyfill(exterior, holes, resolution) FROM (
SELECT
-- extract exterior ring of each polygon
ST_MakePolygon(ST_ExteriorRing(poly))::polygon exterior,
-- extract holes of each polygon
(SELECT array_agg(hole)
FROM (
SELECT ST_MakePolygon(ST_InteriorRingN(
poly,
generate_series(1, ST_NumInteriorRings(poly))
))::polygon AS hole
) q_hole
) holes
-- extract single polygons from multipolygon
FROM (
select (st_dump(multi)).geom as poly
) q_poly GROUP BY poly
) h3_polyfill; $$ LANGUAGE SQL IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION h3_polyfill(multi geography, resolution integer) RETURNS SETOF h3index
AS $$ SELECT h3_polyfill($1::geometry, $2) $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_polyfill(multi geometry, resolution integer) RETURNS SETOF h3index
-- AS $$ SELECT h3_polyfill(exterior, holes, resolution) FROM (
-- SELECT
-- -- extract exterior ring of each polygon
-- ST_MakePolygon(ST_ExteriorRing(poly))::polygon exterior,
-- -- extract holes of each polygon
-- (SELECT array_agg(hole)
-- FROM (
-- SELECT ST_MakePolygon(ST_InteriorRingN(
-- poly,
-- generate_series(1, ST_NumInteriorRings(poly))
-- ))::polygon AS hole
-- ) q_hole
-- ) holes
-- -- extract single polygons from multipolygon
-- FROM (
-- select (st_dump(multi)).geom as poly
-- ) q_poly GROUP BY poly
-- ) h3_polyfill; $$ LANGUAGE SQL IMMUTABLE STRICT;
--CREATE OR REPLACE FUNCTION h3_polyfill(multi geography, resolution integer) RETURNS SETOF h3index
--AS $$ SELECT h3_polyfill($1::geometry, $2) $$ LANGUAGE SQL;

-- Type casts
CREATE CAST (h3index AS point) WITH FUNCTION h3_h3_to_geo(h3index);
CREATE CAST (h3index AS geometry) WITH FUNCTION h3_h3_to_geometry(h3index);
CREATE CAST (h3index AS geography) WITH FUNCTION h3_h3_to_geography(h3index);
--CREATE CAST (h3index AS geometry) WITH FUNCTION h3_h3_to_geometry(h3index);
--CREATE CAST (h3index AS geography) WITH FUNCTION h3_h3_to_geography(h3index);

-- DEPRECATED in v1.0.0
CREATE OR REPLACE FUNCTION h3_haversine_distance(h3index, h3index) RETURNS double precision
Expand Down
8 changes: 4 additions & 4 deletions h3/sql/updates/h3--0.3.0--0.3.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary(h3index, extend_at_meridian BOO
AS 'h3', 'h3_cell_to_boundary' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
COMMENT ON FUNCTION h3_h3_to_geo_boundary(h3index, boolean) IS
'Finds the boundary of the index, second argument extends coordinates when crossing 180th meridian to help visualization';
CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geometry(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geometry
AS $$ SELECT ST_SetSRID(h3_h3_to_geo_boundary($1, $2)::geometry, 4326) $$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geography(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geography
AS $$ SELECT h3_h3_to_geo_boundary_geometry($1, $2)::geography $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geometry(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geometry
-- AS $$ SELECT ST_SetSRID(h3_h3_to_geo_boundary($1, $2)::geometry, 4326) $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_h3_to_geo_boundary_geography(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geography
-- AS $$ SELECT h3_h3_to_geo_boundary_geometry($1, $2)::geography $$ LANGUAGE SQL;
18 changes: 9 additions & 9 deletions h3/sql/updates/h3--0.4.0--1.0.0.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Bytes & Brains
* Copyright 2018-2022 Bytes & Brains
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,20 +34,20 @@ ALTER FUNCTION h3_h3_set_to_linked_geo(h3index[]) RENAME TO h3_set_to_linked_geo
ALTER FUNCTION __h3_h3_to_children_aux(h3index,integer,integer) RENAME TO __h3_to_children_aux;
ALTER FUNCTION h3_h3_to_children(h3index,integer) RENAME TO h3_to_children;
ALTER FUNCTION h3_h3_to_children_slow(h3index,integer) RENAME TO h3_to_children_slow;
ALTER FUNCTION h3_h3_to_geo_boundary_geography(h3index,boolean) RENAME TO h3_to_geo_boundary_geography;
ALTER FUNCTION h3_h3_to_geo_boundary_geometry(h3index,boolean) RENAME TO h3_to_geo_boundary_geometry;
--ALTER FUNCTION h3_h3_to_geo_boundary_geography(h3index,boolean) RENAME TO h3_to_geo_boundary_geography;
--ALTER FUNCTION h3_h3_to_geo_boundary_geometry(h3index,boolean) RENAME TO h3_to_geo_boundary_geometry;
ALTER FUNCTION h3_h3_to_geo_boundary(h3index,boolean) RENAME TO h3_to_geo_boundary;
ALTER FUNCTION h3_h3_to_geography(h3index) RENAME TO h3_to_geography;
--ALTER FUNCTION h3_h3_to_geography(h3index) RENAME TO h3_to_geography;
ALTER FUNCTION h3_h3_to_geo(h3index) RENAME TO h3_to_geo;
ALTER FUNCTION h3_h3_to_geometry(h3index) RENAME TO h3_to_geometry;
--ALTER FUNCTION h3_h3_to_geometry(h3index) RENAME TO h3_to_geometry;
ALTER FUNCTION h3_h3_to_parent(h3index,integer) RENAME TO h3_to_parent;
ALTER FUNCTION h3_h3_to_string(h3index) RENAME TO h3_to_string;
ALTER FUNCTION h3_h3_unidirectional_edge_is_valid(h3index) RENAME TO h3_unidirectional_edge_is_valid;

CREATE OR REPLACE FUNCTION h3_to_geo_boundary_geometry(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geometry
AS $$ SELECT ST_SetSRID(h3_to_geo_boundary($1, $2)::geometry, 4326) $$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_to_geo_boundary_geography(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geography
AS $$ SELECT h3_to_geo_boundary_geometry($1, $2)::geography $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_to_geo_boundary_geometry(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geometry
-- AS $$ SELECT ST_SetSRID(h3_to_geo_boundary($1, $2)::geometry, 4326) $$ LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_to_geo_boundary_geography(h3index, extend BOOLEAN DEFAULT FALSE) RETURNS geography
-- AS $$ SELECT h3_to_geo_boundary_geometry($1, $2)::geography $$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION h3_to_children_slow(index h3index, resolution integer DEFAULT -1) RETURNS SETOF h3index
AS $$ SELECT __h3_to_children_aux($1, $2, -1) $$ LANGUAGE SQL;
Expand Down
34 changes: 17 additions & 17 deletions h3/sql/updates/h3--3.6.4--3.6.5.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Bytes & Brains
* Copyright 2020-2022 Bytes & Brains
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,22 +20,22 @@
-- Fix function flags which were previously only changed in install files
ALTER FUNCTION h3_get_h3_unidirectional_edge_boundary(h3index)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_geo_to_h3(geometry, integer)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_geo_to_h3(geography, integer)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_to_geometry(h3index)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_to_geography(h3index)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_to_geo_boundary_geometry(h3index, boolean)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_to_geo_boundary_geography(h3index, boolean)
IMMUTABLE STRICT PARALLEL SAFE;
ALTER FUNCTION h3_polyfill(geometry, integer)
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT; -- NOT STRICT
ALTER FUNCTION h3_polyfill(geography, integer)
IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT; -- NOT STRICT
--ALTER FUNCTION h3_geo_to_h3(geometry, integer)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_geo_to_h3(geography, integer)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_to_geometry(h3index)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_to_geography(h3index)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_to_geo_boundary_geometry(h3index, boolean)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_to_geo_boundary_geography(h3index, boolean)
-- IMMUTABLE STRICT PARALLEL SAFE;
--ALTER FUNCTION h3_polyfill(geometry, integer)
-- IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT; -- NOT STRICT
--ALTER FUNCTION h3_polyfill(geography, integer)
-- IMMUTABLE PARALLEL SAFE CALLED ON NULL INPUT; -- NOT STRICT

-- Add second support function for hash opclass
CREATE OR REPLACE FUNCTION h3index_hash_extended(h3index, int8) RETURNS int8
Expand Down
8 changes: 4 additions & 4 deletions h3/sql/updates/h3--3.6.5--3.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ CREATE OPERATOR <-> (
);

-- Broken since 1.0.0 on update path
CREATE OR REPLACE FUNCTION h3_to_geometry(h3index) RETURNS geometry
AS $$ SELECT ST_SetSRID(h3_to_geo($1)::geometry, 4326) $$ IMMUTABLE STRICT PARALLEL SAFE LANGUAGE SQL;
CREATE OR REPLACE FUNCTION h3_to_geography(h3index) RETURNS geography
AS $$ SELECT h3_to_geometry($1)::geography $$ IMMUTABLE STRICT PARALLEL SAFE LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_to_geometry(h3index) RETURNS geometry
-- AS $$ SELECT ST_SetSRID(h3_to_geo($1)::geometry, 4326) $$ IMMUTABLE STRICT PARALLEL SAFE LANGUAGE SQL;
--CREATE OR REPLACE FUNCTION h3_to_geography(h3index) RETURNS geography
-- AS $$ SELECT h3_to_geometry($1)::geography $$ IMMUTABLE STRICT PARALLEL SAFE LANGUAGE SQL;

-- New functions in core v3.7.0
CREATE OR REPLACE FUNCTION h3_point_dist(a point, b point, unit text DEFAULT 'km') RETURNS float
Expand Down
4 changes: 2 additions & 2 deletions h3/sql/updates/h3--3.7.2--4.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ DROP FUNCTION IF EXISTS h3_to_geo_boundary_geometry(h3index, extend boolean);
DROP FUNCTION IF EXISTS h3_to_geo_boundary_geography(h3index, extend boolean);
DROP FUNCTION IF EXISTS h3_polyfill(multi geometry, resolution integer);
DROP FUNCTION IF EXISTS h3_polyfill(multi geography, resolution integer);
DROP CAST (h3index AS geometry);
DROP CAST (h3index AS geography);
DROP CAST IF EXISTS (h3index AS geometry);
DROP CAST IF EXISTS (h3index AS geography);
DROP FUNCTION IF EXISTS h3_to_geometry(h3index);
DROP FUNCTION IF EXISTS h3_to_geography(h3index);

Expand Down

0 comments on commit 75d5860

Please sign in to comment.