3924a7ad2f8_init.upgrade()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 219
Code Lines 178

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 178
dl 0
loc 219
rs 7
c 0
b 0
f 0
cc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
"""init
2
3
Revision ID: 3924a7ad2f8
4
Revises: None
5
Create Date: 2014-04-10 15:37:26.804103
6
7
"""
8
import sqlalchemy as sa
9
from alembic import op
10
11
# revision identifiers, used by Alembic.
12
revision = "3924a7ad2f8"
13
down_revision = None
14
branch_labels = ("atramhasis",)
15
16
17
def upgrade():
18
    op.create_table(
19
        "labeltype",
20
        sa.Column("name", sa.String(length=20), nullable=False),
21
        sa.Column("description", sa.Text(), nullable=True),
22
        sa.PrimaryKeyConstraint("name"),
23
    )
24
    op.create_table(
25
        "language",
26
        sa.Column("id", sa.String(length=64), nullable=False),
27
        sa.Column("name", sa.String(length=255), nullable=True),
28
        sa.PrimaryKeyConstraint("id"),
29
    )
30
    op.create_table(
31
        "conceptscheme",
32
        sa.Column("id", sa.Integer(), nullable=False),
33
        sa.Column("uri", sa.String(length=512), nullable=True),
34
        sa.PrimaryKeyConstraint("id"),
35
    )
36
    op.create_table(
37
        "notetype",
38
        sa.Column("name", sa.String(length=20), nullable=False),
39
        sa.Column("description", sa.Text(), nullable=True),
40
        sa.PrimaryKeyConstraint("name"),
41
    )
42
    op.create_table(
43
        "label",
44
        sa.Column("id", sa.Integer(), nullable=False),
45
        sa.Column("label", sa.String(length=512), nullable=False),
46
        sa.Column("labeltype_id", sa.String(length=20), nullable=False),
47
        sa.Column("language_id", sa.String(length=64), nullable=True),
48
        sa.ForeignKeyConstraint(
49
            ["labeltype_id"],
50
            ["labeltype.name"],
51
        ),
52
        sa.ForeignKeyConstraint(
53
            ["language_id"],
54
            ["language.id"],
55
        ),
56
        sa.PrimaryKeyConstraint("id"),
57
    )
58
    op.create_index("ix_label_labeltype_id", "label", ["labeltype_id"], unique=False)
59
    op.create_index("ix_label_language_id", "label", ["language_id"], unique=False)
60
    op.create_table(
61
        "note",
62
        sa.Column("id", sa.Integer(), nullable=False),
63
        sa.Column("note", sa.Text(), nullable=False),
64
        sa.Column("notetype_id", sa.String(length=20), nullable=False),
65
        sa.Column("language_id", sa.String(length=64), nullable=True),
66
        sa.ForeignKeyConstraint(
67
            ["language_id"],
68
            ["language.id"],
69
        ),
70
        sa.ForeignKeyConstraint(
71
            ["notetype_id"],
72
            ["notetype.name"],
73
        ),
74
        sa.PrimaryKeyConstraint("id"),
75
    )
76
    op.create_index("ix_note_language_id", "note", ["language_id"], unique=False)
77
    op.create_index("ix_note_notetype_id", "note", ["notetype_id"], unique=False)
78
    op.create_table(
79
        "concept",
80
        sa.Column("id", sa.Integer(), nullable=False),
81
        sa.Column("type", sa.String(length=30), nullable=True),
82
        sa.Column("concept_id", sa.Integer(), nullable=False),
83
        sa.Column("uri", sa.String(length=512), nullable=True),
84
        sa.Column("conceptscheme_id", sa.Integer(), nullable=False),
85
        sa.ForeignKeyConstraint(
86
            ["conceptscheme_id"],
87
            ["conceptscheme.id"],
88
        ),
89
        sa.PrimaryKeyConstraint("id"),
90
    )
91
    op.create_index("ix_concept_concept_id", "concept", ["concept_id"], unique=False)
92
    op.create_index(
93
        "ix_concept_conceptscheme_id", "concept", ["conceptscheme_id"], unique=False
94
    )
95
    op.create_table(
96
        "collection_concept",
97
        sa.Column("collection_id", sa.Integer(), nullable=False),
98
        sa.Column("concept_id", sa.Integer(), nullable=False),
99
        sa.ForeignKeyConstraint(
100
            ["collection_id"],
101
            ["concept.id"],
102
        ),
103
        sa.ForeignKeyConstraint(
104
            ["concept_id"],
105
            ["concept.id"],
106
        ),
107
        sa.PrimaryKeyConstraint("collection_id", "concept_id"),
108
    )
109
    op.create_table(
110
        "conceptscheme_note",
111
        sa.Column("conceptscheme_id", sa.Integer(), nullable=False),
112
        sa.Column("note_id", sa.Integer(), nullable=False),
113
        sa.ForeignKeyConstraint(
114
            ["conceptscheme_id"],
115
            ["conceptscheme.id"],
116
        ),
117
        sa.ForeignKeyConstraint(
118
            ["note_id"],
119
            ["note.id"],
120
        ),
121
        sa.PrimaryKeyConstraint("conceptscheme_id", "note_id"),
122
    )
123
    op.create_table(
124
        "conceptscheme_label",
125
        sa.Column("conceptscheme_id", sa.Integer(), nullable=False),
126
        sa.Column("label_id", sa.Integer(), nullable=False),
127
        sa.ForeignKeyConstraint(
128
            ["conceptscheme_id"],
129
            ["conceptscheme.id"],
130
        ),
131
        sa.ForeignKeyConstraint(
132
            ["label_id"],
133
            ["label.id"],
134
        ),
135
        sa.PrimaryKeyConstraint("conceptscheme_id", "label_id"),
136
    )
137
    op.create_table(
138
        "visitation",
139
        sa.Column("id", sa.Integer(), nullable=False),
140
        sa.Column("lft", sa.Integer(), nullable=False),
141
        sa.Column("rght", sa.Integer(), nullable=False),
142
        sa.Column("depth", sa.Integer(), nullable=False),
143
        sa.Column("conceptscheme_id", sa.Integer(), nullable=False),
144
        sa.Column("concept_id", sa.Integer(), nullable=False),
145
        sa.ForeignKeyConstraint(
146
            ["concept_id"],
147
            ["concept.id"],
148
        ),
149
        sa.ForeignKeyConstraint(
150
            ["conceptscheme_id"],
151
            ["conceptscheme.id"],
152
        ),
153
        sa.PrimaryKeyConstraint("id"),
154
    )
155
    op.create_index(
156
        "ix_visitation_concept_id", "visitation", ["concept_id"], unique=False
157
    )
158
    op.create_index(
159
        "ix_visitation_conceptscheme_id",
160
        "visitation",
161
        ["conceptscheme_id"],
162
        unique=False,
163
    )
164
    op.create_index("ix_visitation_depth", "visitation", ["depth"], unique=False)
165
    op.create_index("ix_visitation_lft", "visitation", ["lft"], unique=False)
166
    op.create_index("ix_visitation_rght", "visitation", ["rght"], unique=False)
167
    op.create_table(
168
        "concept_note",
169
        sa.Column("concept_id", sa.Integer(), nullable=False),
170
        sa.Column("note_id", sa.Integer(), nullable=False),
171
        sa.ForeignKeyConstraint(
172
            ["concept_id"],
173
            ["concept.id"],
174
        ),
175
        sa.ForeignKeyConstraint(
176
            ["note_id"],
177
            ["note.id"],
178
        ),
179
        sa.PrimaryKeyConstraint("concept_id", "note_id"),
180
    )
181
    op.create_table(
182
        "concept_related_concept",
183
        sa.Column("concept_id_from", sa.Integer(), nullable=False),
184
        sa.Column("concept_id_to", sa.Integer(), nullable=False),
185
        sa.ForeignKeyConstraint(
186
            ["concept_id_from"],
187
            ["concept.id"],
188
        ),
189
        sa.ForeignKeyConstraint(
190
            ["concept_id_to"],
191
            ["concept.id"],
192
        ),
193
        sa.PrimaryKeyConstraint("concept_id_from", "concept_id_to"),
194
    )
195
    op.create_table(
196
        "concept_hierarchy_concept",
197
        sa.Column("concept_id_broader", sa.Integer(), nullable=False),
198
        sa.Column("concept_id_narrower", sa.Integer(), nullable=False),
199
        sa.ForeignKeyConstraint(
200
            ["concept_id_broader"],
201
            ["concept.id"],
202
        ),
203
        sa.ForeignKeyConstraint(
204
            ["concept_id_narrower"],
205
            ["concept.id"],
206
        ),
207
        sa.PrimaryKeyConstraint("concept_id_broader", "concept_id_narrower"),
208
    )
209
    op.create_table(
210
        "concept_hierarchy_collection",
211
        sa.Column("concept_id_broader", sa.Integer(), nullable=False),
212
        sa.Column("collection_id_narrower", sa.Integer(), nullable=False),
213
        sa.ForeignKeyConstraint(
214
            ["collection_id_narrower"],
215
            ["concept.id"],
216
        ),
217
        sa.ForeignKeyConstraint(
218
            ["concept_id_broader"],
219
            ["concept.id"],
220
        ),
221
        sa.PrimaryKeyConstraint("concept_id_broader", "collection_id_narrower"),
222
    )
223
    op.create_table(
224
        "concept_label",
225
        sa.Column("concept_id", sa.Integer(), nullable=False),
226
        sa.Column("label_id", sa.Integer(), nullable=False),
227
        sa.ForeignKeyConstraint(
228
            ["concept_id"],
229
            ["concept.id"],
230
        ),
231
        sa.ForeignKeyConstraint(
232
            ["label_id"],
233
            ["label.id"],
234
        ),
235
        sa.PrimaryKeyConstraint("concept_id", "label_id"),
236
    )
237
238
239
def downgrade():
240
    op.drop_table("concept_label")
241
    op.drop_table("concept_hierarchy_collection")
242
    op.drop_table("concept_hierarchy_concept")
243
    op.drop_table("concept_related_concept")
244
    op.drop_table("concept_note")
245
    op.drop_index("ix_visitation_rght", table_name="visitation")
246
    op.drop_index("ix_visitation_lft", table_name="visitation")
247
    op.drop_index("ix_visitation_depth", table_name="visitation")
248
    op.drop_index("ix_visitation_conceptscheme_id", table_name="visitation")
249
    op.drop_index("ix_visitation_concept_id", table_name="visitation")
250
    op.drop_table("visitation")
251
    op.drop_table("conceptscheme_label")
252
    op.drop_table("conceptscheme_note")
253
    op.drop_table("collection_concept")
254
    op.drop_index("ix_concept_conceptscheme_id", table_name="concept")
255
    op.drop_index("ix_concept_concept_id", table_name="concept")
256
    op.drop_table("concept")
257
    op.drop_index("ix_note_notetype_id", table_name="note")
258
    op.drop_index("ix_note_language_id", table_name="note")
259
    op.drop_table("note")
260
    op.drop_index("ix_label_language_id", table_name="label")
261
    op.drop_index("ix_label_labeltype_id", table_name="label")
262
    op.drop_table("label")
263
    op.drop_table("notetype")
264
    op.drop_table("conceptscheme")
265
    op.drop_table("language")
266
    op.drop_table("labeltype")
267