1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 SQLAlchemy definitions for all tables used by the frontend.
10 import sqlalchemy as sa
12 import nominatim.db.sqlalchemy_functions #pylint: disable=unused-import
13 from nominatim.db.sqlalchemy_types import Geometry, KeyValueStore, IntArray
15 #pylint: disable=too-many-instance-attributes
17 """ Data class that holds the tables of the Nominatim database.
19 This schema strictly reflects the read-access view of the database.
20 Any data used for updates only will not be visible.
23 def __init__(self, meta: sa.MetaData) -> None:
26 self.import_status = sa.Table('import_status', meta,
27 sa.Column('lastimportdate', sa.DateTime(True), nullable=False),
28 sa.Column('sequence_id', sa.Integer),
29 sa.Column('indexed', sa.Boolean))
31 self.properties = sa.Table('nominatim_properties', meta,
32 sa.Column('property', sa.Text, nullable=False),
33 sa.Column('value', sa.Text))
35 self.placex = sa.Table('placex', meta,
36 sa.Column('place_id', sa.BigInteger, nullable=False),
37 sa.Column('parent_place_id', sa.BigInteger),
38 sa.Column('linked_place_id', sa.BigInteger),
39 sa.Column('importance', sa.Float),
40 sa.Column('indexed_date', sa.DateTime),
41 sa.Column('rank_address', sa.SmallInteger),
42 sa.Column('rank_search', sa.SmallInteger),
43 sa.Column('indexed_status', sa.SmallInteger),
44 sa.Column('osm_type', sa.String(1), nullable=False),
45 sa.Column('osm_id', sa.BigInteger, nullable=False),
46 sa.Column('class', sa.Text, nullable=False, key='class_'),
47 sa.Column('type', sa.Text, nullable=False),
48 sa.Column('admin_level', sa.SmallInteger),
49 sa.Column('name', KeyValueStore),
50 sa.Column('address', KeyValueStore),
51 sa.Column('extratags', KeyValueStore),
52 sa.Column('geometry', Geometry, nullable=False),
53 sa.Column('wikipedia', sa.Text),
54 sa.Column('country_code', sa.String(2)),
55 sa.Column('housenumber', sa.Text),
56 sa.Column('postcode', sa.Text),
57 sa.Column('centroid', Geometry))
59 self.addressline = sa.Table('place_addressline', meta,
60 sa.Column('place_id', sa.BigInteger),
61 sa.Column('address_place_id', sa.BigInteger),
62 sa.Column('distance', sa.Float),
63 sa.Column('fromarea', sa.Boolean),
64 sa.Column('isaddress', sa.Boolean))
66 self.postcode = sa.Table('location_postcode', meta,
67 sa.Column('place_id', sa.BigInteger),
68 sa.Column('parent_place_id', sa.BigInteger),
69 sa.Column('rank_search', sa.SmallInteger),
70 sa.Column('rank_address', sa.SmallInteger),
71 sa.Column('indexed_status', sa.SmallInteger),
72 sa.Column('indexed_date', sa.DateTime),
73 sa.Column('country_code', sa.String(2)),
74 sa.Column('postcode', sa.Text),
75 sa.Column('geometry', Geometry))
77 self.osmline = sa.Table('location_property_osmline', meta,
78 sa.Column('place_id', sa.BigInteger, nullable=False),
79 sa.Column('osm_id', sa.BigInteger),
80 sa.Column('parent_place_id', sa.BigInteger),
81 sa.Column('indexed_date', sa.DateTime),
82 sa.Column('startnumber', sa.Integer),
83 sa.Column('endnumber', sa.Integer),
84 sa.Column('step', sa.SmallInteger),
85 sa.Column('indexed_status', sa.SmallInteger),
86 sa.Column('linegeo', Geometry),
87 sa.Column('address', KeyValueStore),
88 sa.Column('postcode', sa.Text),
89 sa.Column('country_code', sa.String(2)))
91 self.country_name = sa.Table('country_name', meta,
92 sa.Column('country_code', sa.String(2)),
93 sa.Column('name', KeyValueStore),
94 sa.Column('derived_name', KeyValueStore),
95 sa.Column('partition', sa.Integer))
97 self.country_grid = sa.Table('country_osm_grid', meta,
98 sa.Column('country_code', sa.String(2)),
99 sa.Column('area', sa.Float),
100 sa.Column('geometry', Geometry))
102 # The following tables are not necessarily present.
103 self.search_name = sa.Table('search_name', meta,
104 sa.Column('place_id', sa.BigInteger),
105 sa.Column('importance', sa.Float),
106 sa.Column('search_rank', sa.SmallInteger),
107 sa.Column('address_rank', sa.SmallInteger),
108 sa.Column('name_vector', IntArray),
109 sa.Column('nameaddress_vector', IntArray),
110 sa.Column('country_code', sa.String(2)),
111 sa.Column('centroid', Geometry))
113 self.tiger = sa.Table('location_property_tiger', meta,
114 sa.Column('place_id', sa.BigInteger),
115 sa.Column('parent_place_id', sa.BigInteger),
116 sa.Column('startnumber', sa.Integer),
117 sa.Column('endnumber', sa.Integer),
118 sa.Column('step', sa.SmallInteger),
119 sa.Column('linegeo', Geometry),
120 sa.Column('postcode', sa.Text))