Fixed issue with user persistence

This commit is contained in:
Peter Yefi 2023-01-10 12:52:20 -05:00
parent 6383a47aa0
commit db9f286992
2 changed files with 2 additions and 3 deletions

View File

@ -17,9 +17,9 @@ class DBSetup:
:param dotenv_path: :param dotenv_path:
""" """
repo = BaseRepo(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path) 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) City.__table__.create(bind=repo.engine, checkfirst=True)
HeatPumpSimulation.__table__.create(bind=repo.engine, checkfirst=True) HeatPumpSimulation.__table__.create(bind=repo.engine, checkfirst=True)
User.__table__.create(bind=repo.engine, checkfirst=True)
self._user_repo = UserRepo(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path) self._user_repo = UserRepo(db_name=db_name, app_env=app_env, dotenv_path=dotenv_path)
self._create_admin_user(self._user_repo) self._create_admin_user(self._user_repo)
@ -29,7 +29,6 @@ class DBSetup:
print('Creating default admin user...') print('Creating default admin user...')
user = user_repo.insert('Administrator', email, password, UserRoles.Admin) user = user_repo.insert('Administrator', email, password, UserRoles.Admin)
if type(user) is dict: if type(user) is dict:
print(user)
logger.info(user) logger.info(user)
else: else:
print(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin}') print(f'Created Admin user with email: {email}, password: {password} and role: {UserRoles.Admin}')

View File

@ -31,7 +31,7 @@ class City(Base):
hub_release = Column(String, nullable=False) hub_release = Column(String, nullable=False)
city_version = Column(Integer, nullable=False) city_version = Column(Integer, nullable=False)
user_id = Column(Integer, ForeignKey('user.id')) user_id = Column(Integer, ForeignKey('user.id'))
user = relationship("User", back_populates="city") user = relationship("User", back_populates="cities")
created = Column(DateTime, default=datetime.datetime.utcnow) created = Column(DateTime, default=datetime.datetime.utcnow)
updated = Column(DateTime, default=datetime.datetime.utcnow) updated = Column(DateTime, default=datetime.datetime.utcnow)