From 31af81dad7b9eddfe7ab3f1dca0afb26fb6952e0 Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Fri, 8 Oct 2021 17:25:26 -0400 Subject: [PATCH] Map RepositoryRatingAssociation declaratively --- lib/tool_shed/webapp/model/__init__.py | 13 ++++++++++++- lib/tool_shed/webapp/model/mapping.py | 14 +------------- test/unit/shed_unit/model/test_mapping.py | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/tool_shed/webapp/model/__init__.py b/lib/tool_shed/webapp/model/__init__.py index 5a22dbf1ad5..f44fc390590 100644 --- a/lib/tool_shed/webapp/model/__init__.py +++ b/lib/tool_shed/webapp/model/__init__.py @@ -569,7 +569,18 @@ class ItemRatingAssociation(_HasTable): """ Set association's item. """ -class RepositoryRatingAssociation(ItemRatingAssociation, _HasTable): +class RepositoryRatingAssociation(Base, ItemRatingAssociation, _HasTable): + __tablename__ = 'repository_rating_association' + + id = Column(Integer, primary_key=True) + create_time = Column(DateTime, default=now) + update_time = Column(DateTime, default=now, onupdate=now) + repository_id = Column(Integer, ForeignKey("repository.id"), index=True) + user_id = Column(Integer, ForeignKey("galaxy_user.id"), index=True) + rating = Column(Integer, index=True) + comment = Column(TEXT) + repository = relationship('Repository') # TODO add back + user = relationship('User') # TODO add back def set_item(self, repository): self.repository = repository diff --git a/lib/tool_shed/webapp/model/mapping.py b/lib/tool_shed/webapp/model/mapping.py index 2cc28366ed8..9aa45923d4c 100644 --- a/lib/tool_shed/webapp/model/mapping.py +++ b/lib/tool_shed/webapp/model/mapping.py @@ -93,15 +93,6 @@ RepositoryReview.table = Table("repository_review", metadata, Column("rating", Integer, index=True), Column("deleted", Boolean, index=True, default=False)) -RepositoryRatingAssociation.table = Table("repository_rating_association", metadata, - Column("id", Integer, primary_key=True), - Column("create_time", DateTime, default=now), - Column("update_time", DateTime, default=now, onupdate=now), - Column("repository_id", Integer, ForeignKey("repository.id"), index=True), - Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True), - Column("rating", Integer, index=True), - Column("comment", TEXT)) - Category.table = Table("category", metadata, Column("id", Integer, primary_key=True), Column("create_time", DateTime, default=now), @@ -136,7 +127,7 @@ mapper_registry.map_imperatively(Category, Category.table, mapper_registry.map_imperatively(Repository, Repository.table, properties=dict( categories=relation(RepositoryCategoryAssociation), - ratings=relation(RepositoryRatingAssociation, order_by=desc(RepositoryRatingAssociation.table.c.update_time), backref="repositories"), + ratings=relation(RepositoryRatingAssociation, order_by=desc(RepositoryRatingAssociation.update_time), backref="repositories"), user=relation(User), downloadable_revisions=relation(RepositoryMetadata, primaryjoin=((Repository.table.c.id == RepositoryMetadata.table.c.repository_id) & (RepositoryMetadata.table.c.downloadable == true())), @@ -173,9 +164,6 @@ mapper_registry.map_imperatively(RepositoryReview, RepositoryReview.table, private_component_reviews=relation(ComponentReview, primaryjoin=((RepositoryReview.table.c.id == ComponentReview.repository_review_id) & (ComponentReview.deleted == false()) & (ComponentReview.private == true()))))) -mapper_registry.map_imperatively(RepositoryRatingAssociation, RepositoryRatingAssociation.table, - properties=dict(repository=relation(Repository), user=relation(User))) - class ToolShedModelMapping(SharedModelMapping): security_agent: CommunityRBACAgent diff --git a/test/unit/shed_unit/model/test_mapping.py b/test/unit/shed_unit/model/test_mapping.py index fcfc119bf47..fb791a2debc 100644 --- a/test/unit/shed_unit/model/test_mapping.py +++ b/test/unit/shed_unit/model/test_mapping.py @@ -478,7 +478,7 @@ class TestRepositoryMetadata(BaseTest): class TestRepositoryRatingAssociation(BaseTest): def test_table(self, cls_): - assert cls_.table.name == 'repository_rating_association' + assert cls_.__tablename__ == 'repository_rating_association' def test_columns(self, session, cls_, repository, user): create_time = datetime.now()