-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2024_12_12_1453-3527051d7f9b_add_kuntajako.py
154 lines (146 loc) · 4.25 KB
/
2024_12_12_1453-3527051d7f9b_add_kuntajako.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""add kuntajako
Revision ID: 3527051d7f9b
Revises: 29f092710449
Create Date: 2024-12-12 14:53:19.753551
"""
from typing import Sequence, Union
import geoalchemy2
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = "3527051d7f9b"
down_revision: Union[str, None] = "29f092710449"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"municipality",
sa.Column(
"geom",
geoalchemy2.types.Geometry(
geometry_type="MULTIPOLYGON",
srid=3067,
from_text="ST_GeomFromEWKT",
name="geometry",
),
nullable=True,
),
sa.Column("value", sa.String(), nullable=False),
sa.Column("short_name", sa.String(), server_default="", nullable=False),
sa.Column(
"name",
postgresql.JSONB(astext_type=sa.Text()),
server_default='{"fin": "", "swe": "", "eng": ""}',
nullable=False,
),
sa.Column(
"description",
postgresql.JSONB(astext_type=sa.Text()),
server_default='{"fin": "", "swe": "", "eng": ""}',
nullable=False,
),
sa.Column("status", sa.String(), nullable=False),
sa.Column("level", sa.Integer(), server_default="1", nullable=False),
sa.Column("parent_id", sa.UUID(as_uuid=False), nullable=True),
sa.Column(
"id",
sa.UUID(as_uuid=False),
server_default=sa.text("gen_random_uuid()"),
nullable=False,
),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"modified_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.ForeignKeyConstraint(
["parent_id"],
["codes.municipality.id"],
name="municipality_parent_id_fkey",
),
sa.PrimaryKeyConstraint("id"),
schema="codes",
)
op.create_index(
op.f("ix_codes_municipality_level"),
"municipality",
["level"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_municipality_parent_id"),
"municipality",
["parent_id"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_municipality_short_name"),
"municipality",
["short_name"],
unique=False,
schema="codes",
)
op.create_index(
op.f("ix_codes_municipality_value"),
"municipality",
["value"],
unique=True,
schema="codes",
)
op.add_column(
"organisation",
sa.Column("municipality_id", sa.UUID(as_uuid=False), nullable=True),
schema="hame",
)
op.create_foreign_key(
"municipality_id_fkey",
"organisation",
"municipality",
["municipality_id"],
["id"],
source_schema="hame",
referent_schema="codes",
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"municipality_id_fkey",
"organisation",
schema="hame",
type_="foreignkey",
)
op.drop_column("organisation", "municipality_id", schema="hame")
op.drop_index(
op.f("ix_codes_municipality_value"),
table_name="municipality",
schema="codes",
)
op.drop_index(
op.f("ix_codes_municipality_short_name"),
table_name="municipality",
schema="codes",
)
op.drop_index(
op.f("ix_codes_municipality_parent_id"),
table_name="municipality",
schema="codes",
)
op.drop_index(
op.f("ix_codes_municipality_level"),
table_name="municipality",
schema="codes",
)
op.drop_table("municipality", schema="codes")
# ### end Alembic commands ###