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
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(
26 '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(
32 'nominatim_properties', meta,
33 sa.Column('property', sa.Text, nullable=False),
34 sa.Column('value', sa.Text))
36 self.placex = sa.Table(
38 sa.Column('place_id', sa.BigInteger, nullable=False),
39 sa.Column('parent_place_id', sa.BigInteger),
40 sa.Column('linked_place_id', sa.BigInteger),
41 sa.Column('importance', sa.Float),
42 sa.Column('indexed_date', sa.DateTime),
43 sa.Column('rank_address', sa.SmallInteger),
44 sa.Column('rank_search', sa.SmallInteger),
45 sa.Column('indexed_status', sa.SmallInteger),
46 sa.Column('osm_type', sa.String(1), nullable=False),
47 sa.Column('osm_id', sa.BigInteger, nullable=False),
48 sa.Column('class', sa.Text, nullable=False, key='class_'),
49 sa.Column('type', sa.Text, nullable=False),
50 sa.Column('admin_level', sa.SmallInteger),
51 sa.Column('name', KeyValueStore),
52 sa.Column('address', KeyValueStore),
53 sa.Column('extratags', KeyValueStore),
54 sa.Column('geometry', Geometry, nullable=False),
55 sa.Column('wikipedia', sa.Text),
56 sa.Column('country_code', sa.String(2)),
57 sa.Column('housenumber', sa.Text),
58 sa.Column('postcode', sa.Text),
59 sa.Column('centroid', Geometry))
61 self.addressline = sa.Table(
62 'place_addressline', meta,
63 sa.Column('place_id', sa.BigInteger),
64 sa.Column('address_place_id', sa.BigInteger),
65 sa.Column('distance', sa.Float),
66 sa.Column('fromarea', sa.Boolean),
67 sa.Column('isaddress', sa.Boolean))
69 self.postcode = sa.Table(
70 'location_postcode', meta,
71 sa.Column('place_id', sa.BigInteger),
72 sa.Column('parent_place_id', sa.BigInteger),
73 sa.Column('rank_search', sa.SmallInteger),
74 sa.Column('rank_address', sa.SmallInteger),
75 sa.Column('indexed_status', sa.SmallInteger),
76 sa.Column('indexed_date', sa.DateTime),
77 sa.Column('country_code', sa.String(2)),
78 sa.Column('postcode', sa.Text),
79 sa.Column('geometry', Geometry))
81 self.osmline = sa.Table(
82 'location_property_osmline', meta,
83 sa.Column('place_id', sa.BigInteger, nullable=False),
84 sa.Column('osm_id', sa.BigInteger),
85 sa.Column('parent_place_id', sa.BigInteger),
86 sa.Column('indexed_date', sa.DateTime),
87 sa.Column('startnumber', sa.Integer),
88 sa.Column('endnumber', sa.Integer),
89 sa.Column('step', sa.SmallInteger),
90 sa.Column('indexed_status', sa.SmallInteger),
91 sa.Column('linegeo', Geometry),
92 sa.Column('address', KeyValueStore),
93 sa.Column('postcode', sa.Text),
94 sa.Column('country_code', sa.String(2)))
96 self.country_name = sa.Table(
98 sa.Column('country_code', sa.String(2)),
99 sa.Column('name', KeyValueStore),
100 sa.Column('derived_name', KeyValueStore),
101 sa.Column('partition', sa.Integer))
103 self.country_grid = sa.Table(
104 'country_osm_grid', meta,
105 sa.Column('country_code', sa.String(2)),
106 sa.Column('area', sa.Float),
107 sa.Column('geometry', Geometry))
109 # The following tables are not necessarily present.
110 self.search_name = sa.Table(
112 sa.Column('place_id', sa.BigInteger),
113 sa.Column('importance', sa.Float),
114 sa.Column('search_rank', sa.SmallInteger),
115 sa.Column('address_rank', sa.SmallInteger),
116 sa.Column('name_vector', IntArray),
117 sa.Column('nameaddress_vector', IntArray),
118 sa.Column('country_code', sa.String(2)),
119 sa.Column('centroid', Geometry))
121 self.tiger = sa.Table(
122 'location_property_tiger', meta,
123 sa.Column('place_id', sa.BigInteger),
124 sa.Column('parent_place_id', sa.BigInteger),
125 sa.Column('startnumber', sa.Integer),
126 sa.Column('endnumber', sa.Integer),
127 sa.Column('step', sa.SmallInteger),
128 sa.Column('linegeo', Geometry),
129 sa.Column('postcode', sa.Text))