Spaces:
Sleeping
Sleeping
File size: 1,929 Bytes
1c0aad9 3e25ded 1c0aad9 bc67f56 1c0aad9 3e25ded 1c0aad9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
from alembic import config
from sqlalchemy import create_engine, Column, String, Integer, DateTime, func
from sqlalchemy.orm import sessionmaker, declarative_base
from blossomtune_gradio import config as cfg
Base = declarative_base()
engine = create_engine(cfg.SQLALCHEMY_URL)
# The sessionmaker factory generates new Session objects when called.
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
class Request(Base):
"""
SQLAlchemy model for the 'requests' table.
This table stores information about participants wanting to join the federation.
"""
__tablename__ = "requests"
participant_id = Column(String, primary_key=True)
status = Column(String, nullable=False, default="pending")
timestamp = Column(DateTime, nullable=False, server_default=func.now())
partition_id = Column(Integer, nullable=True)
email = Column(String, nullable=True)
hf_handle = Column(String, nullable=True)
activation_code = Column(String, nullable=True)
is_activated = Column(Integer, nullable=False, default=0)
public_key_pem = Column(String(), nullable=True)
def __repr__(self):
return (
f"<Request(participant_id='{self.participant_id}', status='{self.status}')>"
)
class Config(Base):
"""
SQLAlchemy model for the 'config' table.
A simple key-value store for application settings.
"""
__tablename__ = "config"
key = Column(String, primary_key=True)
value = Column(String, nullable=False)
def __repr__(self):
return f"<Config(key='{self.key}', value='{self.value}')>"
def run_migrations():
"""
Applies any pending Alembic migrations to the database.
This should be called on application startup.
"""
print("Running database migrations...")
alembicArgs = [
"--raiseerr",
"upgrade",
"head",
]
config.main(argv=alembicArgs)
|