Spaces:
Sleeping
Sleeping
Update orchestrator/provenance.py
Browse files- orchestrator/provenance.py +31 -0
orchestrator/provenance.py
CHANGED
|
@@ -1 +1,32 @@
|
|
| 1 |
# SQLAlchemy models for provenance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# SQLAlchemy models for provenance
|
| 2 |
+
# File: orchestrator/provenance.py
|
| 3 |
+
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, create_engine
|
| 4 |
+
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
Base = declarative_base()
|
| 8 |
+
|
| 9 |
+
class Paper(Base):
|
| 10 |
+
__tablename__ = 'papers'
|
| 11 |
+
id = Column(String, primary_key=True)
|
| 12 |
+
title = Column(String)
|
| 13 |
+
authors = Column(String)
|
| 14 |
+
abstract = Column(String)
|
| 15 |
+
fetched_at = Column(DateTime, default=datetime.utcnow)
|
| 16 |
+
runs = relationship("Run", back_populates="paper")
|
| 17 |
+
|
| 18 |
+
class Run(Base):
|
| 19 |
+
__tablename__ = 'runs'
|
| 20 |
+
id = Column(Integer, primary_key=True, autoincrement=True)
|
| 21 |
+
paper_id = Column(String, ForeignKey('papers.id'))
|
| 22 |
+
cell_index = Column(Integer)
|
| 23 |
+
output = Column(String)
|
| 24 |
+
executed_at = Column(DateTime, default=datetime.utcnow)
|
| 25 |
+
paper = relationship("Paper", back_populates="runs")
|
| 26 |
+
|
| 27 |
+
# Utility to initialize and get a session
|
| 28 |
+
|
| 29 |
+
def init_db(db_url: str):
|
| 30 |
+
engine = create_engine(db_url)
|
| 31 |
+
Base.metadata.create_all(engine)
|
| 32 |
+
return sessionmaker(bind=engine)
|