X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/5226cd2a0bc2baa06d32752f29d4e1f3c632dd13..a413aae8a3962be4d623844d867604df68a9a211:/nominatim/db/sqlalchemy_schema.py?ds=inline diff --git a/nominatim/db/sqlalchemy_schema.py b/nominatim/db/sqlalchemy_schema.py index 17839168..550f1f12 100644 --- a/nominatim/db/sqlalchemy_schema.py +++ b/nominatim/db/sqlalchemy_schema.py @@ -14,6 +14,22 @@ from geoalchemy2 import Geometry from sqlalchemy.dialects.postgresql import HSTORE, ARRAY, JSONB from sqlalchemy.dialects.sqlite import JSON as sqlite_json +class PostgresTypes: + """ Type definitions for complex types as used in Postgres variants. + """ + Composite = HSTORE + Json = JSONB + IntArray = ARRAY(sa.Integer()) #pylint: disable=invalid-name + + +class SqliteTypes: + """ Type definitions for complex types as used in Postgres variants. + """ + Composite = sqlite_json + Json = sqlite_json + IntArray = sqlite_json + + #pylint: disable=too-many-instance-attributes class SearchTables: """ Data class that holds the tables of the Nominatim database. @@ -21,13 +37,9 @@ class SearchTables: def __init__(self, meta: sa.MetaData, engine_name: str) -> None: if engine_name == 'postgresql': - Composite: Any = HSTORE - Json: Any = JSONB - IntArray: Any = ARRAY(sa.Integer()) #pylint: disable=invalid-name + self.types: Any = PostgresTypes elif engine_name == 'sqlite': - Composite = sqlite_json - Json = sqlite_json - IntArray = sqlite_json + self.types = SqliteTypes else: raise ValueError("Only 'postgresql' and 'sqlite' engines are supported.") @@ -57,9 +69,9 @@ class SearchTables: sa.Column('class', sa.Text, nullable=False, key='class_'), sa.Column('type', sa.Text, nullable=False), sa.Column('admin_level', sa.SmallInteger), - sa.Column('name', Composite), - sa.Column('address', Composite), - sa.Column('extratags', Composite), + sa.Column('name', self.types.Composite), + sa.Column('address', self.types.Composite), + sa.Column('extratags', self.types.Composite), sa.Column('geometry', Geometry(srid=4326), nullable=False), sa.Column('wikipedia', sa.Text), sa.Column('country_code', sa.String(2)), @@ -97,21 +109,14 @@ class SearchTables: sa.Column('partition', sa.SmallInteger), sa.Column('indexed_status', sa.SmallInteger), sa.Column('linegeo', Geometry(srid=4326)), - sa.Column('address', Composite), + sa.Column('address', self.types.Composite), sa.Column('postcode', sa.Text), sa.Column('country_code', sa.String(2))) - self.word = sa.Table('word', meta, - sa.Column('word_id', sa.Integer), - sa.Column('word_token', sa.Text, nullable=False), - sa.Column('type', sa.Text, nullable=False), - sa.Column('word', sa.Text), - sa.Column('info', Json)) - self.country_name = sa.Table('country_name', meta, sa.Column('country_code', sa.String(2)), - sa.Column('name', Composite), - sa.Column('derived_name', Composite), + sa.Column('name', self.types.Composite), + sa.Column('derived_name', self.types.Composite), sa.Column('country_default_language_code', sa.Text), sa.Column('partition', sa.Integer)) @@ -126,8 +131,8 @@ class SearchTables: sa.Column('importance', sa.Float), sa.Column('search_rank', sa.SmallInteger), sa.Column('address_rank', sa.SmallInteger), - sa.Column('name_vector', IntArray, index=True), - sa.Column('nameaddress_vector', IntArray, index=True), + sa.Column('name_vector', self.types.IntArray, index=True), + sa.Column('nameaddress_vector', self.types.IntArray, index=True), sa.Column('country_code', sa.String(2)), sa.Column('centroid', Geometry(srid=4326)))