]> git.openstreetmap.org Git - nominatim.git/commitdiff
remove explicitly set postgres/postgis version
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 30 Mar 2016 20:48:18 +0000 (22:48 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 30 Mar 2016 20:48:18 +0000 (22:48 +0200)
Get the version from the database where necessary or simply
probe for existence of features. Fake hstore_to_json when
necessary.

Bumps the minimum required versions fro postgres to 9.1 and
for postgis to 2.0.

lib/Geocode.php
lib/PlaceLookup.php
lib/db.php
settings/settings.php
sql/functions.sql
sql/postgis_15_aux.sql [deleted file]
sql/postgis_20_aux.sql [deleted file]
utils/setup.php
utils/update.php

index d699263e2e87f21c1069bdd0f6b8e7fd7be21794..f2ca5e5008f36d440cc67f8dc81eb5c497f94b61 100644 (file)
                function loadParamArray($aParams)
                {
                        if (isset($aParams['addressdetails'])) $this->bIncludeAddressDetails = (bool)$aParams['addressdetails'];
-                       if ((float) CONST_Postgresql_Version > 9.2)
-                       {
-                               if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
-                               if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
-                       }
+                       if (isset($aParams['extratags'])) $this->bIncludeExtraTags = (bool)$aParams['extratags'];
+                       if (isset($aParams['namedetails'])) $this->bIncludeNameDetails = (bool)$aParams['namedetails'];
+
                        if (isset($aParams['bounded'])) $this->bBoundedSearch = (bool)$aParams['bounded'];
                        if (isset($aParams['dedupe'])) $this->bDeDupe = (bool)$aParams['dedupe'];
 
index 817d0ec50ce4a2a183b83aa96af5e5bdb63f8863..94e414dc7d45e930e8d1092f45f1f9e4125860ee 100644 (file)
 
                function setIncludeExtraTags($bExtraTags = false)
                {
-                       if ((float) CONST_Postgresql_Version > 9.2)
-                       {
-                               $this->bExtraTags = $bExtraTags;
-                       }
+                       $this->bExtraTags = $bExtraTags;
                }
 
                function setIncludeNameDetails($bNameDetails = false)
                {
-                       if ((float) CONST_Postgresql_Version > 9.2)
-                       {
-                               $this->bNameDetails = $bNameDetails;
-                       }
+                       $this->bNameDetails = $bNameDetails;
                }
 
 
index d7c85e7b6df684f850c9e283bc3e2a29195689f9..ab578e4b2673f73d00e2b526c304f42f1b08258c 100644 (file)
                return "'".pg_escape_string($s)."'";
        }
 
+       function getPostgresVersion(&$oDB)
+       {
+               $sVersionString = $oDB->getOne('select version()');
+               preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[^0-9]#', $sVersionString, $aMatches);
+               return (float) ($aMatches[1].'.'.$aMatches[2]);
+       }
+
+       function getPostgisVersion(&$oDB)
+       {
+               $sVersionString = $oDB->getOne('select postgis_full_version()');
+               preg_match('#POSTGIS="([0-9]+)[.]([0-9]+)[.]([0-9]+)( r([0-9]+))?"#', $sVersionString, $aMatches);
+               return (float) ($aMatches[1].'.'.$aMatches[2]);
+       }
index ea664683adc02d9606b71aa28888b45735dc8cbd..0c8d76bdb3e3e2094c916dc3e40888ae2901b51d 100644 (file)
        @define('CONST_HTTP_Proxy_Login', '');
        @define('CONST_HTTP_Proxy_Password', '');
 
-       // Software versions
-       @define('CONST_Postgresql_Version', '9.3'); // values: 9.0, ... , 9.4
-       @define('CONST_Postgis_Version', '2.1'); // values: 1.5, 2.0, 2.1
-
        // Paths
-       @define('CONST_Path_Postgresql_Contrib', '/usr/share/postgresql/'.CONST_Postgresql_Version.'/contrib');
-       @define('CONST_Path_Postgresql_Postgis', CONST_Path_Postgresql_Contrib.'/postgis-'.CONST_Postgis_Version);
        @define('CONST_Osm2pgsql_Binary', CONST_InstallPath.'/osm2pgsql/osm2pgsql');
        @define('CONST_Osmosis_Binary', '/usr/bin/osmosis');
        @define('CONST_Tiger_Data_Path', CONST_BasePath.'/data/tiger');
index b88a7f8121187973c9ea991914d8c43297fd7f92..5b068dfe03f5ed7557939c2f99054d5e98b74160 100644 (file)
@@ -1,3 +1,15 @@
+-- Splits the line at the given point and returns the two parts
+-- in a multilinestring.
+CREATE OR REPLACE FUNCTION split_line_on_node(line GEOMETRY, point GEOMETRY)
+RETURNS GEOMETRY
+  AS $$
+BEGIN
+  RETURN ST_Split(ST_Snap(line, point, 0.0005), point);
+END;
+$$
+LANGUAGE plpgsql;
+
+
 CREATE OR REPLACE FUNCTION geometry_sector(partition INTEGER, place geometry) RETURNS INTEGER
   AS $$
 DECLARE
diff --git a/sql/postgis_15_aux.sql b/sql/postgis_15_aux.sql
deleted file mode 100644 (file)
index 548e0fe..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
--- Splits the line at the given point and returns the two parts
--- in a multilinestring.
-CREATE OR REPLACE FUNCTION split_line_on_node(line GEOMETRY, point GEOMETRY)
-RETURNS GEOMETRY
-  AS $$
-DECLARE
-  frac FLOAT;
-BEGIN
-  frac := ST_Line_Locate_Point(line, point);
-  RETURN ST_Collect(ST_Line_Substring(line, 0, frac),
-         ST_Line_Substring(line, frac, 1));
-END
-$$
-LANGUAGE plpgsql;
diff --git a/sql/postgis_20_aux.sql b/sql/postgis_20_aux.sql
deleted file mode 100644 (file)
index 749e2a4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
--- Splits the line at the given point and returns the two parts
--- in a multilinestring.
-CREATE OR REPLACE FUNCTION split_line_on_node(line GEOMETRY, point GEOMETRY)
-RETURNS GEOMETRY
-  AS $$
-BEGIN
-  RETURN ST_Split(ST_Snap(line, point, 0.0005), point);
-END;
-$$
-LANGUAGE plpgsql;
index 8c343e34a893f107cf0719cd660e684aefd4e212..60fe5dace6734689bfc03aa8e45bfc99f25ceef5 100755 (executable)
@@ -90,8 +90,6 @@
        $aDSNInfo = DB::parseDSN(CONST_Database_DSN);
        if (!isset($aDSNInfo['port']) || !$aDSNInfo['port']) $aDSNInfo['port'] = 5432;
 
-       $fPostgisVersion = (float) CONST_Postgis_Version;
-
        if ($aCMDResult['create-db'] || $aCMDResult['all'])
        {
                echo "Create DB\n";
 
                $oDB =& getDB();
 
-               $sVersionString = $oDB->getOne('select version()');
-               preg_match('#PostgreSQL ([0-9]+)[.]([0-9]+)[^0-9]#', $sVersionString, $aMatches);
-               if (CONST_Postgresql_Version != $aMatches[1].'.'.$aMatches[2])
+               $fPostgresVersion = getPostgresVersion($oDB);
+               echo 'Postgres version found: '.$fPostgresVersion."\n";
+
+               if ($fPostgresVersion < 9.1)
                {
-                       echo "ERROR: PostgreSQL version is not correct.  Expected ".CONST_Postgresql_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n";
-                       exit;
+                       fail("Minimum supported version of Postgresql is 9.1.");
                }
 
-               passthru('createlang plpgsql -p '.$aDSNInfo['port'].' '.$aDSNInfo['database']);
-               $pgver = (float) CONST_Postgresql_Version;
-               if ($pgver < 9.1) {
-                       pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
-                       pgsqlRunScriptFile(CONST_BasePath.'/sql/hstore_compatability_9_0.sql');
-               } else {
-                       pgsqlRunScript('CREATE EXTENSION hstore');
-               }
+               pgsqlRunScript('CREATE EXTENSION IF NOT EXISTS hstore');
+               pgsqlRunScript('CREATE EXTENSION IF NOT EXISTS postgis');
 
-               if ($fPostgisVersion < 2.0) {
-                       pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql');
-                       pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql');
-               } else {
-                       pgsqlRunScript('CREATE EXTENSION IF NOT EXISTS postgis');
+               // For extratags and namedetails the hstore_to_json converter is
+               // needed which is only available from Postgresql 9.3+. For older
+               // versions add a dummy function that returns nothing.
+               $iNumFunc = $oDB->getOne("select count(*) from pg_proc where proname = 'hstore_to_json'");
+               if (PEAR::isError($iNumFunc))
+               {
+                       fail("Cannot query stored procedures.", $iNumFunc);
                }
-               if ($fPostgisVersion < 2.1) {
-                       // Function was renamed in 2.1 and throws an annoying deprecation warning
-                       pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint');
+               if ($iNumFunc == 0)
+               {
+                       pgsqlRunScript("create function hstore_to_json(dummy hstore) returns text AS 'select null::text' language sql immutable");
+                       echo "WARNING: Postgresql is too old. extratags and namedetails API not available.";
                }
-               $sVersionString = $oDB->getOne('select postgis_full_version()');
-               preg_match('#POSTGIS="([0-9]+)[.]([0-9]+)[.]([0-9]+)( r([0-9]+))?"#', $sVersionString, $aMatches);
-               if (CONST_Postgis_Version != $aMatches[1].'.'.$aMatches[2])
+
+               $fPostgisVersion = getPostgisVersion($oDB);
+               echo 'Postgis version found: '.$fPostgisVersion."\n";
+
+               if ($fPostgisVersion < 2.1)
                {
-                       echo "ERROR: PostGIS version is not correct.  Expected ".CONST_Postgis_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n";
-                       exit;
+                       // Function was renamed in 2.1 and throws an annoying deprecation warning
+                       pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint');
                }
 
                pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql');
                if ($aCMDResult['enable-debug-statements']) $sTemplate = str_replace('--DEBUG:', '', $sTemplate);
                if (CONST_Limit_Reindexing) $sTemplate = str_replace('--LIMIT INDEXING:', '', $sTemplate);
                pgsqlRunScript($sTemplate);
-
-               if ($fPostgisVersion < 2.0) {
-                       echo "Helper functions for postgis < 2.0\n";
-                       $sTemplate = file_get_contents(CONST_BasePath.'/sql/postgis_15_aux.sql');
-               } else {
-                       echo "Helper functions for postgis >= 2.0\n";
-                       $sTemplate = file_get_contents(CONST_BasePath.'/sql/postgis_20_aux.sql');
-               }
-               pgsqlRunScript($sTemplate);
        }
 
        if ($aCMDResult['create-tables'] || $aCMDResult['all'])
index f5dec537baca2d035669be3384b9a6b33a9de8b5..34d30a4ff20e3f1961609530a68b80d8e1fe1f09 100755 (executable)
        if ($aResult['deduplicate'])
        {
 
-               $pgver = (float) CONST_Postgresql_Version;
-               if ($pgver < 9.3) {
+               if (getPostgresVersion() < 9.3)
+               {
                        fail("ERROR: deduplicate is only currently supported in postgresql 9.3");
                }