Skip to content

Index

Note that this module is imported from fractal_server/migrations/env.py, thus we should always export all relevant database models from here or they will not be picked up by alembic.

MODULE DESCRIPTION
base
linkusergroup
linkuserproject
security
v2

v2 models module

CLASS DESCRIPTION
AccountingRecord

AccountingRecord table.

AccountingRecordSlurm

AccountingRecordSlurm table.

DatasetV2

Dataset table.

HistoryImageCache

HistoryImageCache table.

HistoryRun

HistoryRun table.

HistoryUnit

HistoryUnit table.

JobV2

Job table.

OAuthAccount

ORM model for OAuth accounts (oauthaccount database table).

Profile

Profile table.

ProjectV2

Project table.

Resource

Resource table.

TaskGroupV2
TaskV2

Model for the taskv2 database table.

UserGroup

ORM model for the usergroup database table.

UserOAuth

ORM model for the user_oauth database table.

WorkflowTemplate

Model for the workflowtemplate database table.

FUNCTION DESCRIPTION
get_timestamp

Get timezone aware timestamp.

Classes

AccountingRecord

Bases: Base

AccountingRecord table.

Source code in fractal_server/app/models/v2/accounting.py
class AccountingRecord(Base):
    """
    AccountingRecord table.
    """

    __tablename__ = "accountingrecord"

    id: Mapped[int] = mapped_column(primary_key=True)
    user_id: Mapped[int] = mapped_column(
        ForeignKey("user_oauth.id"), nullable=False
    )
    timestamp: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    num_tasks: Mapped[int]
    num_new_images: Mapped[int]

AccountingRecordSlurm

Bases: Base

AccountingRecordSlurm table.

Source code in fractal_server/app/models/v2/accounting.py
class AccountingRecordSlurm(Base):
    """
    AccountingRecordSlurm table.
    """

    __tablename__ = "accountingrecordslurm"

    id: Mapped[int] = mapped_column(primary_key=True)
    user_id: Mapped[int] = mapped_column(
        ForeignKey("user_oauth.id"), nullable=False
    )
    timestamp: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    slurm_job_ids: Mapped[list[int]] = mapped_column(
        ARRAY(Integer), nullable=True, default=list
    )
    fractal_job_id: Mapped[int | None] = mapped_column(
        ForeignKey("jobv2.id"), nullable=True, default=lambda: None
    )
    resource_id: Mapped[int | None] = mapped_column(
        ForeignKey("resource.id", ondelete="SET NULL"),
        nullable=True,
        default=lambda: None,
    )

DatasetV2

Bases: Base

Dataset table.

Source code in fractal_server/app/models/v2/dataset.py
class DatasetV2(Base):
    """
    Dataset table.
    """

    __tablename__ = "datasetv2"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]

    project_id: Mapped[int] = mapped_column(
        ForeignKey("projectv2.id", ondelete="CASCADE")
    )
    project: Mapped["ProjectV2"] = relationship(lazy="selectin")
    is_starred: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )

    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )

    zarr_dir: Mapped[str]
    images: Mapped[list[dict[str, Any]]] = mapped_column(
        JSONB, server_default="[]", nullable=False
    )

    @property
    def image_zarr_urls(self) -> list[str]:
        return [image["zarr_url"] for image in self.images]

HistoryImageCache

Bases: Base

HistoryImageCache table.

Source code in fractal_server/app/models/v2/history.py
class HistoryImageCache(Base):
    """
    HistoryImageCache table.
    """

    __tablename__ = "historyimagecache"

    zarr_url: Mapped[str] = mapped_column(primary_key=True)
    dataset_id: Mapped[int] = mapped_column(
        ForeignKey("datasetv2.id", ondelete="CASCADE"),
        primary_key=True,
        index=True,
    )
    workflowtask_id: Mapped[int] = mapped_column(
        ForeignKey("workflowtaskv2.id", ondelete="CASCADE"),
        primary_key=True,
        index=True,
    )

    latest_history_unit_id: Mapped[int] = mapped_column(
        ForeignKey("historyunit.id", ondelete="CASCADE"),
        index=True,
    )

HistoryRun

Bases: Base

HistoryRun table.

