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 SQLAlchemy definitions for all tables used by the frontend.
10 import sqlalchemy as sa
12 from .sqlalchemy_types import Geometry, KeyValueStore, IntArray
14 #pylint: disable=too-many-instance-attributes
16 """ Data class that holds the tables of the Nominatim database.
18 This schema strictly reflects the read-access view of the database.
19 Any data used for updates only will not be visible.
22 def __init__(self, meta: sa.MetaData) -> None:
25 self.import_status = sa.Table('import_status', meta,
26 sa.Column('lastimportdate', sa.DateTime(True), nullable=False),
27 sa.Column('sequence_id', sa.Integer),
28 sa.Column('indexed', sa.Boolean))
30 self.properties = sa.Table('nominatim_properties', meta,
31 sa.Column('property', sa.Text, nullable=False),
32 sa.Column('value', sa.Text))
34 self.placex = sa.Table('placex', meta,
35 sa.Column('place_id', sa.BigInteger, nullable=False),
36 sa.Column('parent_place_id', sa.BigInteger),
37 sa.Column('linked_place_id', sa.BigInteger),
38 sa.Column('importance', sa.Float),
39 sa.Column('indexed_date', sa.DateTime),
40 sa.Column('rank_address', sa.SmallInteger),
41 sa.Column('rank_search', sa.SmallInteger),
42 sa.Column('indexed_status', sa.SmallInteger),
43 sa.Column('osm_type', sa.String(1), nullable=False),
44 sa.Column('osm_id', sa.BigInteger, nullable=False),
45 sa.Column('class', sa.Text, nullable=False, key='class_'),
46 sa.Column('type', sa.Text, nullable=False),
47 sa.Column('admin_level', sa.SmallInteger),
48 sa.Column('name', KeyValueStore),
49 sa.Column('address', KeyValueStore),
50 sa.Column('extratags', KeyValueStore),
51 sa.Column('geometry', Geometry, nullable=False),
52 sa.Column('wikipedia', sa.Text),
53 sa.Column('country_code', sa.String(2)),
54 sa.Column('housenumber', sa.Text),
55 sa.Column('postcode', sa.Text),
56 sa.Column('centroid', Geometry))
58 self.addressline = sa.Table('place_addressline', meta,
59 sa.Column('place_id', sa.BigInteger),
60 sa.Column('address_place_id', sa.BigInteger),
61 sa.Column('distance', sa.Float),
62 sa.Column('fromarea', sa.Boolean),
63 sa.Column('isaddress', sa.Boolean))
65 self.postcode = sa.Table('location_postcode', meta,
66 sa.Column('place_id', sa.BigInteger),
67 sa.Column('parent_place_id', sa.BigInteger),
68 sa.Column('rank_search', sa.SmallInteger),
69 sa.Column('rank_address', sa.SmallInteger),
70 sa.Column('indexed_status', sa.SmallInteger),
71 sa.Column('indexed_date', sa.DateTime),
72 sa.Column('country_code', sa.String(2)),
73 sa.Column('postcode', sa.Text),
74 sa.Column('geometry', Geometry))
76 self.osmline = sa.Table('location_property_osmline', meta,
77 sa.Column('place_id', sa.BigInteger, nullable=False),
78 sa.Column('osm_id', sa.BigInteger),
79 sa.Column('parent_place_id', sa.BigInteger),
80 sa.Column('indexed_date', sa.DateTime),
81 sa.Column('startnumber', sa.Integer),
82 sa.Column('endnumber', sa.Integer),
83 sa.Column('step', sa.SmallInteger),
84 sa.Column('indexed_status', sa.SmallInteger),
85 sa.Column('linegeo', Geometry),
86 sa.Column('address', KeyValueStore),
87 sa.Column('postcode', sa.Text),
88 sa.Column('country_code', sa.String(2)))
90 self.country_name = sa.Table('country_name', meta,
91 sa.Column('country_code', sa.String(2)),
92 sa.Column('name', KeyValueStore),
93 sa.Column('derived_name', KeyValueStore),
94 sa.Column('partition', sa.Integer))
96 self.country_grid = sa.Table('country_osm_grid', meta,
97 sa.Column('country_code', sa.String(2)),
98 sa.Column('area', sa.Float),
99 sa.Column('geometry', Geometry))
101 # The following tables are not necessarily present.
102 self.search_name = sa.Table('search_name', meta,
103 sa.Column('place_id', sa.BigInteger),
104 sa.Column('importance', sa.Float),
105 sa.Column('search_rank', sa.SmallInteger),
106 sa.Column('address_rank', sa.SmallInteger),
107 sa.Column('name_vector', IntArray),
108 sa.Column('nameaddress_vector', IntArray),
109 sa.Column('country_code', sa.String(2)),
110 sa.Column('centroid', Geometry))
112 self.tiger = sa.Table('location_property_tiger', meta,
113 sa.Column('place_id', sa.BigInteger),
114 sa.Column('parent_place_id', sa.BigInteger),
115 sa.Column('startnumber', sa.Integer),
116 sa.Column('endnumber', sa.Integer),
117 sa.Column('step', sa.SmallInteger),
118 sa.Column('linegeo', Geometry),
119 sa.Column('postcode', sa.Text))