mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Map RepositoryRatingAssociation declaratively
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user