Source code in fractal_server/app/models/v2/history.py
class HistoryRun(Base):
    """
    HistoryRun table.
    """

    __tablename__ = "historyrun"

    id: Mapped[int] = mapped_column(primary_key=True)
    dataset_id: Mapped[int] = mapped_column(
        ForeignKey("datasetv2.id", ondelete="CASCADE"),
    )
    workflowtask_id: Mapped[int | None] = mapped_column(
        ForeignKey("workflowtaskv2.id", ondelete="SET NULL"),
        default=lambda: None,
    )
    job_id: Mapped[int] = mapped_column(ForeignKey("jobv2.id"))
    task_id: Mapped[int | None] = mapped_column(
        ForeignKey("taskv2.id", ondelete="SET NULL")
    )

    workflowtask_dump: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False
    )
    task_group_dump: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False
    )

    timestamp_started: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    status: Mapped[str]
    num_available_images: Mapped[int]

HistoryUnit

Bases: Base

HistoryUnit table.

Source code in fractal_server/app/models/v2/history.py
class HistoryUnit(Base):
    """
    HistoryUnit table.
    """

    __tablename__ = "historyunit"

    id: Mapped[int] = mapped_column(primary_key=True)
    history_run_id: Mapped[int] = mapped_column(
        ForeignKey("historyrun.id", ondelete="CASCADE"),
        index=True,
    )

    logfile: Mapped[str]
    has_warnings: Mapped[bool] = mapped_column(default=False)
    status: Mapped[str]
    zarr_urls: Mapped[list[str]] = mapped_column(ARRAY(String), default=list)

JobV2

Bases: Base

Job table.

Source code in fractal_server/app/models/v2/job.py
class JobV2(Base):
    """
    Job table.
    """

    __tablename__ = "jobv2"

    id: Mapped[int] = mapped_column(primary_key=True)
    project_id: Mapped[int | None] = mapped_column(
        ForeignKey("projectv2.id", ondelete="SET NULL"), default=lambda: None
    )
    workflow_id: Mapped[int | None] = mapped_column(
        ForeignKey("workflowv2.id", ondelete="SET NULL"), default=lambda: None
    )
    dataset_id: Mapped[int | None] = mapped_column(
        ForeignKey("datasetv2.id", ondelete="SET NULL"), default=lambda: None
    )

    user_email: Mapped[str] = mapped_column(nullable=False)
    slurm_account: Mapped[str | None] = mapped_column(default=lambda: None)

    dataset_dump: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False)
    workflow_dump: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False)
    project_dump: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False)
    fractal_server_version: Mapped[str] = mapped_column(
        String, server_default="pre-2.19.0", nullable=False
    )

    worker_init: Mapped[str | None] = mapped_column(default=lambda: None)
    working_dir: Mapped[str | None] = mapped_column(default=lambda: None)
    working_dir_user: Mapped[str | None] = mapped_column(default=lambda: None)
    first_task_index: Mapped[int]
    last_task_index: Mapped[int]

    start_timestamp: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    end_timestamp: Mapped[datetime | None] = mapped_column(
        DateTime(timezone=True), default=lambda: None
    )
    status: Mapped[str] = mapped_column(default=JobStatusType.SUBMITTED)
    log: Mapped[str | None] = mapped_column(default=lambda: None)
    executor_error_log: Mapped[str | None] = mapped_column(default=lambda: None)

    attribute_filters: Mapped[dict[str, list[int | float | str | bool]]] = (
        mapped_column(JSONB, nullable=False, server_default="{}")
    )
    type_filters: Mapped[dict[str, bool]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )

    __table_args__ = (
        Index(
            "ix_jobv2_one_submitted_job_per_dataset",
            "dataset_id",
            unique=True,
            postgresql_where=text(f"status = '{JobStatusType.SUBMITTED}'"),
        ),
    )

OAuthAccount

Bases: Base

ORM model for OAuth accounts (oauthaccount database table).

This class is a modification of SQLAlchemyBaseOAuthAccountTable. Original Copyright: 2021 François Voron, released under MIT licence.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

user_id

TYPE: Mapped[int]

user

TYPE: Mapped[UserOAuth | None]

oauth_name

TYPE: Mapped[str]

access_token

TYPE: Mapped[str]

expires_at

TYPE: Mapped[int | None]

refresh_token

TYPE: Mapped[str | None]

account_id

TYPE: Mapped[str]

account_email

TYPE: Mapped[str]

