X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/57db5819efb1eac7497aca2dbdb2493a67bd33f9..7a874d5b97f65dc1f5a267fd53cc73c2cd5246b6:/nominatim/clicmd/transition.py diff --git a/nominatim/clicmd/transition.py b/nominatim/clicmd/transition.py index de4e16ca..c9341f49 100644 --- a/nominatim/clicmd/transition.py +++ b/nominatim/clicmd/transition.py @@ -35,8 +35,16 @@ class AdminTransition: help='Import a osm file') group.add_argument('--load-data', action='store_true', help='Copy data to live tables from import table') + group.add_argument('--create-tables', action='store_true', + help='Create main tables') + group.add_argument('--create-partition-tables', action='store_true', + help='Create required partition tables') group.add_argument('--index', action='store_true', help='Index the data') + group.add_argument('--create-search-indices', action='store_true', + help='Create additional indices required for search and update') + group.add_argument('--create-country-names', action='store_true', + help='Create search index for default country names.') group = parser.add_argument_group('Options') group.add_argument('--no-partitions', action='store_true', help='Do not partition search indices') @@ -48,10 +56,17 @@ class AdminTransition: help='Size of cache to be used by osm2pgsql (in MB)') group.add_argument('--no-analyse', action='store_true', help='Do not perform analyse operations during index') + group.add_argument('--ignore-errors', action='store_true', + help="Ignore certain erros on import.") + group.add_argument('--reverse-only', action='store_true', + help='Do not create search tables and indexes') + group.add_argument('--tiger-data', metavar='FILE', + help='File to import') @staticmethod - def run(args): - from ..tools import database_import + def run(args): # pylint: disable=too-many-statements + from ..tools import database_import, tiger_data + from ..tools import refresh if args.create_db: LOG.warning('Create DB') @@ -59,12 +74,12 @@ class AdminTransition: if args.setup_db: LOG.warning('Setup DB') - mpath = database_import.install_module(args.module_dir, args.project_dir, - args.config.DATABASE_MODULE_PATH) with connect(args.config.get_libpq_dsn()) as conn: database_import.setup_extensions(conn) - database_import.check_module_dir_path(conn, mpath) + database_import.install_module(args.module_dir, args.project_dir, + args.config.DATABASE_MODULE_PATH, + conn=conn) database_import.import_base_data(args.config.get_libpq_dsn(), args.data_dir, args.no_partitions) @@ -75,7 +90,22 @@ class AdminTransition: raise UsageError('Missing required --osm-file argument') database_import.import_osm_data(Path(args.osm_file), args.osm2pgsql_options(0, 1), - drop=args.drop) + drop=args.drop, + ignore_errors=args.ignore_errors) + + if args.create_tables: + LOG.warning('Create Tables') + with connect(args.config.get_libpq_dsn()) as conn: + database_import.create_tables(conn, args.config, args.sqllib_dir, args.reverse_only) + refresh.load_address_levels_from_file(conn, Path(args.config.ADDRESS_LEVEL_CONFIG)) + refresh.create_functions(conn, args.config, args.sqllib_dir, + enable_diff_updates=False) + database_import.create_table_triggers(conn, args.config, args.sqllib_dir) + + if args.create_partition_tables: + LOG.warning('Create Partition Tables') + with connect(args.config.get_libpq_dsn()) as conn: + database_import.create_partition_tables(conn, args.config, args.sqllib_dir) if args.load_data: LOG.warning('Load data') @@ -88,7 +118,7 @@ class AdminTransition: with connect(args.config.get_libpq_dsn()) as conn: try: status.set_status(conn, status.compute_database_date(conn)) - except Exception as exc: # pylint: disable=bare-except + except Exception as exc: # pylint: disable=broad-except LOG.error('Cannot determine date of database: %s', exc) if args.index: @@ -96,3 +126,21 @@ class AdminTransition: from ..indexer.indexer import Indexer indexer = Indexer(args.config.get_libpq_dsn(), args.threads or 1) indexer.index_full() + + if args.create_search_indices: + LOG.warning('Create Search indices') + with connect(args.config.get_libpq_dsn()) as conn: + database_import.create_search_indices(conn, args.config, args.sqllib_dir, args.drop) + + if args.tiger_data: + LOG.warning('Tiger data') + tiger_data.add_tiger_data(args.config.get_libpq_dsn(), + args.tiger_data, + args.threads or 1, + args.config, + args.sqllib_dir) + + if args.create_country_names: + LOG.warning('Create search index for default country names.') + with connect(args.config.get_libpq_dsn()) as conn: + database_import.create_country_names(conn, args.config)