]> git.openstreetmap.org Git - nominatim.git/commitdiff
rename sql directory to lib-sql
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 9 Feb 2021 14:26:56 +0000 (15:26 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 9 Feb 2021 14:26:56 +0000 (15:26 +0100)
Also introduces a separate constant for the sql directory, so that
it can be put separately from the rest of the data if required.

35 files changed:
cmake/script.tmpl
cmake/tool.tmpl
lib-php/lib.php
lib-php/setup/SetupClass.php
lib-sql/aux_tables.sql [moved from sql/aux_tables.sql with 100% similarity]
lib-sql/functions/address_lookup.sql [moved from sql/functions/address_lookup.sql with 100% similarity]
lib-sql/functions/aux_property.sql [moved from sql/functions/aux_property.sql with 100% similarity]
lib-sql/functions/importance.sql [moved from sql/functions/importance.sql with 100% similarity]
lib-sql/functions/interpolation.sql [moved from sql/functions/interpolation.sql with 100% similarity]
lib-sql/functions/normalization.sql [moved from sql/functions/normalization.sql with 100% similarity]
lib-sql/functions/place_triggers.sql [moved from sql/functions/place_triggers.sql with 100% similarity]
lib-sql/functions/placex_triggers.sql [moved from sql/functions/placex_triggers.sql with 100% similarity]
lib-sql/functions/postcode_triggers.sql [moved from sql/functions/postcode_triggers.sql with 100% similarity]
lib-sql/functions/ranking.sql [moved from sql/functions/ranking.sql with 100% similarity]
lib-sql/functions/utils.sql [moved from sql/functions/utils.sql with 100% similarity]
lib-sql/indices.src.sql [moved from sql/indices.src.sql with 100% similarity]
lib-sql/indices_search.src.sql [moved from sql/indices_search.src.sql with 100% similarity]
lib-sql/indices_updates.src.sql [moved from sql/indices_updates.src.sql with 100% similarity]
lib-sql/partition-functions.src.sql [moved from sql/partition-functions.src.sql with 100% similarity]
lib-sql/partition-tables.src.sql [moved from sql/partition-tables.src.sql with 100% similarity]
lib-sql/postcode_tables.sql [moved from sql/postcode_tables.sql with 100% similarity]
lib-sql/table-triggers.sql [moved from sql/table-triggers.sql with 100% similarity]
lib-sql/tables.sql [moved from sql/tables.sql with 100% similarity]
lib-sql/tiger_import_finish.sql [moved from sql/tiger_import_finish.sql with 100% similarity]
lib-sql/tiger_import_start.sql [moved from sql/tiger_import_start.sql with 100% similarity]
lib-sql/update-postcodes.sql [moved from sql/update-postcodes.sql with 100% similarity]
lib-sql/words.sql [moved from sql/words.sql with 100% similarity]
lib-sql/words_from_search_name.sql [moved from sql/words_from_search_name.sql with 100% similarity]
nominatim/cli.py
nominatim/clicmd/refresh.py
nominatim/clicmd/replication.py
nominatim/tools/exec_utils.py
nominatim/tools/refresh.py
test/bdd/steps/nominatim_environment.py
test/python/test_tools_refresh_create_functions.py

index 5fdfe5424605aebb63c0bb931ca14188ffa8ca3e..f0fa2118942e36f4d3aba50e4f7bdef72f16844d 100755 (executable)
@@ -6,6 +6,7 @@ require('@CMAKE_SOURCE_DIR@/lib-php/dotenv_loader.php');
 @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';
index 67d57ad7e270a11c5cad5b8e304208bdbbb4fa69..76f80924c3a041e3a1ac6147c44a8d52ffca9a55 100755 (executable)
@@ -11,5 +11,6 @@ from nominatim import cli
 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@'))
index a02fefd055fa121097a38e55b07fbb069bed2d3c..04b9bf86b1634e24c7f8a08d05b13536647733a0 100644 (file)
@@ -8,6 +8,7 @@ function loadSettings($sProjectDir)
     // 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']);
 }
 
index 2a49828733a2ff97c897b97dbe85deb724be3b5f..80dcabb24c994b8064bea34820b72f2bc1c0cf43 100755 (executable)
@@ -253,7 +253,7 @@ class SetupFunctions
     {
         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);
@@ -269,7 +269,7 @@ class SetupFunctions
     {
         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);
@@ -279,7 +279,7 @@ class SetupFunctions
     {
         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);
@@ -442,7 +442,7 @@ class SetupFunctions
             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);
@@ -496,7 +496,7 @@ class SetupFunctions
         }
 
         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);
@@ -505,7 +505,7 @@ class SetupFunctions
     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)) {
@@ -621,12 +621,12 @@ class SetupFunctions
             $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);
 
similarity index 100%
rename from sql/aux_tables.sql
rename to lib-sql/aux_tables.sql
similarity index 100%
rename from sql/indices.src.sql
rename to lib-sql/indices.src.sql
similarity index 100%
rename from sql/tables.sql
rename to lib-sql/tables.sql
similarity index 100%
rename from sql/words.sql
rename to lib-sql/words.sql
index 845b1451db6455d15b661637e6311d0e82b5fc16..784250e8f6272b489afd26ce0a8c4771c7ce85a5 100644 (file)
@@ -68,7 +68,8 @@ class CommandlineParser:
             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()
 
index 4e2ad1dbe56aa108450cf3c4b1afa2523fce002a..baff9b6acc0c38bb94cbe6c3f36dfdbba542316e 100644 (file)
@@ -51,7 +51,7 @@ class UpdateRefresh:
         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:
@@ -70,7 +70,7 @@ class UpdateRefresh:
         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()
 
index 554dbc4ff93f79c74293abdd389143270ee9eb79..4852c8b1390a45382c70fe79645037f707dbb523 100644 (file)
@@ -66,7 +66,7 @@ class UpdateReplication:
         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
index 45853163a795e662757cdcdad791c29be1d21c48..502fb4fe454ec4f143983fb82fd69c48e57320a5 100644 (file)
@@ -26,6 +26,7 @@ def run_legacy_script(script, *args, nominatim_env=None, throw_on_fail=False):
     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
index 5fbb07f86f53ece24ec2b5a01daeec816b970010..1fcb1577302d1fcca188683426ce6a1dfa48efc1 100644 (file)
@@ -8,17 +8,17 @@ from psycopg2.extras import execute_values
 
 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):
@@ -153,12 +153,10 @@ def _get_partition_function_sql(conn, sql_dir):
 
     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)
index 892d21e9af8b4278838fcfa614f1439ce042f0ea..6dcaf64a674f9f302576827a7153caba43861192 100644 (file)
@@ -88,13 +88,17 @@ class NominatimEnvironment:
         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()
index 4807e64f12e1b4d37c918d9ea5ed6b2179af8c77..d219d74864f4af628e40c9a66738213ecd854ad4 100644 (file)
@@ -7,7 +7,7 @@ import pytest
 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):