Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Add env variable to change the test database
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Dec 28, 2023
1 parent 48c25bf commit b72683f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tm_admin/projects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# Instantiate logger
log = logging.getLogger(__name__)

def importThread(
def updateThread(
data: list,
db: PostgresClient,
):
Expand All @@ -59,7 +59,7 @@ def importThread(
"""
for record in data:
sql = f" UPDATE projects SET licenses = ARRAY[{record[0]['license']}] WHERE id={record[0]['user']}"
print(sql)
# print(sql)
# try:
# result = db.dbcursor.execute(f"{sql};")
# except:
Expand Down Expand Up @@ -122,7 +122,7 @@ def mergeProjectInfo(self,
settings += f"{entry}, "

sql = f"UPDATE projects SET {settings[:-2]} WHERE id={record[0]['project_id']};"
print(sql)
# print(sql)
results = self.pg.queryLocal(sql[:-2])

def main():
Expand Down
50 changes: 41 additions & 9 deletions tm_admin/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from datetime import datetime
from dateutil.parser import parse
import tm_admin.types_tm
from tm_admin.types_tm import Userrole, Mappinglevel
from tm_admin.types_tm import Userrole, Mappinglevel, Teammemberfunctions
import concurrent.futures
from cpuinfo import get_cpu_info

Expand All @@ -43,7 +43,7 @@
info = get_cpu_info()
cores = info["count"]

def importThread(
def updateThread(
data: list,
db: PostgresClient,
):
Expand Down Expand Up @@ -141,13 +141,40 @@ def mergeLicenses(self):
block = 0
while block <= entries:
log.debug("Dispatching Block %d:%d" % (block, block + chunk))
result = executor.submit(importThread, data[block : block + chunk], tmpg[index])
result = executor.submit(updateThread, data[block : block + chunk], tmpg[index])
block += chunk
index += 1
executor.shutdown()

return True

def mergeTeam(self):
table = 'team_members'
# FIXME: this shouldn't be hardcoded!
pg = PostgresClient('localhost/tm4')
sql = f"SELECT row_to_json({table}) as row FROM {table}"
print(sql)
try:
result = pg.dbcursor.execute(sql)
except:
log.error(f"Couldn't execute query! {sql}")
return False

result = pg.dbcursor.fetchall()
for record in result:
func = record[0]['function']
tmfunc = Teammemberfunctions(func)
sql = f"UPDATE {self.table} SET team_members.team={record[0]['team_id']}, team_members.active={record[0]['active']}, team_members.function='{tmfunc.name}' WHERE id={record[0]['user_id']}"
print(f"{sql};")
try:
# FIXME: this fails to execute, but if I write the out to a file,
# it works just fine.
# result = pg.dbcursor.execute(sql)
pass
except:
log.error(f"Couldn't execute query! '{sql}'")
return False

def mergeFavorites(self):
table = 'project_favorites'
# FIXME: this shouldn't be hardcoded!
Expand Down Expand Up @@ -265,14 +292,19 @@ def main():
user = UsersDB(args.uri)

# These may take a long time to complete
# if user.mergeInterests():
# log.info("UserDB.mergeInterests worked!")
if user.mergeInterests():
log.info("UserDB.mergeInterests worked!")

#if user.mergeLicenses():
# log.info("UserDB.mergeLicenses worked!")

if user.mergeLicenses():
log.info("UserDB.mergeLicenses worked!")
if user.mergeFavorites():
log.info("UserDB.mergeFavorites worked!")

# if user.mergeFavorites():
# log.info("UserDB.mergeFavorites worked!")
if user.mergeTeam():
log.info("UserDB.mergeTeams worked!")

# log.warning(f"Nothing to do!")

# user.resetSequence()
# all = user.getAll()
Expand Down

0 comments on commit b72683f

Please sign in to comment.