mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-05-14 10:28:46 +02:00
Changes to the database (#67)
In this PR are pruposed changed that come up when i started the data migration. Plese review them an approve and disaprove.
This commit is contained in:
parent
ba30ba2cc5
commit
06e59b8061
@ -2,15 +2,20 @@
|
||||
import enum
|
||||
|
||||
|
||||
class RelationTypeEnum(enum.Enum):
|
||||
class RelationTypeEnum(enum.IntEnum):
|
||||
"""RelationTypeEnum."""
|
||||
|
||||
executive = "Executive"
|
||||
auditor = "Auditor"
|
||||
supervisory_board = "Supervisory_Board"
|
||||
managing_director = "Managing_Directory"
|
||||
authorized_representative = "Authorized_Representative"
|
||||
final_auditor = "Final_Auditor"
|
||||
EXECUTIVE = enum.auto()
|
||||
AUDITOR = enum.auto()
|
||||
SUPERVISORY_BOARD = enum.auto()
|
||||
MANAGING_DIRECTOR = enum.auto()
|
||||
AUTHORIZED_REPRESENTATIVE = enum.auto()
|
||||
FINAL_AUDITOR = enum.auto()
|
||||
|
||||
PARTICIPATES_WITH = enum.auto()
|
||||
HAS_SHARES_OF = enum.auto()
|
||||
IS_SUPPLIED_BY = enum.auto()
|
||||
WORKS_WITH = enum.auto()
|
||||
|
||||
|
||||
class SentimentTypeEnum(enum.Enum):
|
||||
@ -20,12 +25,3 @@ class SentimentTypeEnum(enum.Enum):
|
||||
sustainability = "sustainability"
|
||||
environmental_aspects = "environmental_aspects"
|
||||
perception = "perception"
|
||||
|
||||
|
||||
class RelationTypeCompanyEnum(enum.Enum):
|
||||
"""RelationTypeCompanyEnum."""
|
||||
|
||||
participates_with = "participates_with"
|
||||
has_shares_of = "has_shares_of"
|
||||
is_supplied_by = "is_supplied_by"
|
||||
works_with = "works_with"
|
||||
|
@ -1,11 +1,10 @@
|
||||
"""Module containing connection utils for PostgreSQL DB."""
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.engine import URL, Engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
from sqlalchemy.orm import Session, declarative_base, sessionmaker
|
||||
|
||||
from aki_prj23_transparenzregister.config.config_providers import JsonFileConfigProvider
|
||||
from aki_prj23_transparenzregister.config.config_template import PostgreConnectionString
|
||||
from aki_prj23_transparenzregister.utils.postgres.entities import Base
|
||||
|
||||
|
||||
def get_engine(conn_args: PostgreConnectionString) -> Engine:
|
||||
@ -34,6 +33,9 @@ def get_session() -> Session: # pragma: no cover
|
||||
return session()
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
"""Initialize DB with all defined entities."""
|
||||
config_provider = JsonFileConfigProvider("./secrets.json")
|
||||
|
@ -1,20 +1,15 @@
|
||||
"""ORM entities for Prod. DB."""
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.orm import (
|
||||
declarative_base,
|
||||
)
|
||||
|
||||
from aki_prj23_transparenzregister.utils.enumy_types import (
|
||||
RelationTypeCompanyEnum,
|
||||
RelationTypeEnum,
|
||||
SentimentTypeEnum,
|
||||
)
|
||||
from aki_prj23_transparenzregister.utils.postgres.connector import Base
|
||||
|
||||
# # create an object *district_court* which inherits attributes from Base-class
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class DistrictCourt(Base):
|
||||
@ -22,9 +17,9 @@ class DistrictCourt(Base):
|
||||
|
||||
__tablename__ = "district_court"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
|
||||
city = sa.Column(sa.String(100), nullable=False)
|
||||
name = sa.Column(sa.String(100), nullable=False)
|
||||
name = sa.Column(sa.String(100), nullable=False, unique=True)
|
||||
|
||||
|
||||
class Company(Base):
|
||||
@ -37,7 +32,7 @@ class Company(Base):
|
||||
sa.UniqueConstraint("hr", "court_id"),
|
||||
)
|
||||
|
||||
id = sa.Column(sa.String, primary_key=True, default=uuid.uuid4, unique=True)
|
||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
|
||||
hr = sa.Column(sa.Integer, nullable=False)
|
||||
court_id = sa.Column(
|
||||
sa.Integer,
|
||||
@ -51,14 +46,14 @@ class Company(Base):
|
||||
sector = sa.Column(sa.String(100), nullable=False)
|
||||
|
||||
|
||||
class Finance(Base):
|
||||
class AnnualFinanceStatement(Base):
|
||||
"""Finance."""
|
||||
|
||||
__tablename__ = "finance"
|
||||
__tablename__ = "annual_finance_statement"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
date = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
date = sa.Column(sa.DateTime(timezone=True), nullable=False)
|
||||
total_volume = sa.Column(sa.Float)
|
||||
ebit = sa.Column(sa.Float)
|
||||
ebitda = sa.Column(sa.Float)
|
||||
@ -103,36 +98,42 @@ class Person(Base):
|
||||
works_for = sa.Column(sa.String(100))
|
||||
|
||||
|
||||
class Relation(Base):
|
||||
"""A super table containing all relations."""
|
||||
|
||||
__tablename__ = "relation"
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
|
||||
date_from = sa.Column(sa.DateTime(timezone=True), nullable=True)
|
||||
date_to = sa.Column(sa.DateTime(timezone=True), nullable=True)
|
||||
|
||||
relation = sa.Column(sa.Enum(RelationTypeEnum), nullable=False)
|
||||
|
||||
|
||||
# create own relation type and person_relation object
|
||||
class PersonRelation(Base):
|
||||
class PersonRelation(Relation):
|
||||
"""PersonRelation."""
|
||||
|
||||
__tablename__ = "person_relation"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company_id = sa.Column(sa.String, sa.ForeignKey("company.id"))
|
||||
person_id = sa.Column(sa.Integer, sa.ForeignKey(Person.id))
|
||||
date_from = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
date_to = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
relation = sa.Column(sa.Enum(RelationTypeEnum), nullable=False)
|
||||
id = sa.Column(sa.Integer, sa.ForeignKey("relation.id"), primary_key=True)
|
||||
person_id = sa.Column(sa.Integer, sa.ForeignKey("person.id"))
|
||||
|
||||
# company = relationship("Company")
|
||||
# person = relationship("Person", foreign_keys=[person_id])
|
||||
# company = relationship('Company', foreign_keys=[company_hr,company_court])
|
||||
__table_args__ = {"extend_existing": True}
|
||||
|
||||
|
||||
# create own relation type and company_relation object
|
||||
class CompanyRelation(Base):
|
||||
class CompanyRelation(Relation):
|
||||
"""CompanyRelation."""
|
||||
|
||||
__tablename__ = "company_relation"
|
||||
|
||||
id = sa.Column(sa.Integer, primary_key=True)
|
||||
company1_id = sa.Column(sa.String, sa.ForeignKey("company.id"), nullable=False)
|
||||
id = sa.Column(sa.Integer, sa.ForeignKey("relation.id"), primary_key=True)
|
||||
company2_id = sa.Column(sa.String, sa.ForeignKey("company.id"), nullable=False)
|
||||
date_from = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
date_to = sa.Column(sa.DateTime(timezone=True), default=datetime.now)
|
||||
relation = sa.Column(sa.Enum(RelationTypeCompanyEnum), nullable=False)
|
||||
|
||||
# company = relationship("Company")
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
"""Tests for config module."""
|
@ -1 +0,0 @@
|
||||
"""Mongo utils module."""
|
@ -1 +0,0 @@
|
||||
"""Tests for utils.postgres module."""
|
@ -18,7 +18,7 @@ def test_init_db() -> None:
|
||||
with patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.get_engine"
|
||||
) as mock_get_engine, patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.entities.declarative_base"
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.declarative_base"
|
||||
) as mock_declarative_base, patch(
|
||||
"aki_prj23_transparenzregister.utils.postgres.connector.JsonFileConfigProvider"
|
||||
) as mock_provider:
|
||||
@ -33,4 +33,3 @@ def test_init_db() -> None:
|
||||
mock_value.get_postgre_connection_string.return_value = ""
|
||||
|
||||
init_db()
|
||||
assert True
|
||||
|
@ -1,4 +1,4 @@
|
||||
def test_import() -> None:
|
||||
from aki_prj23_transparenzregister.utils.postgres import entities
|
||||
|
||||
assert entities is not None
|
||||
assert entities
|
||||
|
Loading…
x
Reference in New Issue
Block a user