LocatieAdres   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 0
c 1
b 0
f 0
dl 0
loc 49
rs 10
1
# -*- coding: utf-8 -*-
2
from sqlalchemy import (
3
    Column,
4
    Integer,
5
    String,
6
    ForeignKey,
7
)
8
9
from oe_utils.data.models.meta import Base
10
11
12
class LocatieElement(Base):
13
    """
14
    A database table configuration object containing information about the location of a resource object.
15
16
    This object will not create the db table object.
17
    To create the table insert following code in the alembic migration file
18
19
    `alembic revision -m "<versie>"`
20
21
22
    from alembic import op
23
    import sqlalchemy as sa
24
25
26
    def upgrade():
27
        locatie_elementen = op.create_table('locatie_elementen',
28
                                        sa.Column('id', sa.Integer(), nullable=False),
29
                                        sa.Column('type', sa.String(length=250), nullable=False),
30
                                        sa.Column('resource_object_id', sa.Integer(), nullable=False),
31
                                        sa.Column('provincie_niscode', sa.Integer(), nullable=False),
32
                                        sa.Column('provincie_naam', sa.String(length=50), nullable=False),
33
                                        sa.Column('gemeente_niscode', sa.Integer(), nullable=False),
34
                                        sa.Column('gemeente_naam', sa.String(length=255), nullable=False),
35
                                        sa.Column('gemeente_crab_id', sa.Integer(), nullable=True),
36
                                        sa.Column('deelgemeente_niscode', sa.String(length=10), nullable=False),
37
                                        sa.Column('deelgemeente_naam', sa.String(length=255), nullable=False),
38
                                        sa.ForeignKeyConstraint(['resource_object_id'],
39
                                                                ['<resource>.id']),
40
                                        sa.PrimaryKeyConstraint('id', name='locatie_elementen_pk')
41
                                        )
42
43
        op.execute('GRANT SELECT, INSERT, UPDATE, DELETE ON locatie_elementen TO <user>_dml')
44
        op.execute('GRANT ALL ON locatie_elementen_id_seq TO <user>_dml')
45
46
47
    def downgrade():
48
        op.drop_table('locatie_elementen')
49
    """
50
    __tablename__ = 'locatie_elementen'
51
    id = Column(Integer, primary_key=True, autoincrement=True)
52
    type = Column(String(250))
53
    resource_object_id = Column(Integer)
54
    provincie_niscode = Column(Integer)
55
    provincie_naam = Column(String(50))
56
    gemeente_niscode = Column(Integer)
57
    gemeente_naam = Column(String(255))
58
    gemeente_crab_id = Column(Integer)
59
    deelgemeente_niscode = Column(String(10))
60
    deelgemeente_naam = Column(String(255))
61
62
    __mapper_args__ = {
63
        'polymorphic_identity': 'https://id.erfgoed.net/vocab/ontology#LocatieElement',
64
        'polymorphic_on': type
65
    }
66
67
68
class Perceel(LocatieElement):
69
    """
70
    A database table configuration object containing information about the location of a resource object.
71
    Perceel is a subclass of LocatieElement. Therefor the table locatie_elementen described in the class documentation
72
    of LocatieElement also needs to be created
73
74
    This object will not create the db table object.
75
    To create the table insert following code in the alembic migration file
76
77
    `alembic revision -m "<versie>"`
78
79
80
    from alembic import op
81
    import sqlalchemy as sa
82
83
    def upgrade():
84
        percelen = op.create_table('percelen',
85
                                sa.Column('id', sa.Integer(), nullable=False),
86
                                sa.Column('afdeling', sa.String(length=50), nullable=True),
87
                                sa.Column('sectie', sa.String(length=50), nullable=True),
88
                                sa.Column('perceel', sa.String(length=50), nullable=True),
89
                                sa.Column('capakey', sa.String(length=50), nullable=False),
90
                                sa.ForeignKeyConstraint(['id'], ['locatie_elementen.id']),
91
                                sa.PrimaryKeyConstraint('id', name='percelen_pk')
92
                                )
93
94
        op.execute('GRANT SELECT, INSERT, UPDATE, DELETE ON percelen TO <user>_dml')
95
96
97
    def downgrade():
98
        op.drop_table('percelen')
99
    """
100
    __tablename__ = 'percelen'
