X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/a7e782353522da11504efd6e1948b86e2a97e7f7..a7edda32ba995cf1c0ceebf1778bb7c483e962da:/lib/setup/SetupClass.php diff --git a/lib/setup/SetupClass.php b/lib/setup/SetupClass.php index c14190c3..b6705968 100755 --- a/lib/setup/SetupClass.php +++ b/lib/setup/SetupClass.php @@ -106,34 +106,19 @@ class SetupFunctions $fPostgresVersion = $this->oDB->getPostgresVersion(); echo 'Postgres version found: '.$fPostgresVersion."\n"; - if ($fPostgresVersion < 9.01) { - fail('Minimum supported version of Postgresql is 9.1.'); + if ($fPostgresVersion < 9.03) { + fail('Minimum supported version of Postgresql is 9.3.'); } $this->pgsqlRunScript('CREATE EXTENSION IF NOT EXISTS hstore'); $this->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 = $this->oDB->getOne("select count(*) from pg_proc where proname = 'hstore_to_json'"); - - if ($iNumFunc == 0) { - $this->pgsqlRunScript("create function hstore_to_json(dummy hstore) returns text AS 'select null::text' language sql immutable"); - warn('Postgresql is too old. extratags and namedetails API not available.'); - } - - $fPostgisVersion = $this->oDB->getPostgisVersion(); echo 'Postgis version found: '.$fPostgisVersion."\n"; - if ($fPostgisVersion < 2.1) { - // Functions were renamed in 2.1 and throw an annoying deprecation warning - $this->pgsqlRunScript('ALTER FUNCTION st_line_interpolate_point(geometry, double precision) RENAME TO ST_LineInterpolatePoint'); - $this->pgsqlRunScript('ALTER FUNCTION ST_Line_Locate_Point(geometry, geometry) RENAME TO ST_LineLocatePoint'); - } if ($fPostgisVersion < 2.2) { - $this->pgsqlRunScript('ALTER FUNCTION ST_Distance_Spheroid(geometry, geometry, spheroid) RENAME TO ST_DistanceSpheroid'); + echo "Minimum required Postgis version 2.2\n"; + exit(1); } $i = $this->oDB->getOne("select count(*) from pg_user where usename = '".CONST_Database_Web_User."'"); @@ -154,16 +139,20 @@ class SetupFunctions $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql'); $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql.gz'); $this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql'); + $this->pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode_table.sql'); $sPostcodeFilename = CONST_BasePath.'/data/gb_postcode_data.sql.gz'; if (file_exists($sPostcodeFilename)) { $this->pgsqlRunScriptFile($sPostcodeFilename); } else { - warn('optional external UK postcode table file ('.$sPostcodeFilename.') not found. Skipping.'); + warn('optional external GB postcode table file ('.$sPostcodeFilename.') not found. Skipping.'); } - if (CONST_Use_Extra_US_Postcodes) { - $this->pgsqlRunScriptFile(CONST_BasePath.'/data/us_postcode.sql'); + $sPostcodeFilename = CONST_BasePath.'/data/us_postcode_data.sql.gz'; + if (file_exists($sPostcodeFilename)) { + $this->pgsqlRunScriptFile($sPostcodeFilename); + } else { + warn('optional external US postcode table file ('.$sPostcodeFilename.') not found. Skipping.'); } if ($this->bNoPartitions) { @@ -573,17 +562,15 @@ class SetupFunctions $sSQL .= ' GROUP BY country_code, pc'; $this->pgExec($sSQL); - if (CONST_Use_Extra_US_Postcodes) { - // only add postcodes that are not yet available in OSM - $sSQL = 'INSERT INTO location_postcode'; - $sSQL .= ' (place_id, indexed_status, country_code, postcode, geometry) '; - $sSQL .= "SELECT nextval('seq_place'), 1, 'us', postcode,"; - $sSQL .= ' ST_SetSRID(ST_Point(x,y),4326)'; - $sSQL .= ' FROM us_postcode WHERE postcode NOT IN'; - $sSQL .= ' (SELECT postcode FROM location_postcode'; - $sSQL .= " WHERE country_code = 'us')"; - $this->pgExec($sSQL); - } + // only add postcodes that are not yet available in OSM + $sSQL = 'INSERT INTO location_postcode'; + $sSQL .= ' (place_id, indexed_status, country_code, postcode, geometry) '; + $sSQL .= "SELECT nextval('seq_place'), 1, 'us', postcode,"; + $sSQL .= ' ST_SetSRID(ST_Point(x,y),4326)'; + $sSQL .= ' FROM us_postcode WHERE postcode NOT IN'; + $sSQL .= ' (SELECT postcode FROM location_postcode'; + $sSQL .= " WHERE country_code = 'us')"; + $this->pgExec($sSQL); // add missing postcodes for GB (if available) $sSQL = 'INSERT INTO location_postcode'; @@ -753,7 +740,10 @@ class SetupFunctions private function pgsqlRunDropAndRestore($sDumpFile) { - $sCMD = 'pg_restore -p '.$this->aDSNInfo['port'].' -d '.$this->aDSNInfo['database'].' -Fc --clean '.$sDumpFile; + $sCMD = 'pg_restore -p '.$this->aDSNInfo['port'].' -d '.$this->aDSNInfo['database'].' --no-owner -Fc --clean '.$sDumpFile; + if ($this->oDB->getPostgresVersion() >= 9.04) { + $sCMD .= ' --if-exists'; + } if (isset($this->aDSNInfo['hostspec'])) { $sCMD .= ' -h '.$this->aDSNInfo['hostspec']; }