mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-04 16:18:13 +08:00
@@ -0,0 +1,60 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
String,
|
||||
)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class CellxGeneUser(Base):
|
||||
"""
|
||||
A registered CellxGene user.
|
||||
Links a user to their annotations
|
||||
"""
|
||||
|
||||
__tablename__ = "cxguser"
|
||||
|
||||
id = Column(String, primary_key=True)
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
annotations = relationship("Annotation", back_populates="cxguser")
|
||||
|
||||
|
||||
class Annotation(Base):
|
||||
"""
|
||||
An annotation is a link between a user, a dataset and tiledb dataframe. A user can have multiple annotations for a
|
||||
dataset, the most recent annotation (based on created_at) will be the default returned when queried
|
||||
"""
|
||||
|
||||
__tablename__ = "annotation"
|
||||
|
||||
id = Column(String, primary_key=True)
|
||||
tiledb_uri = Column(String)
|
||||
user_id = Column(String, ForeignKey("cxguser.id"), nullable=False)
|
||||
dataset_id = Column(String, ForeignKey("cxgdataset.id"), nullable=False)
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
cxguser = relationship("CellxGeneUser", back_populates="annotations")
|
||||
dataset = relationship("CellxGeneDataset", back_populates="annotations")
|
||||
|
||||
|
||||
class CellxGeneDataset(Base):
|
||||
"""
|
||||
Datasets refer to cellxgene datasets stored in tiledb
|
||||
"""
|
||||
|
||||
__tablename__ = "cxgdataset"
|
||||
|
||||
id = Column(String, primary_key=True)
|
||||
name = Column(String)
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
||||
annotations = relationship("Annotation", back_populates="dataset")
|
||||
Reference in New Issue
Block a user