Source code in fractal_server/app/models/security.py
class OAuthAccount(Base):
    """
    ORM model for OAuth accounts (`oauthaccount` database table).

    This class is a modification of
    [`SQLAlchemyBaseOAuthAccountTable`](https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py).
    Original Copyright: 2021 François Voron, released under MIT licence.

    Attributes:
        id:
        user_id:
        user:
        oauth_name:
        access_token:
        expires_at:
        refresh_token:
        account_id:
        account_email:
    """

    __tablename__ = "oauthaccount"

    id: Mapped[int] = mapped_column(primary_key=True)
    user_id: Mapped[int] = mapped_column(
        ForeignKey("user_oauth.id"), nullable=False
    )
    user: Mapped["UserOAuth | None"] = relationship(
        back_populates="oauth_accounts"
    )
    oauth_name: Mapped[str] = mapped_column(index=True, nullable=False)
    access_token: Mapped[str] = mapped_column(nullable=False)
    expires_at: Mapped[int | None] = mapped_column(
        nullable=True, default=lambda: None
    )
    refresh_token: Mapped[str | None] = mapped_column(
        nullable=True, default=lambda: None
    )
    account_id: Mapped[str] = mapped_column(index=True, nullable=False)
    account_email: Mapped[str] = mapped_column(nullable=False)

Profile

Bases: Base

Profile table.

ATTRIBUTE DESCRIPTION
jobs_remote_dir

Remote path of the job folder (only relevant if

TYPE: Mapped[str | None]

name

Profile name.

TYPE: Mapped[str]

pixi_cache_dir

Override for the PIXI_CACHE_DIR variable, which would otherwise default

TYPE: Mapped[str | None]

resource_type

Type of resource (either local, slurm_sudo or slurm_ssh).

TYPE: Mapped[str]

ssh_key_path

Path to the private SSH key of user username (only relevant if

TYPE: Mapped[str | None]

tasks_remote_dir

Remote path of the task folder (only relevant if

TYPE: Mapped[str | None]

username

Username to be impersonated, either via sudo -u or via ssh.

TYPE: Mapped[str | None]

Source code in fractal_server/app/models/v2/profile.py
class Profile(Base):
    """
    Profile table.
    """

    __tablename__ = "profile"

    id: Mapped[int] = mapped_column(primary_key=True)

    resource_id: Mapped[int] = mapped_column(
        ForeignKey("resource.id", ondelete="RESTRICT")
    )

    resource_type: Mapped[str]
    """
    Type of resource (either `local`, `slurm_sudo` or `slurm_ssh`).
    """

    name: Mapped[str] = mapped_column(unique=True)
    """
    Profile name.
    """

    username: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Username to be impersonated, either via `sudo -u` or via `ssh`.
    """

    ssh_key_path: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Path to the private SSH key of user `username` (only relevant if
    `resource_type="slurm_ssh"`).
    """

    jobs_remote_dir: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Remote path of the job folder (only relevant if
    `resource_type="slurm_ssh"`).
    """

    tasks_remote_dir: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Remote path of the task folder (only relevant if
    `resource_type="slurm_ssh"`).
    """

    pixi_cache_dir: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Override for the `PIXI_CACHE_DIR` variable, which would otherwise default
    to the `cache` subfolder of `PIXI_HOME` (only relevant if
    `resource_type="slurm_ssh"`)
    """

Attributes

jobs_remote_dir = mapped_column(default=lambda: None) class-attribute instance-attribute

Remote path of the job folder (only relevant if resource_type="slurm_ssh").

name = mapped_column(unique=True) class-attribute instance-attribute

Profile name.

pixi_cache_dir = mapped_column(default=lambda: None) class-attribute instance-attribute

Override for the PIXI_CACHE_DIR variable, which would otherwise default to the cache subfolder of PIXI_HOME (only relevant if resource_type="slurm_ssh")

resource_type instance-attribute

Type of resource (either local, slurm_sudo or slurm_ssh).

ssh_key_path = mapped_column(default=lambda: None) class-attribute instance-attribute

Path to the private SSH key of user username (only relevant if resource_type="slurm_ssh").

tasks_remote_dir = mapped_column(default=lambda: None) class-attribute instance-attribute

Remote path of the task folder (only relevant if resource_type="slurm_ssh").

username = mapped_column(default=lambda: None) class-attribute instance-attribute

Username to be impersonated, either via sudo -u or via ssh.

ProjectV2

Bases: Base

Project table.

Source code in fractal_server/app/models/v2/project.py
class ProjectV2(Base):
    """
    Project table.
    """

    __tablename__ = "projectv2"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]

    is_starred: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )
    description: Mapped[str | None] = mapped_column(default=lambda: None)

    resource_id: Mapped[int] = mapped_column(
        ForeignKey("resource.id", ondelete="RESTRICT")
    )
    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )

Resource

Bases: Base

Resource table.

ATTRIBUTE DESCRIPTION
host

Address for ssh connections, when type="slurm_ssh".

TYPE: Mapped[str | None]

jobs_local_dir

Base local folder for job subfolders (containing artifacts and logs).

TYPE: Mapped[str]

jobs_poll_interval

On SLURM resources: the interval to wait before new squeue calls.

TYPE: Mapped[int]

jobs_runner_config

Runner configuration, matching one of JobRunnerConfigLocal or

TYPE: Mapped[dict[str, Any]]

jobs_slurm_python_worker

On SLURM deloyments, this is the Python interpreter that runs the

TYPE: Mapped[str | None]

name

Resource name.

TYPE: Mapped[str]

pip_cache_dir_arg

If pip_cache_dir is set (in self.tasks_python_config), then

TYPE: str

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of

TYPE: Mapped[bool]

tasks_local_dir

Base local folder for task-package subfolders.

TYPE: Mapped[str]

tasks_pixi_config

Pixi configuration for task collection. Basic example:

TYPE: Mapped[dict[str, Any]]

tasks_python_config

Python configuration for task collection. Example:

TYPE: Mapped[dict[str, Any]]

timestamp_created

Creation timestamp (autogenerated).

TYPE: Mapped[datetime]

type

One of local, slurm_sudo or slurm_ssh - matching with

TYPE: Mapped[str]

Source code in fractal_server/app/models/v2/resource.py
class Resource(Base):
    """
    Resource table.
    """

    __tablename__ = "resource"

    id: Mapped[int] = mapped_column(primary_key=True)

    type: Mapped[str]
    """
    One of `local`, `slurm_sudo` or `slurm_ssh` - matching with
    `settings.FRACTAL_RUNNER_BACKEND`.
    """

    name: Mapped[str] = mapped_column(unique=True)
    """
    Resource name.
    """

    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    """
    Creation timestamp (autogenerated).
    """

    host: Mapped[str | None] = mapped_column(default=lambda: None)
    """
    Address for ssh connections, when `type="slurm_ssh"`.
    """

    prevent_new_submissions: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )
    """
    When set to true: Prevent new job submissions and stop execution of
    ongoing jobs as soon as the current task is complete.
    """

    jobs_local_dir: Mapped[str]
    """
    Base local folder for job subfolders (containing artifacts and logs).
    """

    jobs_runner_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Runner configuration, matching one of `JobRunnerConfigLocal` or
    `JobRunnerConfigSLURM` schemas.
    """

    jobs_slurm_python_worker: Mapped[str | None] = mapped_column(
        default=lambda: None
    )
    """
    On SLURM deloyments, this is the Python interpreter that runs the
    `fractal-server` worker from within the SLURM jobs.
    """

    jobs_poll_interval: Mapped[int]
    """
    On SLURM resources: the interval to wait before new `squeue` calls.
    On local resources: ignored.
    """

    # task_settings
    tasks_local_dir: Mapped[str]
    """
    Base local folder for task-package subfolders.
    """

    tasks_python_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Python configuration for task collection. Example:
    ```json
    {
      "default_version": "3.10",
      "versions:{
        "3.10": "/xxx/venv-3.10/bin/python",
        "3.11": "/xxx/venv-3.11/bin/python",
        "3.12": "/xxx/venv-3.12/bin/python"
       }
    }
    ```
    """

    tasks_pixi_config: Mapped[dict[str, Any]] = mapped_column(
        JSONB, nullable=False, server_default="{}"
    )
    """
    Pixi configuration for task collection. Basic example:
    ```json
    {
        "default_version": "0.41.0",
        "versions": {
            "0.40.0": "/xxx/pixi/0.40.0/",
            "0.41.0": "/xxx/pixi/0.41.0/"
        },
    }
    ```
    """

    @property
    def pip_cache_dir_arg(self: Self) -> str:
        """
        If `pip_cache_dir` is set (in `self.tasks_python_config`), then
        return `--cache_dir /something`; else return `--no-cache-dir`.
        """
        _pip_cache_dir = self.tasks_python_config.get("pip_cache_dir", None)
        if _pip_cache_dir is not None:
            return f"--cache-dir {_pip_cache_dir}"
        else:
            return "--no-cache-dir"

    # Check constraints
    __table_args__ = (
        # `type` column must be one of "local", "slurm_sudo" or "slurm_ssh"
        CheckConstraint(
            "type IN ('local', 'slurm_sudo', 'slurm_ssh')",
            name="correct_type",
        ),
        # If `type` is not "local", `jobs_slurm_python_worker` must be set
        CheckConstraint(
            "(type = 'local') OR (jobs_slurm_python_worker IS NOT NULL)",
            name="jobs_slurm_python_worker_set",
        ),
    )

Attributes

host = mapped_column(default=lambda: None) class-attribute instance-attribute

Address for ssh connections, when type="slurm_ssh".

jobs_local_dir instance-attribute

Base local folder for job subfolders (containing artifacts and logs).

jobs_poll_interval instance-attribute

On SLURM resources: the interval to wait before new squeue calls. On local resources: ignored.

jobs_runner_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Runner configuration, matching one of JobRunnerConfigLocal or JobRunnerConfigSLURM schemas.

jobs_slurm_python_worker = mapped_column(default=lambda: None) class-attribute instance-attribute

On SLURM deloyments, this is the Python interpreter that runs the fractal-server worker from within the SLURM jobs.

name = mapped_column(unique=True) class-attribute instance-attribute

Resource name.

pip_cache_dir_arg property

If pip_cache_dir is set (in self.tasks_python_config), then return --cache_dir /something; else return --no-cache-dir.

prevent_new_submissions = mapped_column(BOOLEAN, server_default='false', nullable=False) class-attribute instance-attribute

When set to true: Prevent new job submissions and stop execution of ongoing jobs as soon as the current task is complete.

tasks_local_dir instance-attribute

Base local folder for task-package subfolders.

tasks_pixi_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Pixi configuration for task collection. Basic example:

1
2
3
4
5
6
7
{
    "default_version": "0.41.0",
    "versions": {
        "0.40.0": "/xxx/pixi/0.40.0/",
        "0.41.0": "/xxx/pixi/0.41.0/"
    },
}

tasks_python_config = mapped_column(JSONB, nullable=False, server_default='{}') class-attribute instance-attribute

Python configuration for task collection. Example:

1
2
3
4
5
6
7
8
{
  "default_version": "3.10",
  "versions:{
    "3.10": "/xxx/venv-3.10/bin/python",
    "3.11": "/xxx/venv-3.11/bin/python",
    "3.12": "/xxx/venv-3.12/bin/python"
   }
}

timestamp_created = mapped_column(DateTime(timezone=True), nullable=False, default=get_timestamp) class-attribute instance-attribute

Creation timestamp (autogenerated).

type instance-attribute

One of local, slurm_sudo or slurm_ssh - matching with settings.FRACTAL_RUNNER_BACKEND.

TaskGroupV2

Bases: Base

ATTRIBUTE DESCRIPTION
pinned_package_versions_post_string

Prepare string to be used in python -m pip install.

TYPE: str

pinned_package_versions_pre_string

Prepare string to be used in python -m pip install.

TYPE: str

pip_install_string

Prepare string to be used in python -m pip install.

TYPE: str

Source code in fractal_server/app/models/v2/task_group.py
class TaskGroupV2(Base):
    __tablename__ = "taskgroupv2"

    id: Mapped[int] = mapped_column(primary_key=True)
    task_list: Mapped[list["TaskV2"]] = relationship(
        lazy="selectin", cascade="all, delete-orphan"
    )

    user_id: Mapped[int] = mapped_column(ForeignKey("user_oauth.id"))
    user_group_id: Mapped[int | None] = mapped_column(
        ForeignKey("usergroup.id", ondelete="SET NULL"), default=lambda: None
    )
    resource_id: Mapped[int] = mapped_column(
        ForeignKey("resource.id", ondelete="RESTRICT")
    )

    origin: Mapped[str]
    pkg_name: Mapped[str]
    version: Mapped[str]
    python_version: Mapped[str | None] = mapped_column(default=lambda: None)
    pixi_version: Mapped[str | None] = mapped_column(default=lambda: None)
    path: Mapped[str | None] = mapped_column(default=lambda: None)
    archive_path: Mapped[str | None] = mapped_column(default=lambda: None)
    pip_extras: Mapped[str | None] = mapped_column(default=lambda: None)
    pinned_package_versions_pre: Mapped[dict[str, str]] = mapped_column(
        JSONB,
        server_default="{}",
        default={},
        nullable=True,
    )
    pinned_package_versions_post: Mapped[dict[str, str]] = mapped_column(
        JSONB,
        server_default="{}",
        default={},
        nullable=True,
    )
    env_info: Mapped[str | None] = mapped_column(default=lambda: None)
    venv_path: Mapped[str | None] = mapped_column(default=lambda: None)

    active: Mapped[bool] = mapped_column(default=True)
    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    timestamp_last_used: Mapped[datetime] = mapped_column(
        DateTime(timezone=True),
        nullable=False,
        server_default=(
            datetime(2024, 11, 20, tzinfo=timezone.utc).isoformat()
        ),
        default=get_timestamp,
    )

    __table_args__ = (
        Index(
            "ix_taskgroupv2_path_unique_constraint",
            "path",
            "resource_id",
            unique=True,
        ),
    )

    @property
    def pip_install_string(self) -> str:
        """
        Prepare string to be used in `python -m pip install`.
        """
        _check_origin_not_pixi(self.origin)

        extras = (
            f"[{self.pip_extras}]"
            if (self.pip_extras is not None and self.pip_extras != "")
            else ""
        )

        if self.archive_path is not None:
            return f"{self.archive_path}{extras}"
        else:
            return f"{self.pkg_name}{extras}=={self.version}"

    @property
    def pinned_package_versions_pre_string(self) -> str:
        """
        Prepare string to be used in `python -m pip install`.
        """
        _check_origin_not_pixi(self.origin)

        if self.pinned_package_versions_pre is None:
            return ""
        output = _create_dependency_string(self.pinned_package_versions_pre)
        return output

    @property
    def pinned_package_versions_post_string(self) -> str:
        """
        Prepare string to be used in `python -m pip install`.
        """
        _check_origin_not_pixi(self.origin)

        if self.pinned_package_versions_post is None:
            return ""
        output = _create_dependency_string(self.pinned_package_versions_post)
        return output

Attributes

pinned_package_versions_post_string property

Prepare string to be used in python -m pip install.

pinned_package_versions_pre_string property

Prepare string to be used in python -m pip install.

pip_install_string property

Prepare string to be used in python -m pip install.

TaskV2

Bases: Base

Model for the taskv2 database table.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

name

TYPE: Mapped[str]

type

TYPE: Mapped[str]

version

TYPE: Mapped[str]

command_non_parallel

TYPE: Mapped[str | None]

command_parallel

TYPE: Mapped[str | None]

meta_non_parallel

TYPE: Mapped[dict[str, Any]]

meta_parallel

TYPE: Mapped[dict[str, Any]]

input_types

TYPE: Mapped[dict[str, bool]]

output_types

TYPE: Mapped[dict[str, bool]]

taskgroupv2_id

TYPE: Mapped[int]

args_schema_version

TYPE: Mapped[str | None]

args_schema_non_parallel

TYPE: Mapped[dict[str, Any] | None]

args_schema_parallel

TYPE: Mapped[dict[str, Any] | None]

docs_info

TYPE: Mapped[str | None]

docs_link

TYPE: Mapped[str | None]

category

TYPE: Mapped[str | None]

modality

TYPE: Mapped[str | None]

authors

TYPE: Mapped[str | None]

tags

TYPE: Mapped[list[str]]

Source code in fractal_server/app/models/v2/task.py
class TaskV2(Base):
    """
    Model for the `taskv2` database table.

    Attributes:
        id:
        name:
        type:
        version:
        command_non_parallel:
        command_parallel:
        meta_non_parallel:
        meta_parallel:
        input_types:
        output_types:
        taskgroupv2_id:
        args_schema_version:
        args_schema_non_parallel:
        args_schema_parallel:
        docs_info:
        docs_link:
        category:
        modality:
        authors:
        tags:
    """

    __tablename__ = "taskv2"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str]

    type: Mapped[str]
    command_non_parallel: Mapped[str | None] = mapped_column(
        default=lambda: None
    )
    command_parallel: Mapped[str | None] = mapped_column(default=lambda: None)

    meta_non_parallel: Mapped[dict[str, Any]] = mapped_column(
        JSON, server_default="{}", default={}, nullable=False
    )
    meta_parallel: Mapped[dict[str, Any]] = mapped_column(
        JSON, server_default="{}", default={}, nullable=False
    )

    version: Mapped[str]
    args_schema_non_parallel: Mapped[dict[str, Any] | None] = mapped_column(
        JSON, default=lambda: None
    )
    args_schema_parallel: Mapped[dict[str, Any] | None] = mapped_column(
        JSON, default=lambda: None
    )
    args_schema_version: Mapped[str | None] = mapped_column(
        default=lambda: None
    )
    docs_info: Mapped[str | None] = mapped_column(default=lambda: None)
    docs_link: Mapped[str | None] = mapped_column(default=lambda: None)

    input_types: Mapped[dict[str, bool]] = mapped_column(
        JSONB, nullable=True, default={}
    )
    output_types: Mapped[dict[str, bool]] = mapped_column(
        JSONB, nullable=True, default={}
    )

    taskgroupv2_id: Mapped[int] = mapped_column(ForeignKey("taskgroupv2.id"))

    category: Mapped[str | None] = mapped_column(default=lambda: None)
    modality: Mapped[str | None] = mapped_column(default=lambda: None)
    authors: Mapped[str | None] = mapped_column(default=lambda: None)
    tags: Mapped[list[str]] = mapped_column(
        JSONB, server_default="[]", nullable=False
    )
    is_core: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )
    __table_args__ = (
        Index(
            "ix_taskv2_one_task_name_per_task_group",
            "name",
            "taskgroupv2_id",
            unique=True,
        ),
    )

UserGroup

Bases: Base

ORM model for the usergroup database table.

ATTRIBUTE DESCRIPTION
id

ID of the group

TYPE: Mapped[int]

name

Name of the group

TYPE: Mapped[str]

timestamp_created

Time of creation

TYPE: Mapped[datetime]

Source code in fractal_server/app/models/security.py
class UserGroup(Base):
    """
    ORM model for the `usergroup` database table.

    Attributes:
        id: ID of the group
        name: Name of the group
        timestamp_created: Time of creation
    """

    __tablename__ = "usergroup"

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column(unique=True)
    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )

UserOAuth

Bases: Base

ORM model for the user_oauth database table.

This class is a modification of SQLAlchemyBaseUserTable from fastapi_users_db_sqlalchemy. Original Copyright: 2021 François Voron, released under MIT licence.

Note that some class attributes (e.g is_active, is_verified and is_superuser) are the default ones from fastapi-users - see https://fastapi-users.github.io/fastapi-users/latest/configuration/schemas.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

email

TYPE: Mapped[str]

hashed_password

TYPE: Mapped[str]

is_active

If this is False, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[bool]

is_superuser

TYPE: Mapped[bool]

is_verified

If this is False, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[bool]

oauth_accounts

TYPE: Mapped[list[OAuthAccount]]

profile_id

Foreign key linking the user to a Profile. If this is unset, the user has no access to the /api/v2/ endpoints.

TYPE: Mapped[int | None]

project_dirs

Absolute paths of the user's project directory. This is used (A) as a default base folder for the zarr_dir of new datasets (where the output Zarr are located), and (B) as a folder which is included by default in the paths that a user is allowed to stream (if the fractal-data integration is set up). two goals:

TYPE: Mapped[list[str]]

slurm_accounts

List of SLURM accounts that the user can select upon running a job.

TYPE: Mapped[list[str]]

Source code in fractal_server/app/models/security.py
class UserOAuth(Base):
    """
    ORM model for the `user_oauth` database table.

    This class is a modification of
    [`SQLAlchemyBaseUserTable`](https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py)
    from `fastapi_users_db_sqlalchemy`.
    Original Copyright: 2021 François Voron, released under MIT licence.

    Note that some class attributes (e.g `is_active`, `is_verified` and
    `is_superuser`) are the default ones from `fastapi-users` - see
    https://fastapi-users.github.io/fastapi-users/latest/configuration/schemas.

    Attributes:
        id:
        email:
        hashed_password:
        is_active:
            If this is `False`, the user has no access to the `/api/v2/`
            endpoints.
        is_superuser:
        is_verified:
            If this is `False`, the user has no access to the `/api/v2/`
            endpoints.
        oauth_accounts:
        profile_id:
            Foreign key linking the user to a `Profile`. If this is unset,
            the user has no access to the `/api/v2/` endpoints.
        project_dirs:
            Absolute paths of the user's project directory. This is used (A) as
            a default base folder for the `zarr_dir` of new datasets (where
            the output Zarr are located), and (B) as a folder which is included
            by default in the paths that a user is allowed to stream (if the
            `fractal-data` integration is set up).
            two goals:
        slurm_accounts:
            List of SLURM accounts that the user can select upon running a job.
    """

    __tablename__ = "user_oauth"

    id: Mapped[int] = mapped_column(primary_key=True)

    email: Mapped[str] = mapped_column(unique=True, index=True, nullable=False)
    hashed_password: Mapped[str]
    is_active: Mapped[bool] = mapped_column(default=True, nullable=False)
    is_superuser: Mapped[bool] = mapped_column(default=False, nullable=False)
    is_verified: Mapped[bool] = mapped_column(default=False, nullable=False)
    is_guest: Mapped[bool] = mapped_column(
        BOOLEAN,
        server_default="false",
        nullable=False,
    )

    oauth_accounts: Mapped[list["OAuthAccount"]] = relationship(
        back_populates="user",
        lazy="joined",
        cascade="all, delete",
    )

    profile_id: Mapped[int | None] = mapped_column(
        ForeignKey("profile.id", ondelete="RESTRICT"), default=lambda: None
    )

    project_dirs: Mapped[list[str]] = mapped_column(
        ARRAY(String), nullable=False
    )

    slurm_accounts: Mapped[list[str]] = mapped_column(
        ARRAY(String), nullable=True, server_default="{}"
    )

    __table_args__ = (
        CheckConstraint(
            "NOT (is_superuser AND is_guest)",
            name="superuser_is_not_guest",
        ),
    )

WorkflowTemplate

Bases: Base

Model for the workflowtemplate database table.

ATTRIBUTE DESCRIPTION
id

TYPE: Mapped[int]

user_id

TYPE: Mapped[int]

name

TYPE: Mapped[str]

version

TYPE: Mapped[int]

fractal_server_version

TYPE: Mapped[str]

timestamp_created

TYPE: Mapped[datetime]

timestamp_last_used

TYPE: Mapped[datetime]

user_group_id

TYPE: Mapped[int | None]

description

TYPE: Mapped[str | None]

data

TYPE: Mapped[dict[str, Any]]

Source code in fractal_server/app/models/v2/workflow_template.py
class WorkflowTemplate(Base):
    """
    Model for the `workflowtemplate` database table.

    Attributes:
        id:
        user_id:
        name:
        version:
        fractal_server_version:
        timestamp_created:
        timestamp_last_used:
        user_group_id:
        description:
        data:
    """

    __tablename__ = "workflowtemplate"

    id: Mapped[int] = mapped_column(primary_key=True)

    user_id: Mapped[int] = mapped_column(
        ForeignKey("user_oauth.id"), nullable=False
    )
    name: Mapped[str]
    version: Mapped[int]

    fractal_server_version: Mapped[str]
    timestamp_created: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )
    timestamp_last_used: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, default=get_timestamp
    )

    user_group_id: Mapped[int | None] = mapped_column(
        ForeignKey("usergroup.id", ondelete="SET NULL"), default=lambda: None
    )

    description: Mapped[str | None] = mapped_column(default=lambda: None)
    data: Mapped[dict[str, Any]] = mapped_column(JSON, nullable=False)

    __table_args__ = (
        Index(
            "ix_workflowtemplate_user_name_version_unique_constraint",
            "user_id",
            "name",
            "version",
            unique=True,
        ),
    )

Functions:

get_timestamp()

Get timezone aware timestamp.

Source code in fractal_server/utils.py
def get_timestamp() -> datetime:
    """
    Get timezone aware timestamp.
    """
    return datetime.now(tz=timezone.utc)