From 4acae73cb9e0700b9e7b49181d57d1410e583789 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 17 Jan 2025 15:49:30 -0500 Subject: [PATCH 1/8] chore: wip attempt to fix search paths for postgis_tiger_geocoder --- nix/ext/postgis.nix | 47 +++++++++++++++++++++-------------- nix/ext/tiger_search_path.sql | 19 ++++++++++++++ 2 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 nix/ext/tiger_search_path.sql diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index 17b389e5c..a0a2de189 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -35,9 +35,12 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ perl pkg-config ]; dontDisableStatic = true; - # postgis config directory assumes /include /lib from the same root for json-c library - env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib"; + # Copy our SQL file into the source + postUnpack = '' + cp ${./tiger_search_path.sql} $sourceRoot/tiger_search_path.sql + ''; + env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib"; preConfigure = '' sed -i 's@/usr/bin/file@${file}/bin/file@' configure @@ -45,6 +48,7 @@ stdenv.mkDerivation rec { makeFlags="PERL=${perl}/bin/perl datadir=$out/share/postgresql pkglibdir=$out/lib bindir=$out/bin docdir=$doc/share/doc/${pname}" ''; + postConfigure = '' sed -i "s|@mkdir -p \$(DESTDIR)\$(PGSQL_BINDIR)||g ; s|\$(DESTDIR)\$(PGSQL_BINDIR)|$prefix/bin|g @@ -54,28 +58,33 @@ stdenv.mkDerivation rec { " \ "raster/scripts/python/Makefile"; mkdir -p $out/bin - - # postgis' build system assumes it is being installed to the same place as postgresql, and looks - # for the postgres binary relative to $PREFIX. We gently support this system using an illusion. ln -s ${postgresql}/bin/postgres $out/bin/postgres ''; - # create aliases for all commands adding version information - postInstall = '' - # Teardown the illusory postgres used for building; see postConfigure. - rm $out/bin/postgres +postInstall = '' + rm $out/bin/postgres - for prog in $out/bin/*; do # */ - ln -s $prog $prog-${version} - done + for prog in $out/bin/*; do # */ + ln -s $prog $prog-${version} + done - for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do - sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file" - done + # Add AddToSearchPath function to tiger_geocoder files + for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do + # Insert the function near the start of the file + sed -i '/Copyright (C) 2010, 2011-2015 Regina Obe and Leo Hsu/r tiger_search_path.sql' "$file" + + # Add the call to AddToSearchPath just before the install_geocode_settings function + #sed -i '/CREATE FUNCTION install_geocode_settings()/i SELECT tiger.AddToSearchPath('"'"'extensions'"'"');' "$file" + done - mkdir -p $doc/share/doc/postgis - mv doc/* $doc/share/doc/postgis/ - ''; + # Original topology patching + for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do + sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file" + done + + mkdir -p $doc/share/doc/postgis + mv doc/* $doc/share/doc/postgis/ +''; passthru.tests.postgis = nixosTests.postgis; @@ -87,4 +96,4 @@ stdenv.mkDerivation rec { maintainers = with maintainers; [ samrose ]; inherit (postgresql.meta) platforms; }; -} +} \ No newline at end of file diff --git a/nix/ext/tiger_search_path.sql b/nix/ext/tiger_search_path.sql new file mode 100644 index 000000000..aee2fb102 --- /dev/null +++ b/nix/ext/tiger_search_path.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE FUNCTION tiger.AddToSearchPath(varchar) +RETURNS text +AS $$ +DECLARE + var_result text; + var_cur_search_path text; +BEGIN + -- Get current search path + SELECT current_setting('search_path') INTO var_cur_search_path; + + -- If schema is not in search path, add it + IF NOT var_cur_search_path LIKE '%' || quote_ident($1) || '%' THEN + var_cur_search_path := var_cur_search_path || ', ' || quote_ident($1); + EXECUTE 'SET search_path = ' || quote_literal(var_cur_search_path); + END IF; + + RETURN $1 || ' added to search_path'; +END +$$ LANGUAGE plpgsql VOLATILE STRICT SET search_path = pg_catalog; From a19cab67dcf35539647c506157045f6d0c1f5c96 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 17 Jan 2025 15:50:29 -0500 Subject: [PATCH 2/8] chore: suffix for staging AMI --- ansible/vars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/vars.yml b/ansible/vars.yml index dba3aff49..0a9c4f0d4 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -8,8 +8,8 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.019-orioledb" - postgres15: "15.8.1.029" + postgresorioledb-17: "17.0.1.019-orioledb-staging-1" + postgres15: "15.8.1.029-staging-1" # Non Postgres Extensions pgbouncer_release: "1.19.0" From 2220c64f1a1c3d5448f37d8c87fa92ddc6aca55b Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 17 Jan 2025 15:53:16 -0500 Subject: [PATCH 3/8] chore: newline --- nix/ext/postgis.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index a0a2de189..34727c0ad 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -96,4 +96,4 @@ postInstall = '' maintainers = with maintainers; [ samrose ]; inherit (postgresql.meta) platforms; }; -} \ No newline at end of file +} From 7ef2e77eebc2ca372d97c0329d00603c68bdf4a1 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 17 Jan 2025 16:31:28 -0500 Subject: [PATCH 4/8] chore: fix pg_regress --- nix/tests/expected/z_15_ext_interface.out | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/tests/expected/z_15_ext_interface.out b/nix/tests/expected/z_15_ext_interface.out index 648693928..93a227fd6 100644 --- a/nix/tests/expected/z_15_ext_interface.out +++ b/nix/tests/expected/z_15_ext_interface.out @@ -4382,6 +4382,7 @@ order by postgis_sfcgal | public | st_straightskeleton | geometry | geometry postgis_sfcgal | public | st_tesselate | geometry | geometry postgis_sfcgal | public | st_volume | geometry | double precision + postgis_tiger_geocoder | tiger | addtosearchpath | character varying | text postgis_tiger_geocoder | tiger | count_words | character varying | integer postgis_tiger_geocoder | tiger | create_census_base_tables | | text postgis_tiger_geocoder | tiger | cull_null | character varying | character varying @@ -5205,7 +5206,7 @@ order by xml2 | public | xpath_table | text, text, text, text, text | SETOF record xml2 | public | xslt_process | text, text | text xml2 | public | xslt_process | text, text, text | text -(5034 rows) +(5035 rows) /* From 2e2fab6f36904daac8672d0b9e9bca3690086f89 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 21 Jan 2025 07:55:36 -0500 Subject: [PATCH 5/8] fix: use postgis_extension_AddToSearchPath for extensions schema --- ansible/vars.yml | 4 ++-- nix/ext/postgis.nix | 17 ++--------------- nix/ext/tiger_search_path.sql | 19 ------------------- nix/tests/expected/z_15_ext_interface.out | 3 +-- 4 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 nix/ext/tiger_search_path.sql diff --git a/ansible/vars.yml b/ansible/vars.yml index 0a9c4f0d4..1e480e9c6 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -8,8 +8,8 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.019-orioledb-staging-1" - postgres15: "15.8.1.029-staging-1" + postgresorioledb-17: "17.0.1.019-orioledb-staging-2" + postgres15: "15.8.1.029-staging-2" # Non Postgres Extensions pgbouncer_release: "1.19.0" diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index 34727c0ad..20b710389 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -35,11 +35,6 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ perl pkg-config ]; dontDisableStatic = true; - # Copy our SQL file into the source - postUnpack = '' - cp ${./tiger_search_path.sql} $sourceRoot/tiger_search_path.sql - ''; - env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib"; preConfigure = '' @@ -63,25 +58,17 @@ stdenv.mkDerivation rec { postInstall = '' rm $out/bin/postgres - for prog in $out/bin/*; do # */ ln -s $prog $prog-${version} done - - # Add AddToSearchPath function to tiger_geocoder files + # Add function definition and usage to tiger geocoder files for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do - # Insert the function near the start of the file - sed -i '/Copyright (C) 2010, 2011-2015 Regina Obe and Leo Hsu/r tiger_search_path.sql' "$file" - - # Add the call to AddToSearchPath just before the install_geocode_settings function - #sed -i '/CREATE FUNCTION install_geocode_settings()/i SELECT tiger.AddToSearchPath('"'"'extensions'"'"');' "$file" + sed -i '/SELECT postgis_extension_AddToSearchPath('tiger');/a SELECT postgis_extension_AddToSearchPath('extensions');' "$file" done - # Original topology patching for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do sed -i "/SELECT topology.AddToSearchPath('topology');/i SELECT topology.AddToSearchPath('extensions');" "$file" done - mkdir -p $doc/share/doc/postgis mv doc/* $doc/share/doc/postgis/ ''; diff --git a/nix/ext/tiger_search_path.sql b/nix/ext/tiger_search_path.sql deleted file mode 100644 index aee2fb102..000000000 --- a/nix/ext/tiger_search_path.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE OR REPLACE FUNCTION tiger.AddToSearchPath(varchar) -RETURNS text -AS $$ -DECLARE - var_result text; - var_cur_search_path text; -BEGIN - -- Get current search path - SELECT current_setting('search_path') INTO var_cur_search_path; - - -- If schema is not in search path, add it - IF NOT var_cur_search_path LIKE '%' || quote_ident($1) || '%' THEN - var_cur_search_path := var_cur_search_path || ', ' || quote_ident($1); - EXECUTE 'SET search_path = ' || quote_literal(var_cur_search_path); - END IF; - - RETURN $1 || ' added to search_path'; -END -$$ LANGUAGE plpgsql VOLATILE STRICT SET search_path = pg_catalog; diff --git a/nix/tests/expected/z_15_ext_interface.out b/nix/tests/expected/z_15_ext_interface.out index 93a227fd6..648693928 100644 --- a/nix/tests/expected/z_15_ext_interface.out +++ b/nix/tests/expected/z_15_ext_interface.out @@ -4382,7 +4382,6 @@ order by postgis_sfcgal | public | st_straightskeleton | geometry | geometry postgis_sfcgal | public | st_tesselate | geometry | geometry postgis_sfcgal | public | st_volume | geometry | double precision - postgis_tiger_geocoder | tiger | addtosearchpath | character varying | text postgis_tiger_geocoder | tiger | count_words | character varying | integer postgis_tiger_geocoder | tiger | create_census_base_tables | | text postgis_tiger_geocoder | tiger | cull_null | character varying | character varying @@ -5206,7 +5205,7 @@ order by xml2 | public | xpath_table | text, text, text, text, text | SETOF record xml2 | public | xslt_process | text, text | text xml2 | public | xslt_process | text, text, text | text -(5035 rows) +(5034 rows) /* From 45c3762c1c9694308f39894a3783ea20b59186a9 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 21 Jan 2025 08:32:46 -0500 Subject: [PATCH 6/8] chore: bump staging suffix --- ansible/vars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/vars.yml b/ansible/vars.yml index 1e480e9c6..e4a1d42ff 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -8,8 +8,8 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.019-orioledb-staging-2" - postgres15: "15.8.1.029-staging-2" + postgresorioledb-17: "17.0.1.019-orioledb-staging-3" + postgres15: "15.8.1.029-staging-3" # Non Postgres Extensions pgbouncer_release: "1.19.0" From d16d6f2dbb4c6d373553d0558272b01ab3fcbe00 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 21 Jan 2025 15:10:28 -0500 Subject: [PATCH 7/8] chore: resolve quotes to test --- ansible/vars.yml | 4 ++-- nix/ext/postgis.nix | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ansible/vars.yml b/ansible/vars.yml index e4a1d42ff..920e5bf54 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -8,8 +8,8 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.019-orioledb-staging-3" - postgres15: "15.8.1.029-staging-3" + postgresorioledb-17: "17.0.1.019-orioledb-staging-4" + postgres15: "15.8.1.029-staging-4" # Non Postgres Extensions pgbouncer_release: "1.19.0" diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index 20b710389..2c8a36ce5 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -35,6 +35,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ perl pkg-config ]; dontDisableStatic = true; + env.NIX_LDFLAGS = "-L${lib.getLib json_c}/lib"; preConfigure = '' @@ -63,7 +64,7 @@ postInstall = '' done # Add function definition and usage to tiger geocoder files for file in $out/share/postgresql/extension/postgis_tiger_geocoder*--${version}.sql; do - sed -i '/SELECT postgis_extension_AddToSearchPath('tiger');/a SELECT postgis_extension_AddToSearchPath('extensions');' "$file" + sed -i "/SELECT postgis_extension_AddToSearchPath('tiger');/a SELECT postgis_extension_AddToSearchPath('extensions');" "$file" done # Original topology patching for file in $out/share/postgresql/extension/postgis_topology*--${version}.sql; do From 2faf3c2384107b04f6c965942034e47ddb2a1856 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 21 Jan 2025 17:10:32 -0500 Subject: [PATCH 8/8] chore: bump versions --- ansible/vars.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/vars.yml b/ansible/vars.yml index 920e5bf54..3d8d96252 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -8,8 +8,8 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.019-orioledb-staging-4" - postgres15: "15.8.1.029-staging-4" + postgresorioledb-17: "17.0.1.021-orioledb" + postgres15: "15.8.1.031" # Non Postgres Extensions pgbouncer_release: "1.19.0"