@define('CONST_Default_Osm2pgsql', '@CMAKE_BINARY_DIR@/osm2pgsql/osm2pgsql');
@define('CONST_BinDir', '@CMAKE_SOURCE_DIR@/utils');
@define('CONST_DataDir', '@CMAKE_SOURCE_DIR@');
+@define('CONST_SqlDir', '@CMAKE_SOURCE_DIR@/lib-sql');
loadDotEnv();
$_SERVER['NOMINATIM_NOMINATIM_TOOL'] = '@CMAKE_BINARY_DIR@/nominatim';
exit(cli.nominatim(module_dir='@CMAKE_BINARY_DIR@/module',
osm2pgsql_path='@CMAKE_BINARY_DIR@/osm2pgsql/osm2pgsql',
phplib_dir='@CMAKE_SOURCE_DIR@/lib-php',
+ sqllib_dir='@CMAKE_SOURCE_DIR@/lib-sql',
data_dir='@CMAKE_SOURCE_DIR@',
phpcgi_path='@PHPCGI_BIN@'))
// set of settings.
defined('CONST_DataDir') or define('CONST_DataDir', $_SERVER['NOMINATIM_DATADIR']);
defined('CONST_BinDir') or define('CONST_BinDir', $_SERVER['NOMINATIM_BINDIR']);
+ defined('CONST_SqlDir') or define('CONST_SqlDir', $_SERVER['NOMINATIM_SQLDIR']);
defined('CONST_Default_ModulePath') or define('CONST_Default_ModulePath', $_SERVER['NOMINATIM_DATABASE_MODULE_SRC_PATH']);
}
{
info('Create Tables');
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/tables.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/tables.sql');
$sTemplate = $this->replaceSqlPatterns($sTemplate);
$this->pgsqlRunScript($sTemplate, false);
{
info('Create Tables');
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/table-triggers.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/table-triggers.sql');
$sTemplate = $this->replaceSqlPatterns($sTemplate);
$this->pgsqlRunScript($sTemplate, false);
{
info('Create Partition Tables');
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/partition-tables.src.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/partition-tables.src.sql');
$sTemplate = $this->replaceSqlPatterns($sTemplate);
$this->pgsqlRunPartitionScript($sTemplate);
warn('Tiger data import selected but no files found in path '.$sTigerPath);
return;
}
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_start.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/tiger_import_start.sql');
$sTemplate = $this->replaceSqlPatterns($sTemplate);
$this->pgsqlRunScript($sTemplate, false);
}
info('Creating indexes on Tiger data');
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/tiger_import_finish.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/tiger_import_finish.sql');
$sTemplate = $this->replaceSqlPatterns($sTemplate);
$this->pgsqlRunScript($sTemplate, false);
public function calculatePostcodes($bCMDResultAll)
{
info('Calculate Postcodes');
- $this->pgsqlRunScriptFile(CONST_DataDir.'/sql/postcode_tables.sql');
+ $this->pgsqlRunScriptFile(CONST_SqlDir.'/postcode_tables.sql');
$sPostcodeFilename = CONST_InstallDir.'/gb_postcode_data.sql.gz';
if (file_exists($sPostcodeFilename)) {
$this->db()->exec("DROP INDEX $sIndexName;");
}
- $sTemplate = file_get_contents(CONST_DataDir.'/sql/indices.src.sql');
+ $sTemplate = file_get_contents(CONST_SqlDir.'/indices.src.sql');
if (!$this->bDrop) {
- $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_updates.src.sql');
+ $sTemplate .= file_get_contents(CONST_SqlDir.'/indices_updates.src.sql');
}
if (!$this->dbReverseOnly()) {
- $sTemplate .= file_get_contents(CONST_DataDir.'/sql/indices_search.src.sql');
+ $sTemplate .= file_get_contents(CONST_SqlDir.'/indices_search.src.sql');
}
$sTemplate = $this->replaceSqlPatterns($sTemplate);
self.parser.print_help()
return 1
- for arg in ('module_dir', 'osm2pgsql_path', 'phplib_dir', 'data_dir', 'phpcgi_path'):
+ for arg in ('module_dir', 'osm2pgsql_path', 'phplib_dir', 'sqllib_dir',
+ 'data_dir', 'phpcgi_path'):
setattr(args, arg, Path(kwargs[arg]))
args.project_dir = Path(args.project_dir).resolve()
if args.postcodes:
LOG.warning("Update postcodes centroid")
conn = connect(args.config.get_libpq_dsn())
- refresh.update_postcodes(conn, args.data_dir)
+ refresh.update_postcodes(conn, args.sqllib_dir)
conn.close()
if args.word_counts:
if args.functions:
LOG.warning('Create functions')
conn = connect(args.config.get_libpq_dsn())
- refresh.create_functions(conn, args.config, args.data_dir,
+ refresh.create_functions(conn, args.config, args.sqllib_dir,
args.diffs, args.enable_debug_statements)
conn.close()
replication.init_replication(conn, base_url=args.config.REPLICATION_URL)
if args.update_functions:
LOG.warning("Create functions")
- refresh.create_functions(conn, args.config, args.data_dir,
+ refresh.create_functions(conn, args.config, args.sqllib_dir,
True, False)
conn.close()
return 0
env = nominatim_env.config.get_os_env()
env['NOMINATIM_DATADIR'] = str(nominatim_env.data_dir)
env['NOMINATIM_BINDIR'] = str(nominatim_env.data_dir / 'utils')
+ env['NOMINATIM_SQLDIR'] = str(nominatim_env.sqllib_dir)
env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = nominatim_env.module_dir
if not env['NOMINATIM_OSM2PGSQL_BINARY']:
env['NOMINATIM_OSM2PGSQL_BINARY'] = nominatim_env.osm2pgsql_path
from ..db.utils import execute_file
-def update_postcodes(conn, datadir):
+def update_postcodes(conn, sql_dir):
""" Recalculate postcode centroids and add, remove and update entries in the
location_postcode table. `conn` is an opne connection to the database.
"""
- execute_file(conn, datadir / 'sql' / 'update-postcodes.sql')
+ execute_file(conn, sql_dir / 'update-postcodes.sql')
-def recompute_word_counts(conn, datadir):
+def recompute_word_counts(conn, sql_dir):
""" Compute the frequency of full-word search terms.
"""
- execute_file(conn, datadir / 'sql' / 'words_from_search_name.sql')
+ execute_file(conn, sql_dir / 'words_from_search_name.sql')
def _add_address_level_rows_from_entry(rows, entry):
return replace_partition_string(sql, sorted(partitions))
-def create_functions(conn, config, data_dir,
+def create_functions(conn, config, sql_dir,
enable_diff_updates=True, enable_debug=False):
""" (Re)create the PL/pgSQL functions.
"""
- sql_dir = data_dir / 'sql'
-
sql = _get_standard_function_sql(conn, config, sql_dir,
enable_diff_updates, enable_debug)
sql += _get_partition_function_sql(conn, sql_dir)
self.test_env['NOMINATIM_IMPORT_STYLE'] = 'full'
self.test_env['NOMINATIM_USE_US_TIGER_DATA'] = 'yes'
self.test_env['NOMINATIM_DATADIR'] = self.src_dir
+ self.test_env['NOMINATIM_SQLDIR'] = self.src_dir / 'lib-sql'
self.test_env['NOMINATIM_BINDIR'] = self.src_dir / 'utils'
- self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.build_dir / 'module'
+ self.test_env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = self.build_dir / 'module'
self.test_env['NOMINATIM_OSM2PGSQL_BINARY'] = self.build_dir / 'osm2pgsql' / 'osm2pgsql'
self.test_env['NOMINATIM_NOMINATIM_TOOL'] = self.build_dir / 'nominatim'
if self.server_module_path:
self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.server_module_path
+ else:
+ # avoid module being copied into the temporary environment
+ self.test_env['NOMINATIM_DATABASE_MODULE_PATH'] = self.build_dir / 'module'
if self.website_dir is not None:
self.website_dir.cleanup()
from nominatim.db.connection import connect
from nominatim.tools.refresh import _get_standard_function_sql, _get_partition_function_sql
-SQL_DIR = (Path(__file__) / '..' / '..' / '..' / 'sql').resolve()
+SQL_DIR = (Path(__file__) / '..' / '..' / '..' / 'lib-sql').resolve()
@pytest.fixture
def db(temp_db):