From 96d3cb61c80d5fd0219497f74f908ca867ba5dce Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Tue, 18 Dec 2012 13:09:50 +0000 Subject: [PATCH] add constant to define postgis version. Verify definted version constants are correct during database creation. --- settings/settings.php | 5 ++++- utils/setup.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/settings/settings.php b/settings/settings.php index cd97b4a7..afa20d20 100644 --- a/settings/settings.php +++ b/settings/settings.php @@ -7,8 +7,11 @@ @define('CONST_Database_DSN', 'pgsql://@/nominatim'); @define('CONST_Max_Word_Frequency', '50000'); + // Software versions + @define('CONST_Postgresql_Version', '9.1'); // values: 8.3, 8.4, 9.0, 9.1, 9.2 + @define('CONST_Postgis_Version', '1.5'); // values: 1.5, 2.0 + // Paths - @define('CONST_Postgresql_Version', '9.1'); @define('CONST_Path_Postgresql_Contrib', '/usr/share/postgresql/'.CONST_Postgresql_Version.'/contrib'); @define('CONST_Path_Postgresql_Postgis', CONST_Path_Postgresql_Contrib.'/postgis-1.5'); @define('CONST_Osm2pgsql_Binary', CONST_BasePath.'/osm2pgsql/osm2pgsql'); diff --git a/utils/setup.php b/utils/setup.php index ed4b79c0..01aa8062 100755 --- a/utils/setup.php +++ b/utils/setup.php @@ -105,6 +105,15 @@ // TODO: path detection, detection memory, etc. $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]) + { + echo "ERROR: PostgreSQL version is not correct. Expected ".CONST_Postgresql_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n"; + exit; + } + passthru('createlang plpgsql '.$aDSNInfo['database']); $pgver = (float) CONST_Postgresql_Version; if ($pgver < 9.1) { @@ -113,7 +122,16 @@ } else { pgsqlRunScript('CREATE EXTENSION hstore'); } + pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/postgis.sql'); + $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]) + { + echo "ERROR: PostGIS version is not correct. Expected ".CONST_Postgis_Version." found ".$aMatches[1].'.'.$aMatches[2]."\n"; + exit; + } + pgsqlRunScriptFile(CONST_Path_Postgresql_Postgis.'/spatial_ref_sys.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql'); -- 2.39.5