101
    id = Column(Integer, ForeignKey('locatie_elementen.id'), primary_key=True)
102
    afdeling = Column(String(50))
103
    sectie = Column(String(50))
104
    perceel = Column(String(50))
105
    capakey = Column(String(50))
106
107
    __mapper_args__ = {
108
        'polymorphic_identity': 'https://id.erfgoed.net/vocab/ontology#LocatieElementPerceel',
109
    }
110
111
112
class OpenbaarDomein(LocatieElement):
113
    """
114
    A database table configuration object containing information about the location of a resource object.
115
    OpenbaarDomein is a subclass of LocatieElement. Therefor the table locatie_elementen described in the
116
    class documentation of LocatieElement also needs to be created
117
118
    This object will not create the db table object.
119
    To create the table insert following code in the alembic migration file
120
121
    `alembic revision -m "<versie>"`
122
123
124
    from alembic import op
125
    import sqlalchemy as sa
126
127
    def upgrade():
128
        openbaredomeinen = op.create_table('openbaredomeinen',
129
                                       sa.Column('id', sa.Integer(), nullable=False),
130
                                       sa.Column('omschrijving', sa.String(length=250), nullable=True),
131
                                       sa.ForeignKeyConstraint(['id'], ['locatie_elementen.id']),
132
                                       sa.PrimaryKeyConstraint('id', name='openbaredomeinen_pk')
133
                                       )
134
135
        op.execute('GRANT SELECT, INSERT, UPDATE, DELETE ON openbaredomeinen TO <user>_dml')
136
137
138
    def downgrade():
139
        op.drop_table('openbaredomeinen')
140
    """
141
    __tablename__ = 'openbaredomeinen'
142
    id = Column(Integer, ForeignKey('locatie_elementen.id'), primary_key=True)
143
    omschrijving = Column(String(250))
144
145
    __mapper_args__ = {
146
        'polymorphic_identity': 'https://id.erfgoed.net/vocab/ontology#LocatieElementOpenbaarDomein',
147
    }
148
149
150
class LocatieAdres(LocatieElement):
151
    """
152
    A database table configuration object containing information about the location of a resource object.
153
    LocatieAdres is a subclass of LocatieElement. Therefor the table locatie_elementen described in the
154
    class documentation of LocatieElement also needs to be created
155
156
    This object will not create the db table object.
157
    To create the table insert following code in the alembic migration file
158
159
    `alembic revision -m "<versie>"`
160
161
162
    from alembic import op
163
    import sqlalchemy as sa
164
165
    def upgrade():
166
        locatieadressen = op.create_table('locatieadressen',
167
                                      sa.Column('id', sa.Integer(), nullable=False),
168
                                      sa.Column('straat_id', sa.Integer(), nullable=True),
169
                                      sa.Column('straat', sa.String(length=100), nullable=True),
170
                                      sa.Column('huisnummer_id', sa.Integer(), nullable=True),
171
                                      sa.Column('huisnummer', sa.String(length=20), nullable=True),
172
                                      sa.Column('subadres_id', sa.Integer(), nullable=True),
173
                                      sa.Column('subadres', sa.String(length=20), nullable=True),
174
                                      sa.Column('postcode', sa.String(length=20), nullable=True),
175
                                      sa.Column('land', sa.String(length=100), nullable=True),
176
                                      sa.ForeignKeyConstraint(['id'], ['locatie_elementen.id']),
177
                                      sa.PrimaryKeyConstraint('id', name='locatieadressen_pk')
178
                                      )
179
180
        op.execute('GRANT SELECT, INSERT, UPDATE, DELETE ON locatieadressen TO <user>_dml')
181
182
183
    def downgrade():
184
        op.drop_table('locatieadressen')
185
    """
186
    __tablename__ = 'locatieadressen'
187
    id = Column(Integer, ForeignKey('locatie_elementen.id'), primary_key=True)
188
    straat_id = Column(Integer)
189
    straat = Column(String(100))
190
    huisnummer_id = Column(Integer)
191
    huisnummer = Column(String(20))
192
    subadres_id = Column(Integer)
193
    subadres = Column(String(20))
194
    postcode = Column(String(20))
195
    land = Column(String(100))
196
197
    __mapper_args__ = {
198
        'polymorphic_identity': 'https://id.erfgoed.net/vocab/ontology#LocatieElementAdres',
199
    }
200