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.
12 from nominatim.tools.exec_utils import run_legacy_script
14 # Do not repeat documentation of subcommand classes.
15 # pylint: disable=C0111
16 # Using non-top-level imports to avoid eventually unused imports.
17 # pylint: disable=E0012,C0415
19 LOG = logging.getLogger()
23 Analyse and maintain the database.
28 group = parser.add_argument_group('Admin tasks')
29 objs = group.add_mutually_exclusive_group(required=True)
30 objs.add_argument('--warm', action='store_true',
31 help='Warm database caches for search and reverse queries')
32 objs.add_argument('--check-database', action='store_true',
33 help='Check that the database is complete and operational')
34 objs.add_argument('--migrate', action='store_true',
35 help='Migrate the database to a new software version')
36 objs.add_argument('--analyse-indexing', action='store_true',
37 help='Print performance analysis of the indexing process')
38 group = parser.add_argument_group('Arguments for cache warming')
39 group.add_argument('--search-only', action='store_const', dest='target',
41 help="Only pre-warm tables for search queries")
42 group.add_argument('--reverse-only', action='store_const', dest='target',
44 help="Only pre-warm tables for reverse queries")
45 group = parser.add_argument_group('Arguments for index anaysis')
46 mgroup = group.add_mutually_exclusive_group()
47 mgroup.add_argument('--osm-id', type=str,
48 help='Analyse indexing of the given OSM object')
49 mgroup.add_argument('--place-id', type=int,
50 help='Analyse indexing of the given Nominatim object')
55 return AdminFuncs._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)
78 LOG.warning('Warming database caches')
80 if args.target == 'reverse':
81 params.append('--reverse-only')
82 if args.target == 'search':
83 params.append('--search-only')
84 return run_legacy_script(*params, nominatim_env=args)