Add basic application handling to the persistence

This commit is contained in:
Guille Gutierrez 2023-01-30 06:49:08 -05:00
parent ba011d9517
commit 17f8223023
6 changed files with 68 additions and 4 deletions

View File

@ -13,7 +13,6 @@ Update your repositories with
Install postgresql
`
sudo apt-get install postgresql
`
*NB: PostgreSQL DB Server runs on a default port of 5432.*

View File

@ -1,9 +1,12 @@
from hub.persistence.models import City
from hub.persistence import BaseRepo
from hub.persistence.models import City
from hub.persistence.models import HeatPumpSimulation
from hub.persistence.models import User
from hub.persistence.repositories import UserRepo
from hub.persistence.models import UserRoles
from hub.persistence.models import Application
from hub.persistence.models import UserApplications
from hub.persistence.repositories import UserRepo
from hub.hub_logger import logger
@ -19,6 +22,8 @@ class DBSetup:
repo = BaseRepo(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
User.__table__.create(bind=repo.engine, checkfirst=True)
City.__table__.create(bind=repo.engine, checkfirst=True)
Application.__table__.create(bind=repo.engine, checkfirst=True)
UserApplications.__table__.create(bind=repo.engine, checkfirst=True)
HeatPumpSimulation.__table__.create(bind=repo.engine, checkfirst=True)
self._user_repo = UserRepo(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
self._create_admin_user(self._user_repo)

View File

@ -3,3 +3,5 @@ from .heat_pump_simulation import HeatPumpSimulation
from .heat_pump_simulation import SimulationTypes
from .heat_pump_simulation import HeatPumpTypes
from .user import User, UserRoles
from .user_applications import UserApplications
from .application import Application

View File

@ -0,0 +1,29 @@
"""
Model representation of an application
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
"""
import datetime
from sqlalchemy import Column, Integer, String, Sequence
from sqlalchemy import DateTime
from hub.persistence.db_config import Base
class Application(Base):
"""
A model representation of an application
"""
__tablename__ = "application"
id = Column(Integer, Sequence('application_id_seq'), primary_key=True)
name = Column(String, nullable=False)
description = Column(String, nullable=False)
created = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow)
def __init__(self, name, description):
self.name = name
self.description = description

View File

@ -0,0 +1,29 @@
"""
Model representation of the user applications
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
"""
import datetime
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy import DateTime
from hub.persistence.db_config import Base
class UserApplications(Base):
"""
A model representation of the user applications
"""
__tablename__ = "user_applications"
user_id = Column(Integer, ForeignKey('user.id'))
application_id = Column(Integer, ForeignKey('application.id'))
created = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow)
def __init__(self, user_id, application_id):
self.user_id = user_id
self.application_id = application_id

View File

@ -29,7 +29,7 @@ class TestDBFactory(TestCase):
:return: None
"""
# Create test database
repo = BaseRepo(db_name='test_db', app_env='TEST', dotenv_path='../.env')
repo = BaseRepo(db_name='test_db', app_env='TEST', dotenv_path='/usr/local/etc/hub/.env')
eng = create_engine(f'postgresql://{repo.config.get_db_user()}@/{repo.config.get_db_user()}')
try: