# Snapshot of MLflow DB models as of the 0.9.1 release, prior to the first database migration. # This file corresponds to the first database schema that we can reasonably expect users to be # running and exists to test that the oldest database schema can be brought up-to-date. # Copied from https://github.com/mlflow/mlflow/blob/v0.9.1/mlflow/store/dbmodels/models.py, with # modifications to substitute constants from MLflow with hard-coded values (e.g. replacing # SourceType.to_string(SourceType.NOTEBOOK) with the constant "NOTEBOOK"). import time from sqlalchemy import ( BigInteger, CheckConstraint, Column, Float, ForeignKey, Integer, PrimaryKeyConstraint, String, ) from sqlalchemy.orm import backref, declarative_base, relationship Base = declarative_base() SourceTypes = [ "NOTEBOOK", "JOB", "LOCAL", "UNKNOWN", "PROJECT", ] RunStatusTypes = [ "SCHEDULED", "FAILED", "FINISHED", "RUNNING", ] class SqlExperiment(Base): """ DB model for :py:class:`mlflow.entities.Experiment`. These are recorded in ``experiment`` table. """ __tablename__ = "experiments" experiment_id = Column(Integer, autoincrement=True) """ Experiment ID: `Integer`. *Primary Key* for ``experiment`` table. """ name = Column(String(256), unique=True, nullable=False) """ Experiment name: `String` (limit 256 characters). Defined as *Unique* and *Non null* in table schema. """ artifact_location = Column(String(256), nullable=True) """ Default artifact location for this experiment: `String` (limit 256 characters). Defined as *Non null* in table schema. """ lifecycle_stage = Column(String(32), default="active") """ Lifecycle Stage of experiment: `String` (limit 32 characters). Can be either ``active`` (default) or ``deleted``. """ __table_args__ = ( CheckConstraint(lifecycle_stage.in_(["active", "deleted"]), name="lifecycle_stage"), PrimaryKeyConstraint("experiment_id", name="experiment_pk"), ) def __repr__(self): return f"" class SqlRun(Base): """ DB model for :py:class:`mlflow.entities.Run`. These are recorded in ``runs`` table. """ __tablename__ = "runs" run_uuid = Column(String(32), nullable=False) """ Run UUID: `String` (limit 32 characters). *Primary Key* for ``runs`` table. """ name = Column(String(250)) """ Run name: `String` (limit 250 characters). """ source_type = Column(String(20), default="LOCAL") """ Source Type: `String` (limit 20 characters). Can be one of ``NOTEBOOK``, ``JOB``, ``PROJECT``, ``LOCAL`` (default), or ``UNKNOWN``. """ source_name = Column(String(500)) """ Name of source recording the run: `String` (limit 500 characters). """ entry_point_name = Column(String(50)) """ Entry-point name that launched the run run: `String` (limit 50 characters). """ user_id = Column(String(256), nullable=True, default=None) """ User ID: `String` (limit 256 characters). Defaults to ``null``. """ status = Column(String(20), default="SCHEDULED") """ Run Status: `String` (limit 20 characters). Can be one of ``RUNNING``, ``SCHEDULED`` (default), ``FINISHED``, ``FAILED``. """ start_time = Column(BigInteger, default=int(time.time())) """ Run start time: `BigInteger`. Defaults to current system time. """ end_time = Column(BigInteger, nullable=True, default=None) """ Run end time: `BigInteger`. """ deleted_time = Column(BigInteger, nullable=True, default=None) """ Run deleted time: `BigInteger`. Timestamp of when run is deleted, defaults to none. """ source_version = Column(String(50)) """ Source version: `String` (limit 50 characters). """ lifecycle_stage = Column(String(20), default="active") """ Lifecycle Stage of run: `String` (limit 32 characters). Can be either ``active`` (default) or ``deleted``. """ artifact_uri = Column(String(200), default=None) """ Default artifact location for this run: `String` (limit 200 characters). """ experiment_id = Column(Integer, ForeignKey("experiments.experiment_id")) """ Experiment ID to which this run belongs to: *Foreign Key* into ``experiment`` table. """ experiment = relationship("SqlExperiment", backref=backref("runs", cascade="all")) """ SQLAlchemy relationship (many:one) with :py:class:`mlflow.store.dbmodels.models.SqlExperiment`. """ __table_args__ = ( CheckConstraint(source_type.in_(SourceTypes), name="source_type"), CheckConstraint(status.in_(RunStatusTypes), name="status"), CheckConstraint(lifecycle_stage.in_(["active", "deleted"]), name="lifecycle_stage"), PrimaryKeyConstraint("run_uuid", name="run_pk"), ) class SqlTag(Base): """ DB model for :py:class:`mlflow.entities.RunTag`. These are recorded in ``tags`` table. """ __tablename__ = "tags" key = Column(String(250)) """ Tag key: `String` (limit 250 characters). *Primary Key* for ``tags`` table. """ value = Column(String(250), nullable=True) """ Value associated with tag: `String` (limit 250 characters). Could be *null*. """ run_uuid = Column(String(32), ForeignKey("runs.run_uuid")) """ Run UUID to which this tag belongs to: *Foreign Key* into ``runs`` table. """ run = relationship("SqlRun", backref=backref("tags", cascade="all")) """ SQLAlchemy relationship (many:one) with :py:class:`mlflow.store.dbmodels.models.SqlRun`. """ __table_args__ = (PrimaryKeyConstraint("key", "run_uuid", name="tag_pk"),) def __repr__(self): return f"" class SqlMetric(Base): __tablename__ = "metrics" key = Column(String(250)) """ Metric key: `String` (limit 250 characters). Part of *Primary Key* for ``metrics`` table. """ value = Column(Float, nullable=False) """ Metric value: `Float`. Defined as *Non-null* in schema. """ timestamp = Column(BigInteger, default=lambda: int(time.time())) """ Timestamp recorded for this metric entry: `BigInteger`. Part of *Primary Key* for ``metrics`` table. """ run_uuid = Column(String(32), ForeignKey("runs.run_uuid")) """ Run UUID to which this metric belongs to: Part of *Primary Key* for ``metrics`` table. *Foreign Key* into ``runs`` table. """ run = relationship("SqlRun", backref=backref("metrics", cascade="all")) """ SQLAlchemy relationship (many:one) with :py:class:`mlflow.store.dbmodels.models.SqlRun`. """ __table_args__ = (PrimaryKeyConstraint("key", "timestamp", "run_uuid", name="metric_pk"),) def __repr__(self): return f"" class SqlParam(Base): __tablename__ = "params" key = Column(String(250)) """ Param key: `String` (limit 250 characters). Part of *Primary Key* for ``params`` table. """ value = Column(String(250), nullable=False) """ Param value: `String` (limit 250 characters). Defined as *Non-null* in schema. """ run_uuid = Column(String(32), ForeignKey("runs.run_uuid")) """ Run UUID to which this metric belongs to: Part of *Primary Key* for ``params`` table. *Foreign Key* into ``runs`` table. """ run = relationship("SqlRun", backref=backref("params", cascade="all")) """ SQLAlchemy relationship (many:one) with :py:class:`mlflow.store.dbmodels.models.SqlRun`. """ __table_args__ = (PrimaryKeyConstraint("key", "run_uuid", name="param_pk"),) def __repr__(self): return f""