From 20ed9d87bea17edfed3608440609be089a67cf93 Mon Sep 17 00:00:00 2001 From: Khoroshevskyi Date: Thu, 27 Mar 2025 17:08:01 -0400 Subject: [PATCH] Fixed connection between schema and project --- docs/changelog.md | 7 ++++ pepdbagent/_version.py | 2 +- pepdbagent/modules/project.py | 61 +++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 9fee62b..923c310 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format. +## [0.12.2] -- 2025-03-27 +- Fixed links between schema and project + +## [0.12.1] -- 2025-03-27 +- Added alembic to the project +- Fixed errors in methods getting user stars + ## [0.12.0] -- 2025-03-27 - New database model for schemas diff --git a/pepdbagent/_version.py b/pepdbagent/_version.py index def467e..76da4a9 100644 --- a/pepdbagent/_version.py +++ b/pepdbagent/_version.py @@ -1 +1 @@ -__version__ = "0.12.1" +__version__ = "0.12.2" diff --git a/pepdbagent/modules/project.py b/pepdbagent/modules/project.py index d5ee5a7..bf87e78 100644 --- a/pepdbagent/modules/project.py +++ b/pepdbagent/modules/project.py @@ -24,6 +24,7 @@ NAME_KEY, PEPHUB_SAMPLE_ID_KEY, PKG_NAME, + LATEST_SCHEMA_VERSION, ) from pepdbagent.db_utils import ( BaseEngine, @@ -369,17 +370,29 @@ def create( schema_namespace, schema_name, schema_version = schema_path_converter(pep_schema) with Session(self._sa_engine) as session: - schema_mapping = session.scalar( - select(SchemaVersions) - .join(SchemaRecords, SchemaRecords.id == SchemaVersions.schema_id) - .where( - and_( - SchemaRecords.namespace == schema_namespace, - SchemaRecords.name == schema_name, - SchemaVersions.version == schema_version, + if schema_version == LATEST_SCHEMA_VERSION: + schema_mapping = session.scalar( + select(SchemaVersions) + .join(SchemaRecords, SchemaRecords.id == SchemaVersions.schema_id) + .where( + and_( + SchemaRecords.namespace == schema_namespace, + SchemaRecords.name == schema_name, + ) ) + .order_by(SchemaVersions.version.desc()) + ) + + else: + where_clause = and_( + SchemaRecords.namespace == schema_namespace, + SchemaRecords.name == schema_name, + SchemaVersions.version == schema_version, + ) + + schema_mapping = session.scalar( + select(SchemaVersions).join(SchemaRecords).where(where_clause) ) - ) if not schema_mapping: raise SchemaDoesNotExistError( f"Schema {schema_namespace}/{schema_name} does not exist. " @@ -698,15 +711,29 @@ def _convert_update_schema_id(session: Session, update_values: dict): schema_namespace, schema_name, schema_version = schema_path_converter( update_values["pep_schema"] ) - where_clause = and_( - SchemaRecords.namespace == schema_namespace, - SchemaRecords.name == schema_name, - SchemaVersions.version == schema_version, - ) + if schema_version == LATEST_SCHEMA_VERSION: + schema_mapping = session.scalar( + select(SchemaVersions) + .join(SchemaRecords, SchemaRecords.id == SchemaVersions.schema_id) + .where( + and_( + SchemaRecords.namespace == schema_namespace, + SchemaRecords.name == schema_name, + ) + ) + .order_by(SchemaVersions.version.desc()) + ) - schema_mapping = session.scalar( - select(SchemaVersions).join(SchemaRecords).where(where_clause) - ) + else: + where_clause = and_( + SchemaRecords.namespace == schema_namespace, + SchemaRecords.name == schema_name, + SchemaVersions.version == schema_version, + ) + + schema_mapping = session.scalar( + select(SchemaVersions).join(SchemaRecords).where(where_clause) + ) if not schema_mapping: raise SchemaDoesNotExistError( f"Schema {schema_namespace}/{schema_name} does not exist. "