namespace Nominatim\Setup;
+require_once(CONST_BasePath.'/lib/setup/AddressLevelParser.php');
+
class SetupFunctions
{
protected $iCacheMemory;
exit(1);
}
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_name.sql');
- $this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_naturalearthdata.sql');
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/country_osm_grid.sql.gz');
$this->pgsqlRunScriptFile(CONST_BasePath.'/data/gb_postcode_table.sql');
$this->createSqlFunctions();
}
- public function createTables()
+ public function createTables($bReverseOnly = false)
{
info('Create Tables');
);
$this->pgsqlRunScript($sTemplate, false);
+
+ if ($bReverseOnly) {
+ $this->pgExec('DROP TABLE search_name');
+ }
+
+ $oAlParser = new AddressLevelParser(CONST_Address_Level_Config);
+ $oAlParser->createTable($this->oDB, 'address_levels');
}
public function createPartitionTables()
echo '.';
$this->pgExec('TRUNCATE location_area');
echo '.';
- $this->pgExec('TRUNCATE search_name');
- echo '.';
+ if (!$this->dbReverseOnly()) {
+ $this->pgExec('TRUNCATE search_name');
+ echo '.';
+ }
$this->pgExec('TRUNCATE search_name_blank');
echo '.';
$this->pgExec('DROP SEQUENCE seq_place');
info('Create Search indices');
$sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
+ if (!$this->dbReverseOnly()) {
+ $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql');
+ }
$sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
$sTemplate = $this->replaceTablespace(
'{ts:address-index}',
if (!$bFound) array_push($aDropTables, $sTable);
}
foreach ($aDropTables as $sDrop) {
- if ($this->sVerbose) echo "dropping table $sDrop\n";
+ if ($this->sVerbose) echo "Dropping table $sDrop\n";
@pg_query($this->oDB->connection, "DROP TABLE $sDrop CASCADE");
// ignore warnings/errors as they might be caused by a table having
// been deleted already by CASCADE
}
if (!is_null(CONST_Osm2pgsql_Flatnode_File) && CONST_Osm2pgsql_Flatnode_File) {
- if ($sVerbose) echo 'deleting '.CONST_Osm2pgsql_Flatnode_File."\n";
- unlink(CONST_Osm2pgsql_Flatnode_File);
+ if (file_exists(CONST_Osm2pgsql_Flatnode_File)) {
+ if ($this->sVerbose) echo 'Deleting '.CONST_Osm2pgsql_Flatnode_File."\n";
+ unlink(CONST_Osm2pgsql_Flatnode_File);
+ }
}
}
if (!CONST_Use_Aux_Location_data) {
$sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
}
+
+ $sReverseOnly = $this->dbReverseOnly() ? 'true' : 'false';
+ $sTemplate = str_replace('%REVERSE-ONLY%', $sReverseOnly, $sTemplate);
+
$this->pgsqlRunScript($sTemplate);
}
fail(pg_last_error($this->oDB->connection));
}
}
+
+ /**
+ * Check if the database is in reverse-only mode.
+ *
+ * @return True if there is no search_name table and infrastructure.
+ */
+ private function dbReverseOnly()
+ {
+ $sSQL = "SELECT count(*) FROM pg_tables WHERE tablename = 'search_name'";
+ return !(chksql($this->oDB->getOne($sSQL)));
+ }
}