1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2024 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 typing import Optional
 
  11 from pathlib import Path
 
  13 from psycopg import sql as pysql
 
  15 from ..db.connection import Connection, drop_tables, table_exists
 
  32 def drop_update_tables(conn: Connection) -> None:
 
  33     """ Drop all tables only necessary for updating the database from
 
  36     parts = (pysql.SQL("(tablename LIKE {})").format(pysql.Literal(t)) for t in UPDATE_TABLES)
 
  38     with conn.cursor() as cur:
 
  39         cur.execute(pysql.SQL("SELECT tablename FROM pg_tables WHERE ")
 
  40                     + pysql.SQL(' or ').join(parts))
 
  41         tables = [r[0] for r in cur]
 
  43     drop_tables(conn, *tables, cascade=True)
 
  47 def drop_flatnode_file(fpath: Optional[Path]) -> None:
 
  48     """ Remove the flatnode file if it exists.
 
  50     if fpath and fpath.exists():
 
  54 def is_frozen(conn: Connection) -> bool:
 
  55     """ Returns true if database is in a frozen state
 
  57     return table_exists(conn, 'place') is False