-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from GispoCoding/6-add-other-tables-to-postgis
Add plan regulation table
- Loading branch information
Showing
5 changed files
with
270 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
database/migrations/versions/2024_02_08_1648-776ca8ea5a68_add_plan_regulation_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""add_plan_regulation_table | ||
Revision ID: 776ca8ea5a68 | ||
Revises: 6ee06a6e634a | ||
Create Date: 2024-02-08 16:48:20.346350 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# import geoalchemy2 | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "776ca8ea5a68" | ||
down_revision: Union[str, None] = "6ee06a6e634a" | ||
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( | ||
"plan_regulation", | ||
sa.Column("plan_regulation_group_id", sa.UUID(), nullable=False), | ||
sa.Column("type_of_plan_regulation_id", sa.UUID(), nullable=False), | ||
sa.Column("type_of_verbal_plan_regulation_id", sa.UUID(), nullable=False), | ||
sa.Column("numeric_range", postgresql.NUMRANGE(), nullable=False), | ||
sa.Column("unit", sa.String(), nullable=False), | ||
sa.Column( | ||
"text_value", | ||
postgresql.JSONB(astext_type=sa.Text()), | ||
server_default='{"fin": "", "swe": "", "eng": ""}', | ||
nullable=False, | ||
), | ||
sa.Column("numeric_value", sa.Float(), nullable=False), | ||
sa.Column( | ||
"regulation_number", sa.Integer(), autoincrement=True, nullable=False | ||
), | ||
sa.Column("exported_at", sa.DateTime(), nullable=True), | ||
sa.Column("valid_from", sa.DateTime(), nullable=True), | ||
sa.Column("valid_to", sa.DateTime(), nullable=True), | ||
sa.Column("repealed_at", sa.DateTime(), nullable=True), | ||
sa.Column("lifecycle_status_id", sa.UUID(), nullable=False), | ||
sa.Column( | ||
"id", sa.UUID(), server_default=sa.text("gen_random_uuid()"), nullable=False | ||
), | ||
sa.Column( | ||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False | ||
), | ||
sa.Column( | ||
"modified_at", | ||
sa.DateTime(), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["lifecycle_status_id"], | ||
["codes.lifecycle_status.id"], | ||
name="plan_lifecycle_status_id_fkey", | ||
), | ||
sa.ForeignKeyConstraint( | ||
["plan_regulation_group_id"], | ||
["hame.plan_regulation_group.id"], | ||
name="plan_regulation_group_id_fkey", | ||
), | ||
sa.ForeignKeyConstraint( | ||
["type_of_plan_regulation_id"], | ||
["codes.type_of_plan_regulation.id"], | ||
name="type_of_plan_regulation_id_fkey", | ||
), | ||
sa.ForeignKeyConstraint( | ||
["type_of_verbal_plan_regulation_id"], | ||
["codes.type_of_verbal_plan_regulation.id"], | ||
name="type_of_verbal_plan_regulation_id_fkey", | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
schema="hame", | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("plan_regulation", schema="hame") | ||
# ### end Alembic commands ### |
111 changes: 111 additions & 0 deletions
111
database/migrations/versions/2024_02_15_0751-e22a66335242_edit_plan_regulation_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
"""edit_plan_regulation_table | ||
Revision ID: e22a66335242 | ||
Revises: 776ca8ea5a68 | ||
Create Date: 2024-02-15 07:51:18.528788 | ||
""" | ||
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 = "e22a66335242" | ||
down_revision: Union[str, None] = "776ca8ea5a68" | ||
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.add_column( | ||
"plan_regulation", | ||
sa.Column("ordering", sa.Integer(), autoincrement=True, nullable=False), | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"type_of_verbal_plan_regulation_id", | ||
existing_type=sa.UUID(), | ||
nullable=True, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"numeric_range", | ||
existing_type=postgresql.NUMRANGE(), | ||
nullable=True, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"unit", | ||
existing_type=sa.VARCHAR(), | ||
nullable=True, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"numeric_value", | ||
existing_type=sa.DOUBLE_PRECISION(precision=53), | ||
nullable=True, | ||
schema="hame", | ||
) | ||
op.create_index( | ||
op.f("ix_hame_plan_regulation_ordering"), | ||
"plan_regulation", | ||
["ordering"], | ||
unique=False, | ||
schema="hame", | ||
) | ||
op.drop_column("plan_regulation", "regulation_number", schema="hame") | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"plan_regulation", | ||
sa.Column( | ||
"regulation_number", sa.INTEGER(), autoincrement=False, nullable=False | ||
), | ||
schema="hame", | ||
) | ||
op.drop_index( | ||
op.f("ix_hame_plan_regulation_ordering"), | ||
table_name="plan_regulation", | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"numeric_value", | ||
existing_type=sa.DOUBLE_PRECISION(precision=53), | ||
nullable=False, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"unit", | ||
existing_type=sa.VARCHAR(), | ||
nullable=False, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"numeric_range", | ||
existing_type=postgresql.NUMRANGE(), | ||
nullable=False, | ||
schema="hame", | ||
) | ||
op.alter_column( | ||
"plan_regulation", | ||
"type_of_verbal_plan_regulation_id", | ||
existing_type=sa.UUID(), | ||
nullable=False, | ||
schema="hame", | ||
) | ||
op.drop_column("plan_regulation", "ordering", schema="hame") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters