Skip to main content

prefect.server.database.interface

Classes

DBSingleton

Ensures that only one database interface is created per unique key

PrefectDBInterface

An interface for backend-specific SqlAlchemy actions and ORM models. The REST API can be configured to run against different databases in order maintain performance at different scales. This interface integrates database- and dialect- specific configuration into a unified interface that the orchestration engine runs against. Methods:

Agent

An agent model

Artifact

An artifact orm model

ArtifactCollection

An artifact collection orm model

Automation

An automation model

AutomationBucket

An automation bucket model

AutomationEventFollower

A model capturing one event following another event

AutomationRelatedResource

An automation related resource model

Base

Base class for orm models

BlockDocument

A block document model

BlockDocumentReference

A block document reference model

BlockSchema

A block schema model

BlockSchemaReference

A block schema reference model

BlockType

A block type model

CompositeTriggerChildFiring

A model capturing a composite trigger’s child firing

ConcurrencyLimit

A concurrency model

ConcurrencyLimitV2

A v2 concurrency model

Configuration

An configuration model

CsrfToken

A csrf token model

Deployment

A deployment orm model

DeploymentSchedule

A deployment schedule orm model

Event

An event model

EventResource

An event resource model

Flow

A flow orm model

FlowRun

A flow run orm model

FlowRunInput

A flow run input model

FlowRunState

A flow run state orm model

Log

A log orm model

SavedSearch

A saved search orm model

TaskRun

A task run orm model

TaskRunState

A task run state orm model

TaskRunStateCache

A task run state cache orm model

Variable

A variable model

WorkPool

A work pool orm model

WorkQueue

A work queue model

Worker

A worker process orm model

create_db

Create the database

dialect

drop_db

Drop the database by removing all tables directly. This reflects the actual database schema and drops every table rather than running all Alembic downgrade migrations in reverse. Running downgrades is fragile because individual migration downgrade steps may fail on real-world data (e.g. re-adding a foreign key constraint when orphaned references exist). Dropping tables directly is both faster and more robust. Reflection is used instead of Base.metadata.drop_all() so that tables created by migrations but not tracked in the ORM (e.g. deployment_version, alembic_version) are also removed.

engine

Provides a SqlAlchemy engine against a specific database.

is_db_connectable

Returns boolean indicating if the database is connectable. This method is used to determine if the server is ready to accept requests.

run_migrations_downgrade

Run all downgrade migrations

run_migrations_upgrade

Run all upgrade migrations

session

Provides a SQLAlchemy session.

session_context

Provides a SQLAlchemy session and a context manager for opening/closing the underlying connection. Args:
  • begin_transaction: if True, the context manager will begin a SQL transaction. Exiting the context manager will COMMIT or ROLLBACK any changes.