Skip to content

Commit

Permalink
Merge pull request #86 from GispoCoding/add-operator
Browse files Browse the repository at this point in the history
Add organisation table
  • Loading branch information
Rikuoja authored Feb 22, 2024
2 parents a78104e + 03dd327 commit 74aee65
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""add_source_data_table
Revision ID: 194b9836f0a0
Revises: 7de05df06dce
Revises: 7beedadfb049
Create Date: 2024-02-15 09:55:59.456659
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""add_organisation_table
Revision ID: 57815edcbeeb
Revises: f90c256163dd
Create Date: 2024-02-22 14:42:09.725658
"""
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 = "57815edcbeeb"
down_revision: Union[str, None] = "7beedadfb049"
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(
"organisation",
sa.Column(
"name",
postgresql.JSONB(astext_type=sa.Text()),
server_default='{"fin": "", "swe": "", "eng": ""}',
nullable=False,
),
sa.Column("business_id", sa.String(), 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.PrimaryKeyConstraint("id"),
schema="hame",
)
op.add_column(
"plan", sa.Column("organisation_id", sa.UUID(), nullable=False), schema="hame"
)
op.create_foreign_key(
"organisation_id_fkey",
"plan",
"organisation",
["organisation_id"],
["id"],
source_schema="hame",
referent_schema="hame",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"organisation_id_fkey", "plan", schema="hame", type_="foreignkey"
)
op.drop_column("plan", "organisation_id", schema="hame")
op.drop_table("organisation", schema="hame")
# ### end Alembic commands ###
16 changes: 16 additions & 0 deletions database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Plan(PlanBase):

__tablename__ = "plan"

organisation_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("hame.organisation.id", name="organisation_id_fkey")
)

name: Mapped[language_str]
approved_at: Mapped[Optional[datetime]]
geom: Mapped[MultiPolygon]
Expand Down Expand Up @@ -179,3 +183,15 @@ class SourceData(VersionedBase):
type_of_source_data = relationship("TypeOfSourceData", backref="source_data")
name: Mapped[language_str]
additional_information_uri: Mapped[str]


class Organisation(VersionedBase):
"""
Toimija
"""

__tablename__ = "organisation"

name: Mapped[language_str]
business_id: Mapped[str]
# administrative_region_id: koodilista
2 changes: 1 addition & 1 deletion database/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from db_manager import db_manager
from dotenv import load_dotenv

hame_count: int = 10 # adjust me when adding tables
hame_count: int = 11 # adjust me when adding tables
codes_count: int = 8 # adjust me when adding tables
matview_count: int = 0 # adjust me when adding views

Expand Down

0 comments on commit 74aee65

Please sign in to comment.