From 8e36b394a881d3a042b51261d5c2a8ac38263526 Mon Sep 17 00:00:00 2001 From: Ulincsys Date: Wed, 1 Nov 2023 16:59:19 -0500 Subject: [PATCH 1/4] Work on adding ORM syntax into RLC Signed-off-by: Ulincsys --- augur/api/view/utils.py | 55 ++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/augur/api/view/utils.py b/augur/api/view/utils.py index 76551a6ab9..2c557ae635 100644 --- a/augur/api/view/utils.py +++ b/augur/api/view/utils.py @@ -9,11 +9,13 @@ from augur.application.db.session import DatabaseSession from augur.application.db.engine import DatabaseEngine from augur.application.db.models import User, Repo, RepoGroup, UserGroup, UserRepo -from sqlalchemy import Column, Table, Integer, MetaData, or_, Label +from sqlalchemy import Column, Table, Integer, MetaData, or_ from sqlalchemy.sql.operators import ilike_op, distinct_op from sqlalchemy.sql.functions import coalesce from augur.application.db.models.base import Base +from sqlalchemy.orm import Query + init_logging() from .init import logger @@ -327,7 +329,7 @@ def renderLoading(dest, query, request): """ ---------------------------------------------------------------- """ def load_repos_test(count = False, source = None, **kwargs): - columns: list[Label] = [ + columns: list[Column] = [ Repo.repo_id.distinct().label("repo_id"), Repo.description.label("description"), Repo.repo_git.label("url"), @@ -339,22 +341,44 @@ def load_repos_test(count = False, source = None, **kwargs): RepoGroup.repo_group_id.label("repo_group_id") ] - def get_colum_by_label(label: str)-> Label: + def get_colum_by_label(label: str)-> Column: for column in columns: if column.name == label: return column - repos = db_session.query(*columns)\ + repos: Query = db_session.query(*columns)\ .outerjoin(commits_materialized_view, Repo.repo_id == commits_materialized_view.columns.repo_id)\ .outerjoin(issues_materialized_view, Repo.repo_id == issues_materialized_view.columns.repo_id)\ .join(RepoGroup, Repo.repo_group_id == RepoGroup.repo_group_id) - user: User = kwargs.get("user") - if user: + if source == "user": + user: User = kwargs.get("user") + + if not user: + return None, {"status": "User not passed when trying to get user repos"} + if not user.groups: + return None, {"status": "No data"} + repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ .join(UserGroup, UserGroup.group_id == UserRepo.group_id)\ .filter(UserGroup.user_id == user.user_id) + elif source == "group": + user: User = kwargs.get("user") + + if not user: + return None, {"status": "User not specified"} + group_name = kwargs.get("group_name") + if not group_name: + return None, {"status": "Group name not specified"} + + group_id = ... # UserGroup.convert_group_name_to_id(self.session, user.user_id, group_name) + if group_id is None: + return None, {"status": "Group does not exists"} + + repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ + .filter(UserRepo.group_id == group_id) + search = kwargs.get("search") qkey = kwargs.get("query_key") or ["repo_name", "repo_owner"] if search: @@ -367,9 +391,22 @@ def get_colum_by_label(label: str)-> Label: if count: c = repos.count() return math.ceil(c / page_size) - 1 - - page: int = kwargs.get("page") or 0 - offset = page * page_size + else: + page: int = kwargs.get("page") or 0 + offset = page * page_size + direction = kwargs.get("direction") or "ASC" + order_by = kwargs.get("order_by") or "repo_id" + + if direction not in ["ASC", "DESC"]: + return None, None, {"status": "Invalid direction"} + + if order_by not in ["repo_id", "repo_name", "repo_owner", "commits_all_time", "issues_all_time"]: + return None, None, {"status": "Invalid order by"} + + # Find the column named in the 'order_by', and get its asc() or desc() method + directive: function = getattr(get_colum_by_label(order_by), direction.lower()) + + repos = repos.order_by(directive()) return repos.slice(offset, offset + page_size) From 9e023b13b0a4189a8ab8191e47969ab1287a45d4 Mon Sep 17 00:00:00 2001 From: Andrew Brain Date: Fri, 3 Nov 2023 17:29:38 -0500 Subject: [PATCH 2/4] Update repo_load_controller.py to use orm syntax. Signed-off-by: Andrew Brain Co-authored-by: John McGinness --- augur/api/view/routes.py | 16 +-- augur/api/view/utils.py | 97 -------------- augur/util/repo_load_controller.py | 205 ++++++++++++----------------- 3 files changed, 93 insertions(+), 225 deletions(-) diff --git a/augur/api/view/routes.py b/augur/api/view/routes.py index ed617cd36c..bf6e8fc056 100644 --- a/augur/api/view/routes.py +++ b/augur/api/view/routes.py @@ -74,17 +74,15 @@ def repo_table_view(): pagination_offset = config.get_value("frontend", "pagination_offset") if current_user.is_authenticated: - data = load_repos_test(user = current_user, search = query, page = page, sort = sorting, direction = direction, source = "user") - page_count = load_repos_test(user = current_user, search = query, count = True, source = "user") - # data = current_user.get_repos(page = page, sort = sorting, direction = direction, search=query)[0] - # page_count = (current_user.get_repo_count(search = query)[0] or 0) // pagination_offset + data = current_user.get_repos(page = page, sort = sorting, direction = direction, search=query)[0] + repos_count = (current_user.get_repo_count(search = query)[0] or 0) else: - data = load_repos_test(search = query, page = page, sort = sorting, direction = direction) - page_count = load_repos_test(search = query, count = True) - # data = get_all_repos(page = page, sort = sorting, direction = direction, search=query)[0] - # page_count = (get_all_repos_count(search = query)[0] or 0) // pagination_offset + data = get_all_repos(page = page, sort = sorting, direction = direction, search=query)[0] + repos_count = (get_all_repos_count(search = query)[0] or 0) + + page_count = math.ceil(repos_count / pagination_offset) - 1 - if not data.count(): + if not data: data = None diff --git a/augur/api/view/utils.py b/augur/api/view/utils.py index 2c557ae635..7712873b55 100644 --- a/augur/api/view/utils.py +++ b/augur/api/view/utils.py @@ -312,101 +312,4 @@ def render_module(module, **args): return render_template('index.j2', **args) """ ---------------------------------------------------------------- - No longer used """ -# My attempt at a loading page -def renderLoading(dest, query, request): - cache_files_requested.append(request) - return render_template('index.j2', body="loading", title="Loading", d=dest, query_key=query, api_url=getSetting('serving')) - -with DatabaseEngine() as engine: - augur_data_schema = MetaData(schema = "augur_data") - augur_data_schema.reflect(bind = engine, views = True) - - commits_materialized_view: Table = augur_data_schema.tables["augur_data.api_get_all_repos_commits"] - issues_materialized_view: Table = augur_data_schema.tables["augur_data.api_get_all_repos_issues"] - -""" ---------------------------------------------------------------- -""" -def load_repos_test(count = False, source = None, **kwargs): - columns: list[Column] = [ - Repo.repo_id.distinct().label("repo_id"), - Repo.description.label("description"), - Repo.repo_git.label("url"), - coalesce(commits_materialized_view.columns.commits_all_time, 0).label("commits_all_time"), - coalesce(issues_materialized_view.columns.issues_all_time, 0).label("issues_all_time"), - RepoGroup.rg_name.label("rg_name"), - Repo.repo_git.regexp_replace('.*github\.com\/[A-Za-z0-9 \- _]+\/([A-Za-z0-9 \- _ .]+)$', "\\1").label("repo_name"), - Repo.repo_git.regexp_replace('.*github\.com\/([A-Za-z0-9 \- _]+)\/[A-Za-z0-9 \- _ .]+$', "\\1").label("repo_owner"), - RepoGroup.repo_group_id.label("repo_group_id") - ] - - def get_colum_by_label(label: str)-> Column: - for column in columns: - if column.name == label: - return column - - repos: Query = db_session.query(*columns)\ - .outerjoin(commits_materialized_view, Repo.repo_id == commits_materialized_view.columns.repo_id)\ - .outerjoin(issues_materialized_view, Repo.repo_id == issues_materialized_view.columns.repo_id)\ - .join(RepoGroup, Repo.repo_group_id == RepoGroup.repo_group_id) - - if source == "user": - user: User = kwargs.get("user") - - if not user: - return None, {"status": "User not passed when trying to get user repos"} - if not user.groups: - return None, {"status": "No data"} - - repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ - .join(UserGroup, UserGroup.group_id == UserRepo.group_id)\ - .filter(UserGroup.user_id == user.user_id) - - elif source == "group": - user: User = kwargs.get("user") - - if not user: - return None, {"status": "User not specified"} - group_name = kwargs.get("group_name") - if not group_name: - return None, {"status": "Group name not specified"} - - group_id = ... # UserGroup.convert_group_name_to_id(self.session, user.user_id, group_name) - if group_id is None: - return None, {"status": "Group does not exists"} - - repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ - .filter(UserRepo.group_id == group_id) - - search = kwargs.get("search") - qkey = kwargs.get("query_key") or ["repo_name", "repo_owner"] - if search: - if isinstance(qkey, list) and len(qkey) > 0: - repos = repos.filter(or_(ilike_op(get_colum_by_label(filter_column), f"%{search}%") for filter_column in qkey)) - else: - repos = repos.filter(ilike_op(get_colum_by_label(qkey), f"%{search}%")) - - page_size: int = kwargs.get("page_size") or 25 - if count: - c = repos.count() - return math.ceil(c / page_size) - 1 - else: - page: int = kwargs.get("page") or 0 - offset = page * page_size - direction = kwargs.get("direction") or "ASC" - order_by = kwargs.get("order_by") or "repo_id" - - if direction not in ["ASC", "DESC"]: - return None, None, {"status": "Invalid direction"} - - if order_by not in ["repo_id", "repo_name", "repo_owner", "commits_all_time", "issues_all_time"]: - return None, None, {"status": "Invalid order by"} - - # Find the column named in the 'order_by', and get its asc() or desc() method - directive: function = getattr(get_colum_by_label(order_by), direction.lower()) - - repos = repos.order_by(directive()) - - return repos.slice(offset, offset + page_size) - diff --git a/augur/util/repo_load_controller.py b/augur/util/repo_load_controller.py index f6841d976e..b5ff5d07a0 100644 --- a/augur/util/repo_load_controller.py +++ b/augur/util/repo_load_controller.py @@ -12,10 +12,23 @@ from augur.application.db.models.augur_operations import retrieve_owner_repos from augur.application.db.util import execute_session_query +from sqlalchemy import Column, Table, MetaData, or_ +from sqlalchemy.sql.operators import ilike_op +from sqlalchemy.sql.functions import coalesce +from sqlalchemy.orm import Query + logger = logging.getLogger(__name__) +with DatabaseEngine() as engine: + augur_data_schema = MetaData(schema = "augur_data") + augur_data_schema.reflect(bind = engine, views = True) + + commits_materialized_view: Table = augur_data_schema.tables["augur_data.api_get_all_repos_commits"] + issues_materialized_view: Table = augur_data_schema.tables["augur_data.api_get_all_repos_issues"] + + class RepoLoadController: def __init__(self, gh_session): @@ -131,34 +144,33 @@ def paginate_repos(self, source, page=0, page_size=25, sort="repo_id", direction order_by = sort if sort else "repo_id" order_direction = direction if direction else "ASC" - query, query_args, result = self.generate_repo_query(source, count=False, order_by=order_by, direction=order_direction, + + query, result = self.generate_repo_query(source, count=False, order_by=order_by, direction=order_direction, page=page, page_size=page_size, **kwargs) + + + # query, query_args, result = self.generate_repo_query(source, count=False, order_by=order_by, direction=order_direction, + # page=page, page_size=page_size, **kwargs) if not query: return None, {"status": result["status"]} if result["status"] == "No data": return [], {"status": "No data"} - get_page_of_repos_sql = s.sql.text(query) - - with DatabaseEngine(connection_pool_size=1).connect() as conn: + # get_page_of_repos_sql = s.sql.text(query) - results = pd.read_sql(get_page_of_repos_sql, conn, params=query_args) + # with DatabaseEngine(connection_pool_size=1).connect() as conn: - results['url'] = results['url'].apply(lambda datum: datum.split('//')[1]) + # results = pd.read_sql(get_page_of_repos_sql, conn, params=query_args) - b64_urls = [] - for i in results.index: - b64_urls.append(base64.b64encode((results.at[i, 'url']).encode())) - results['base64_url'] = b64_urls + results = [dict(x._mapping) for x in query] - data = results.to_dict(orient="records") + for row in results: - # The SELECT statement in generate_repo_query has been updated to include `repo_name` - # for row in data: - # row["repo_name"] = re.search(r"github\.com\/[A-Za-z0-9 \- _]+\/([A-Za-z0-9 \- _ .]+)$", row["url"]).groups()[0] + row["url"] = row["url"].split('//')[1] + row["base64_url"] = base64.b64encode(row["url"].encode()) - return data, {"status": "success"} + return results, {"status": "success"} def get_repo_count(self, source, **kwargs): @@ -169,142 +181,97 @@ def get_repo_count(self, source, **kwargs): if source not in ["all", "user", "group"]: print("Func: get_repo_count. Error: Invalid source") return None, {"status": "Invalid source"} - - query, query_args, result = self.generate_repo_query(source, count=True, **kwargs) + + query, result = self.generate_repo_query(source, count=True, **kwargs) if not query: return None, result if result["status"] == "No data": return 0, {"status": "No data"} - - # surround query with count query so we just get the count of the rows - final_query = f"SELECT count(*) FROM ({query}) a;" - - get_page_of_repos_sql = s.sql.text(final_query) - - result = self.session.execute(get_page_of_repos_sql, query_args).fetchall() + + count = query.count() - return result[0]["count"], {"status": "success"} + return count, {"status": "success"} def generate_repo_query(self, source, count, **kwargs): - # TODO: need more flexible way of calculating count for variable column queries - - query_args = {} - - if count: - # only query for repos ids so the query is faster for getting the count - select = """ DISTINCT(augur_data.repo.repo_id), - (regexp_match(augur_data.repo.repo_git, 'github\.com\/[A-Za-z0-9 \- _]+\/([A-Za-z0-9 \- _ .]+)$'))[1] as repo_name, - (regexp_match(augur_data.repo.repo_git, 'github\.com\/([A-Za-z0-9 \- _]+)\/[A-Za-z0-9 \- _ .]+$'))[1] as repo_owner""" - else: - - select = """ DISTINCT(augur_data.repo.repo_id), - augur_data.repo.description, - augur_data.repo.repo_git AS url, - COALESCE(a.commits_all_time, 0) as commits_all_time, - COALESCE(b.issues_all_time, 0) as issues_all_time, - rg_name, - (regexp_match(augur_data.repo.repo_git, 'github\.com\/[A-Za-z0-9 \- _]+\/([A-Za-z0-9 \- _ .]+)$'))[1] as repo_name, - (regexp_match(augur_data.repo.repo_git, 'github\.com\/([A-Za-z0-9 \- _]+)\/[A-Za-z0-9 \- _ .]+$'))[1] as repo_owner, - augur_data.repo.repo_group_id""" - - query = f""" - SELECT - {select} - FROM - augur_data.repo - LEFT OUTER JOIN augur_data.api_get_all_repos_commits a ON augur_data.repo.repo_id = a.repo_id - LEFT OUTER JOIN augur_data.api_get_all_repos_issues b ON augur_data.repo.repo_id = b.repo_id - JOIN augur_data.repo_groups ON augur_data.repo.repo_group_id = augur_data.repo_groups.repo_group_id\n""" - + + columns: list[Column] = [ + Repo.repo_id.distinct().label("repo_id"), + Repo.description.label("description"), + Repo.repo_git.label("url"), + coalesce(commits_materialized_view.columns.commits_all_time, 0).label("commits_all_time"), + coalesce(issues_materialized_view.columns.issues_all_time, 0).label("issues_all_time"), + RepoGroup.rg_name.label("rg_name"), + Repo.repo_git.regexp_replace('.*github\.com\/[A-Za-z0-9 \- _]+\/([A-Za-z0-9 \- _ .]+)$', "\\1").label("repo_name"), + Repo.repo_git.regexp_replace('.*github\.com\/([A-Za-z0-9 \- _]+)\/[A-Za-z0-9 \- _ .]+$', "\\1").label("repo_owner"), + RepoGroup.repo_group_id.label("repo_group_id") + ] + + def get_colum_by_label(label: str)-> Column: + for column in columns: + if column.name == label: + return column + + repos: Query = self.session.query(*columns)\ + .outerjoin(commits_materialized_view, Repo.repo_id == commits_materialized_view.columns.repo_id)\ + .outerjoin(issues_materialized_view, Repo.repo_id == issues_materialized_view.columns.repo_id)\ + .join(RepoGroup, Repo.repo_group_id == RepoGroup.repo_group_id) + if source == "user": + user: User = kwargs.get("user") - user = kwargs.get("user") if not user: - print("Func: generate_repo_query. Error: User not passed when trying to get user repos") return None, {"status": "User not passed when trying to get user repos"} - if not user.groups: return None, {"status": "No data"} - - query += "\t\t JOIN augur_operations.user_repos ON augur_data.repo.repo_id = augur_operations.user_repos.repo_id\n" - query += "\t\t JOIN augur_operations.user_groups ON augur_operations.user_repos.group_id = augur_operations.user_groups.group_id\n" - query += "\t\t WHERE augur_operations.user_groups.user_id = :user_id\n" - - query_args["user_id"] = user.user_id - + + repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ + .join(UserGroup, UserGroup.group_id == UserRepo.group_id)\ + .filter(UserGroup.user_id == user.user_id) + elif source == "group": - - user = kwargs.get("user") + user: User = kwargs.get("user") + if not user: - print("Func: generate_repo_query. Error: User not specified") return None, {"status": "User not specified"} - group_name = kwargs.get("group_name") if not group_name: - print("Func: generate_repo_query. Error: Group name not specified") return None, {"status": "Group name not specified"} - + group_id = UserGroup.convert_group_name_to_id(self.session, user.user_id, group_name) if group_id is None: - print("Func: generate_repo_query. Error: Group does not exist") return None, {"status": "Group does not exists"} - - query += "\t\t JOIN augur_operations.user_repos ON augur_data.repo.repo_id = augur_operations.user_repos.repo_id\n" - query += "\t\t WHERE augur_operations.user_repos.group_id = :group_id \n" - - query_args["group_id"] = group_id + + repos = repos.join(UserRepo, Repo.repo_id == UserRepo.repo_id)\ + .filter(UserRepo.group_id == group_id) - # implement sorting by query_key search = kwargs.get("search") qkey = kwargs.get("query_key") or ["repo_name", "repo_owner"] - if search: - # The WHERE clause cannot use a column alias created in the directly preceeding SELECT clause - # We must wrap the query in an additional SELECT with a table alias - # This way, we can use WHERE with the computed repo_name column alias - query = f"""\tSELECT * from ( - {query} - ) res\n""" - # This is done so repos with a NULL repo_name can still be sorted. - # "res" here is a randomly chosen table alias, short for "result" - # It is only included because it is required by the SQL syntax - if isinstance(qkey, list) and len(qkey) > 0: - query += f"\tWHERE :qkey_where ilike :search\n" - query_args["qkey_where"] = qkey.pop(0) - - for i, key in enumerate(qkey): - param_name = f"qkey_or_{i}" - query += f"OR :{param_name} ilike :search\n" - query_args[param_name] = key + repos = repos.filter(or_(ilike_op(get_colum_by_label(filter_column), f"%{search}%") for filter_column in qkey)) else: - query += f"\tWHERE :qkey ilike :search\n" - query_args["qkey"] = qkey - - query_args["search"] = f'%{search}%' - - - if not count: - order_by = kwargs.get("order_by") or "repo_id" - page = kwargs.get("page") or 0 - page_size = kwargs.get("page_size") or 25 + repos = repos.filter(ilike_op(get_colum_by_label(qkey), f"%{search}%")) + + page_size: int = kwargs.get("page_size") or 25 + if count: + return repos, {"status": "success"} + else: + page: int = kwargs.get("page") or 0 + offset = page * page_size direction = kwargs.get("direction") or "ASC" - + order_by = kwargs.get("order_by") or "repo_id" + if direction not in ["ASC", "DESC"]: - return None, None, {"status": "Invalid direction"} + return None, {"status": "Invalid direction"} if order_by not in ["repo_id", "repo_name", "repo_owner", "commits_all_time", "issues_all_time"]: - return None, None, {"status": "Invalid order by"} - - offset = page*page_size - - query += f"\tORDER BY {order_by} {direction}\n" - query += "\tLIMIT :page_size\n" - query += "\tOFFSET :offset;\n" - - query_args["page_size"] = page_size - query_args["offset"] = offset + return None, {"status": "Invalid order by"} + + # Find the column named in the 'order_by', and get its asc() or desc() method + directive: function = getattr(get_colum_by_label(order_by), direction.lower()) + + repos = repos.order_by(directive()) - return query, query_args, {"status": "success"} + return repos.slice(offset, offset + page_size), {"status": "success"} From 631aea266bedc95d221da6819e8716abb3f931e7 Mon Sep 17 00:00:00 2001 From: Andrew Brain Date: Sat, 4 Nov 2023 07:41:10 -0500 Subject: [PATCH 3/4] Fix orm warnings --- augur/application/db/models/augur_data.py | 10 +++--- .../application/db/models/augur_operations.py | 32 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/augur/application/db/models/augur_data.py b/augur/application/db/models/augur_data.py index 3ed584ee14..f5efceb4e7 100644 --- a/augur/application/db/models/augur_data.py +++ b/augur/application/db/models/augur_data.py @@ -564,6 +564,8 @@ class RepoGroup(Base): data_source = Column(String) data_collection_date = Column(TIMESTAMP(precision=0)) + repo = relationship("Repo", back_populates="repo_group") + @staticmethod def is_valid_repo_group_id(session, repo_group_id: int) -> bool: """Deterime is repo_group_id exists. @@ -866,8 +868,8 @@ class Repo(Base): TIMESTAMP(precision=0), server_default=text("CURRENT_TIMESTAMP") ) - repo_group = relationship("RepoGroup") - user_repo = relationship("UserRepo") + repo_group = relationship("RepoGroup", back_populates="repo") + user_repo = relationship("UserRepo", back_populates="repo") collection_status = relationship("CollectionStatus", back_populates="repo") issues = relationship("Issue", back_populates="repo") prs = relationship("PullRequest", back_populates="repo") @@ -1208,10 +1210,6 @@ class Commit(Base): primaryjoin="Commit.cmt_author_platform_username == Contributor.cntrb_login", back_populates="commits" ) - contributor1 = relationship( - "Contributor", - primaryjoin="Commit.cmt_author_platform_username == Contributor.cntrb_login", - ) repo = relationship("Repo", back_populates="commits") message_ref = relationship("CommitCommentRef", back_populates="cmt") diff --git a/augur/application/db/models/augur_operations.py b/augur/application/db/models/augur_operations.py index f702d829a3..86a96743b9 100644 --- a/augur/application/db/models/augur_operations.py +++ b/augur/application/db/models/augur_operations.py @@ -271,9 +271,9 @@ class User(Base): {"schema": "augur_operations"} ) - groups = relationship("UserGroup") - tokens = relationship("UserSessionToken") - applications = relationship("ClientApplication") + groups = relationship("UserGroup", back_populates="user") + tokens = relationship("UserSessionToken", back_populates="user") + applications = relationship("ClientApplication", back_populates="user") _is_authenticated = False _is_active = True @@ -628,8 +628,8 @@ class UserGroup(Base): {"schema": "augur_operations"} ) - user = relationship("User") - repos = relationship("UserRepo") + user = relationship("User", back_populates="groups") + user_repos = relationship("UserRepo", back_populates="group") @staticmethod def insert(session, user_id:int, group_name:str) -> dict: @@ -739,8 +739,8 @@ class UserRepo(Base): ForeignKey("augur_data.repo.repo_id", name="user_repo_user_id_fkey"), primary_key=True, nullable=False ) - repo = relationship("Repo") - group = relationship("UserGroup") + repo = relationship("Repo", back_populates="user_repo") + group = relationship("UserGroup", back_populates="user_repos") @staticmethod def insert(session, repo_id: int, group_id:int = 1) -> bool: @@ -949,9 +949,9 @@ class UserSessionToken(Base): application_id = Column(ForeignKey("augur_operations.client_applications.id", name="user_session_token_application_id_fkey"), nullable=False) created_at = Column(BigInteger) - user = relationship("User") - application = relationship("ClientApplication") - refresh_tokens = relationship("RefreshToken") + user = relationship("User", back_populates="tokens") + application = relationship("ClientApplication", back_populates="sessions") + refresh_tokens = relationship("RefreshToken", back_populates="user_session") @staticmethod def create(session, user_id, application_id, seconds_to_expire=86400): @@ -991,9 +991,9 @@ class ClientApplication(Base): redirect_url = Column(String, nullable=False) api_key = Column(String, nullable=False) - user = relationship("User") + user = relationship("User", back_populates="applications") sessions = relationship("UserSessionToken") - subscriptions = relationship("Subscription") + subscriptions = relationship("Subscription", back_populates="application") def __eq__(self, other): return isinstance(other, ClientApplication) and str(self.id) == str(other.id) @@ -1013,8 +1013,8 @@ class Subscription(Base): application_id = Column(ForeignKey("augur_operations.client_applications.id", name="subscriptions_application_id_fkey"), primary_key=True) type_id = Column(ForeignKey("augur_operations.subscription_types.id", name="subscriptions_type_id_fkey"), primary_key=True) - application = relationship("ClientApplication") - type = relationship("SubscriptionType") + application = relationship("ClientApplication", back_populates="subscriptions") + type = relationship("SubscriptionType", back_populates="subscriptions") class SubscriptionType(Base): __tablename__ = "subscription_types" @@ -1027,7 +1027,7 @@ class SubscriptionType(Base): id = Column(BigInteger, primary_key=True) name = Column(String, nullable=False) - subscriptions = relationship("Subscription") + subscriptions = relationship("Subscription", back_populates="type") class RefreshToken(Base): @@ -1040,7 +1040,7 @@ class RefreshToken(Base): id = Column(String, primary_key=True) user_session_token = Column(ForeignKey("augur_operations.user_session_tokens.token", name="refresh_token_session_token_id_fkey"), nullable=False) - user_session = relationship("UserSessionToken") + user_session = relationship("UserSessionToken", back_populates="refresh_tokens") @staticmethod def create(session, user_session_token_id): From de5a69f92450c2bce86a12d3934d0a05c9ed9d35 Mon Sep 17 00:00:00 2001 From: Andrew Brain Date: Sat, 4 Nov 2023 08:51:15 -0500 Subject: [PATCH 4/4] Fix issue when merging branches together Signed-off-by: Andrew Brain --- augur/application/db/models/augur_operations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/augur/application/db/models/augur_operations.py b/augur/application/db/models/augur_operations.py index 86a96743b9..63b9144b35 100644 --- a/augur/application/db/models/augur_operations.py +++ b/augur/application/db/models/augur_operations.py @@ -629,7 +629,7 @@ class UserGroup(Base): ) user = relationship("User", back_populates="groups") - user_repos = relationship("UserRepo", back_populates="group") + repos = relationship("UserRepo", back_populates="group") @staticmethod def insert(session, user_id:int, group_name:str) -> dict: @@ -740,7 +740,7 @@ class UserRepo(Base): ) repo = relationship("Repo", back_populates="user_repo") - group = relationship("UserGroup", back_populates="user_repos") + group = relationship("UserGroup", back_populates="repos") @staticmethod def insert(session, repo_id: int, group_id:int = 1) -> bool: