diff --git a/database/base.py b/database/base.py index fda5932..be2b1be 100644 --- a/database/base.py +++ b/database/base.py @@ -52,6 +52,7 @@ class VersionedBase(Base): """ __abstract__ = True + __table_args__ = {"schema": "hame"} id: Mapped[uuid_pk] created_at: Mapped[timestamp] @@ -105,7 +106,6 @@ class PlanBase(VersionedBase): """ __abstract__ = True - __table_args__ = {"schema": "hame"} exported_at: Mapped[Optional[datetime]] valid_from: Mapped[Optional[datetime]] diff --git a/database/migrations/versions/2024_02_08_1613-6ee06a6e634a_edit_plan_regulation_group_base_class.py b/database/migrations/versions/2024_02_08_1613-6ee06a6e634a_edit_plan_regulation_group_base_class.py new file mode 100644 index 0000000..33eae14 --- /dev/null +++ b/database/migrations/versions/2024_02_08_1613-6ee06a6e634a_edit_plan_regulation_group_base_class.py @@ -0,0 +1,84 @@ +"""edit_plan_regulation_group_base_class + +Revision ID: 6ee06a6e634a +Revises: 811b23178cef +Create Date: 2024-02-08 16:13:11.875724 + +""" +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 = "6ee06a6e634a" +down_revision: Union[str, None] = "811b23178cef" +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.drop_constraint( + "plan_lifecycle_status_id_fkey", + "plan_regulation_group", + schema="hame", + type_="foreignkey", + ) + op.drop_column("plan_regulation_group", "valid_to", schema="hame") + op.drop_column("plan_regulation_group", "valid_from", schema="hame") + op.drop_column("plan_regulation_group", "exported_at", schema="hame") + op.drop_column("plan_regulation_group", "lifecycle_status_id", schema="hame") + op.drop_column("plan_regulation_group", "repealed_at", schema="hame") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + "plan_regulation_group", + sa.Column( + "repealed_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + schema="hame", + ) + op.add_column( + "plan_regulation_group", + sa.Column( + "lifecycle_status_id", sa.UUID(), autoincrement=False, nullable=False + ), + schema="hame", + ) + op.add_column( + "plan_regulation_group", + sa.Column( + "exported_at", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + schema="hame", + ) + op.add_column( + "plan_regulation_group", + sa.Column( + "valid_from", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + schema="hame", + ) + op.add_column( + "plan_regulation_group", + sa.Column( + "valid_to", postgresql.TIMESTAMP(), autoincrement=False, nullable=True + ), + schema="hame", + ) + op.create_foreign_key( + "plan_lifecycle_status_id_fkey", + "plan_regulation_group", + "lifecycle_status", + ["lifecycle_status_id"], + ["id"], + source_schema="hame", + referent_schema="codes", + ) + # ### end Alembic commands ### diff --git a/database/models.py b/database/models.py index 2f3af15..237e71c 100644 --- a/database/models.py +++ b/database/models.py @@ -1,7 +1,7 @@ from datetime import datetime from typing import Optional -from base import PlanBase, language_str, unique_str +from base import PlanBase, VersionedBase, language_str, unique_str from shapely.geometry import Polygon from sqlalchemy.orm import Mapped @@ -18,7 +18,7 @@ class Plan(PlanBase): geom: Mapped[Polygon] -class PlanRegulationGroup(PlanBase): +class PlanRegulationGroup(VersionedBase): """ Kaavamääräysryhmä """