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 Functions for removing unnecessary data from the database.
10 from pathlib import Path
12 from psycopg2 import sql as pysql
28 def drop_update_tables(conn):
29 """ Drop all tables only necessary for updating the database from
32 parts = (pysql.SQL("(tablename LIKE {})").format(pysql.Literal(t)) for t in UPDATE_TABLES)
34 with conn.cursor() as cur:
35 cur.execute(pysql.SQL("SELECT tablename FROM pg_tables WHERE ")
36 + pysql.SQL(' or ').join(parts))
37 tables = [r[0] for r in cur]
40 cur.drop_table(table, cascade=True)
45 def drop_flatnode_file(fname):
46 """ Remove the flatnode file if it exists.