1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Implementation of the 'admin' subcommand.
13 from nominatim.tools.exec_utils import run_legacy_script
14 from nominatim.clicmd.args import NominatimArgs
16 # Do not repeat documentation of subcommand classes.
17 # pylint: disable=C0111
18 # Using non-top-level imports to avoid eventually unused imports.
19 # pylint: disable=E0012,C0415
21 LOG = logging.getLogger()
25 Analyse and maintain the database.
28 def add_args(self, parser: argparse.ArgumentParser) -> None:
29 group = parser.add_argument_group('Admin tasks')
30 objs = group.add_mutually_exclusive_group(required=True)
31 objs.add_argument('--warm', action='store_true',
32 help='Warm database caches for search and reverse queries')
33 objs.add_argument('--check-database', action='store_true',
34 help='Check that the database is complete and operational')
35 objs.add_argument('--migrate', action='store_true',
36 help='Migrate the database to a new software version')
37 objs.add_argument('--analyse-indexing', action='store_true',
38 help='Print performance analysis of the indexing process')
39 group = parser.add_argument_group('Arguments for cache warming')
40 group.add_argument('--search-only', action='store_const', dest='target',
42 help="Only pre-warm tables for search queries")
43 group.add_argument('--reverse-only', action='store_const', dest='target',
45 help="Only pre-warm tables for reverse queries")
46 group = parser.add_argument_group('Arguments for index anaysis')
47 mgroup = group.add_mutually_exclusive_group()
48 mgroup.add_argument('--osm-id', type=str,
49 help='Analyse indexing of the given OSM object')
50 mgroup.add_argument('--place-id', type=int,
51 help='Analyse indexing of the given Nominatim object')
53 def run(self, args: NominatimArgs) -> int:
55 return self._warm(args)
57 if args.check_database:
58 LOG.warning('Checking database')
59 from ..tools import check_database
60 return check_database.check_database(args.config)
62 if args.analyse_indexing:
63 LOG.warning('Analysing performance of indexing function')
64 from ..tools import admin
65 admin.analyse_indexing(args.config, osm_id=args.osm_id, place_id=args.place_id)
69 LOG.warning('Checking for necessary database migrations')
70 from ..tools import migration
71 return migration.migrate(args.config, args)
76 def _warm(self, args: NominatimArgs) -> int:
77 LOG.warning('Warming database caches')
79 if args.target == 'reverse':
80 params.append('--reverse-only')
81 if args.target == 'search':
82 params.append('--search-only')
83 return run_legacy_script(*params, nominatim_env=args)