Skip to content

Commit

Permalink
Merge pull request #137 from GispoCoding/add-documents
Browse files Browse the repository at this point in the history
Add documents table
  • Loading branch information
Rikuoja authored Feb 23, 2024
2 parents 2a9b677 + c677eca commit 9a9953e
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""add_document_table
Revision ID: 9a8e55a1d1bc
Revises: 57815edcbeeb
Create Date: 2024-02-22 15:38:18.244075
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# import geoalchemy2


# revision identifiers, used by Alembic.
revision: str = "9a8e55a1d1bc"
down_revision: Union[str, None] = "57815edcbeeb"
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(
"document",
sa.Column("type_of_document_id", sa.UUID(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("personal_details", sa.String(), nullable=False),
sa.Column(
"publicity",
sa.Enum("julkinen", "ei julkinen", native_enum=False),
nullable=False,
),
sa.Column("language", sa.String(), nullable=False),
sa.Column("decision", sa.Boolean(), nullable=False),
sa.Column(
"decision_date",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=True,
),
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(
["type_of_document_id"],
["codes.type_of_document.id"],
name="type_of_document_id_fkey",
),
sa.PrimaryKeyConstraint("id"),
schema="hame",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("document", schema="hame")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""add plan fk to document
Revision ID: 4e8869aba78f
Revises: 9a8e55a1d1bc
Create Date: 2024-02-23 18:06:34.802480
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# import geoalchemy2


# revision identifiers, used by Alembic.
revision: str = "4e8869aba78f"
down_revision: Union[str, None] = "9a8e55a1d1bc"
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(
"document", sa.Column("plan_id", sa.UUID(), nullable=False), schema="hame"
)
op.create_foreign_key(
"plan_id_fkey",
"document",
"plan",
["plan_id"],
["id"],
source_schema="hame",
referent_schema="hame",
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("plan_id_fkey", "document", schema="hame", type_="foreignkey")
op.drop_column("document", "plan_id", schema="hame")
# ### end Alembic commands ###
28 changes: 27 additions & 1 deletion database/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from datetime import datetime
from typing import Optional
from typing import Literal, Optional

# we have to import CodeBase in codes.py from here to allow two-way relationships
from base import ( # noqa
Expand All @@ -11,6 +11,7 @@
autoincrement_int,
language_str,
numeric_range,
timestamp,
unique_str,
)
from shapely.geometry import MultiLineString, MultiPoint, MultiPolygon
Expand Down Expand Up @@ -195,3 +196,28 @@ class Organisation(VersionedBase):
name: Mapped[language_str]
business_id: Mapped[str]
# administrative_region_id: koodilista


class Document(VersionedBase):
"""
Asiakirja
"""

__tablename__ = "document"

type_of_document_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("codes.type_of_document.id", name="type_of_document_id_fkey")
)
plan_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("hame.plan.id", name="plan_id_fkey")
)

type_of_document = relationship("TypeOfDocument", backref="documents")
plan = relationship("Plan", backref="documents")
name: Mapped[str]
personal_details: Mapped[str]
publicity: Mapped[Literal["julkinen", "ei julkinen"]] # Muita?
language: Mapped[str]
decision: Mapped[bool]
decision_date: Mapped[Optional[timestamp]]
# file
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 = 11 # adjust me when adding tables
hame_count: int = 12 # 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 9a9953e

Please sign in to comment.