X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6e89310a9285f1ad15d8002bf68f578eada367a0..98c1b923fc090f830b7b3a575e3d08ba399bd870:/src/nominatim_db/tools/freeze.py?ds=inline diff --git a/src/nominatim_db/tools/freeze.py b/src/nominatim_db/tools/freeze.py index 2023bb8a..a308d0eb 100644 --- a/src/nominatim_db/tools/freeze.py +++ b/src/nominatim_db/tools/freeze.py @@ -10,9 +10,9 @@ Functions for removing unnecessary data from the database. from typing import Optional from pathlib import Path -from psycopg2 import sql as pysql +from psycopg import sql as pysql -from nominatim_core.db.connection import Connection +from ..db.connection import Connection, drop_tables, table_exists UPDATE_TABLES = [ 'address_levels', @@ -28,6 +28,7 @@ UPDATE_TABLES = [ 'wikipedia_%' ] + def drop_update_tables(conn: Connection) -> None: """ Drop all tables only necessary for updating the database from OSM replication data. @@ -39,9 +40,7 @@ def drop_update_tables(conn: Connection) -> None: + pysql.SQL(' or ').join(parts)) tables = [r[0] for r in cur] - for table in tables: - cur.drop_table(table, cascade=True) - + drop_tables(conn, *tables, cascade=True) conn.commit() @@ -51,8 +50,8 @@ def drop_flatnode_file(fpath: Optional[Path]) -> None: if fpath and fpath.exists(): fpath.unlink() + def is_frozen(conn: Connection) -> bool: """ Returns true if database is in a frozen state """ - - return conn.table_exists('place') is False + return table_exists(conn, 'place') is False