etlantic-sqlmodel API¶
Status: Available in ETLantic 0.41.0. SQLModel bridge helpers. Install narrative: package README. Hub: Optional packages API.
Setup¶
Failure modes¶
| Topic | Behavior |
|---|---|
| Model mismatch | Type/bridge errors |
Public API¶
etlantic_sqlmodel
¶
etlantic-sqlmodel — ContractModel ↔ SQLModel bridge + CP1 reference stores.
AliasRow
¶
Bases: SQLModel
Scoped alias pointing at an immutable revision.
EnvironmentRow
¶
Bases: SQLModel
Deployment / promotion environment directory row.
LogicalIdentityRow
¶
Bases: SQLModel
Stable logical identity preserved across revisions.
PromotionRow
¶
Bases: SQLModel
Immutable promotion record preserving logical_id.
RevisionRow
¶
Bases: SQLModel
Immutable append-only registry revision.
SecurityDomainRow
¶
Bases: SQLModel
Security-domain directory row.
SQLModelDefinitionRepository
¶
Workspace-scoped definition registry backed by SQLModel.
SqlModelEventStore
¶
Minimal SQLModel-backed EventStore with tenant/workspace isolation.
SqlModelRegistryProvider
dataclass
¶
SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)
SQLModel :class:RegistryProvider with shared suspension checks.
SqlModelRevisionRegistry
dataclass
¶
SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)
Append-only SQLModel revision store with aliases and promotions.
SQLModelSubmissionStore
¶
Durable acceptance store with ADR-016 scoped idempotency and run observation.
SqlModelTenantDirectory
dataclass
¶
SQLModel tenant directory with isolation and suspension fail-closed.
SqlModelWorkspaceDirectory
dataclass
¶
SQLModel workspace directory keyed by (tenant_id, workspace_id).
TenantRow
¶
Bases: SQLModel
Durable tenant directory row (CP2 / 040-P).
WorkspaceRow
¶
Bases: SQLModel
Durable workspace directory row (tenant-owned).
SqlModelIntegrationPlugin
¶
Schema bridge helpers without ORM sessions or migrations.
create_control_plane_tables
¶
Create CP reference tables.
Intended for tests and local demos — not a production migration path.
create_registry_tables
¶
Create CP2 registry tables.
Intended for tests and local demos — not a production migration path.
Prefer :mod:etlantic_sqlmodel.migrations.
create_sqlite_engine
¶
Create an engine; use a file URL for restart durability tests.
make_session_factory
¶
Return a zero-arg factory that opens a short-lived Session.
request_scoped_session
¶
FastAPI-compatible dependency generator for a request-scoped session.
Sessions stay in the API layer — never pass them into pipeline runtimes.
session_scope
¶
Yield a session that commits on success and rolls back on error.
apply_migrations
¶
Upgrade to the latest migration (SQLite-friendly for tests).
current_version
¶
Return the applied migration version, or None on a fresh database.
downgrade
¶
Roll back migrations down to target (None = empty schema).
upgrade
¶
Apply pending migrations up to target (default: latest).
contract_to_sqlmodel
¶
contract_to_sqlmodel(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> type[SQLModel]
Generate a SQLModel table class from a Data / ContractModel class.
contract_to_sqlmodel_source
¶
contract_to_sqlmodel_source(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> str
Generate importable SQLModel source for a Data / ContractModel class.
sqlmodel_to_contract
¶
Extract draft contract metadata from a SQLModel table class.
primary_key_fields
¶
Return ordered primary-key column names from a SQLModel table class.
validate_model_primary_keys
¶
validate_model_primary_keys(model_cls: type[Any], *, expected_keys: tuple[str, ...] | list[str] | None = None) -> ValidationReport
Fail closed when a SQLModel table lacks the expected primary key.
compare_metadata
¶
Compare contract and SQLModel metadata; return a ValidationReport.
create_plugin
¶
Entry-point factory for tooling and conformance helpers.
run_conformance_checks
¶
run_conformance_checks(contract_cls: type[Data], *, table_name: str | None = None, primary_key: tuple[str, ...] | None = None) -> ValidationReport
Round-trip contract → SQLModel → metadata and compare schemas.
control_plane
¶
Optional SQLModel control-plane reference stores (CP1/CP2).
Persistence models are separate from HTTP response models. Sessions are
request-scoped helpers and must not be passed into pipeline runtimes.
create_control_plane_tables / create_registry_tables are for
tests/demos — production must apply versioned migrations under
etlantic_sqlmodel.migrations.
SQLModelDurableWorkStore
¶
SQLModelDurableWorkStore(engine: Engine, *, admission_limit: int | None = None, store_id: str = 'default')
Transactional DurableWorkStore backed by a SQL snapshot row.
AliasRow
¶
Bases: SQLModel
Scoped alias pointing at an immutable revision.
DurableSnapshotRow
¶
Bases: SQLModel
Transactional CP3 durable-work snapshot (reference provider).
One logical store per engine; mutations load/save under a DB transaction so accept+outbox and fencing CAS share commit boundaries.
EnvironmentRow
¶
Bases: SQLModel
Deployment / promotion environment directory row.
LogicalIdentityRow
¶
Bases: SQLModel
Stable logical identity preserved across revisions.
PromotionRow
¶
Bases: SQLModel
Immutable promotion record preserving logical_id.
RevisionRow
¶
Bases: SQLModel
Immutable append-only registry revision.
SecurityDomainRow
¶
Bases: SQLModel
Security-domain directory row.
TenantRow
¶
Bases: SQLModel
Durable tenant directory row (CP2 / 040-P).
WorkspaceRow
¶
Bases: SQLModel
Durable workspace directory row (tenant-owned).
BackupTranscript
dataclass
¶
BackupTranscript(schema: str, created_at: str, tenants: tuple[dict[str, Any], ...], workspaces: tuple[dict[str, Any], ...], revisions: tuple[dict[str, Any], ...], logicals: tuple[dict[str, Any], ...] = (), aliases: tuple[dict[str, Any], ...] = (), promotions: tuple[dict[str, Any], ...] = (), environments: tuple[dict[str, Any], ...] = (), security_domains: tuple[dict[str, Any], ...] = ())
Structured backup transcript (scope-preserving).
SqlModelRegistryProvider
dataclass
¶
SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)
SQLModel :class:RegistryProvider with shared suspension checks.
SqlModelRevisionRegistry
dataclass
¶
SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)
Append-only SQLModel revision store with aliases and promotions.
SqlModelTenantDirectory
dataclass
¶
SQLModel tenant directory with isolation and suspension fail-closed.
SqlModelWorkspaceDirectory
dataclass
¶
SQLModel workspace directory keyed by (tenant_id, workspace_id).
SQLModelDefinitionRepository
¶
Workspace-scoped definition registry backed by SQLModel.
SqlModelEventStore
¶
Minimal SQLModel-backed EventStore with tenant/workspace isolation.
SQLModelSubmissionStore
¶
Durable acceptance store with ADR-016 scoped idempotency and run observation.
create_durable_tables
¶
Create CP3 durable tables (tests/demos only).
backup_round_trip
¶
Dump source and load into destination; return the transcript.
dump_registry_sqlite
¶
Dump tenants, workspaces, and revisions from a registry SQLite engine.
load_registry_sqlite
¶
load_registry_sqlite(engine: Engine, transcript: BackupTranscript, *, create_tables: bool = True) -> SqlModelRegistryProvider
Restore tenants/workspaces/revisions into engine, preserving scope.
read_backup_transcript
¶
Read a backup transcript JSON file.
write_backup_transcript
¶
Write a backup transcript JSON file.
collect_revision_hits
¶
collect_revision_hits(provider: SqlModelRegistryProvider, ctx: ControlPlaneContext, *, logical_id: str | None = None, kind: str | None = None) -> Sequence[RevisionSearchHit]
Return metadata-only hits for ctx scope (no content bodies).
create_registry_tables
¶
Create CP2 registry tables.
Intended for tests and local demos — not a production migration path.
Prefer :mod:etlantic_sqlmodel.migrations.
create_sqlite_engine
¶
Create an engine; use a file URL for restart durability tests.
make_session_factory
¶
Return a zero-arg factory that opens a short-lived Session.
request_scoped_session
¶
FastAPI-compatible dependency generator for a request-scoped session.
Sessions stay in the API layer — never pass them into pipeline runtimes.
session_scope
¶
Yield a session that commits on success and rolls back on error.
create_control_plane_tables
¶
Create CP reference tables.
Intended for tests and local demos — not a production migration path.
durable_stores
¶
SQLModel-backed DurableWorkStore (CP3 / 041-P).
Reference provider: each mutating call loads the durable snapshot inside a
database transaction, applies MemoryDurableWorkStore semantics, and writes the
snapshot back with an optimistic payload_version check before commit.
Production note: apply versioned migrations — do not rely on
create_durable_tables as the sole schema path.
models
¶
SQLModel persistence tables for control-plane reference stores.
These are persistence models only — not HTTP response models and not ETLantic pipeline contracts.
TenantRow
¶
Bases: SQLModel
Durable tenant directory row (CP2 / 040-P).
WorkspaceRow
¶
Bases: SQLModel
Durable workspace directory row (tenant-owned).
LogicalIdentityRow
¶
Bases: SQLModel
Stable logical identity preserved across revisions.
RevisionRow
¶
Bases: SQLModel
Immutable append-only registry revision.
AliasRow
¶
Bases: SQLModel
Scoped alias pointing at an immutable revision.
PromotionRow
¶
Bases: SQLModel
Immutable promotion record preserving logical_id.
EnvironmentRow
¶
Bases: SQLModel
Deployment / promotion environment directory row.
SecurityDomainRow
¶
Bases: SQLModel
Security-domain directory row.
DurableSnapshotRow
¶
Bases: SQLModel
Transactional CP3 durable-work snapshot (reference provider).
One logical store per engine; mutations load/save under a DB transaction so accept+outbox and fencing CAS share commit boundaries.
registry_backup
¶
Registry SQLite backup/restore transcript helpers (CP2 / 040-O).
Dump and load tenants, workspaces, and revisions while preserving compound tenant/workspace scope. Content bodies are included for round-trip fidelity but histories/impact remain separate (metadata-only stores).
BackupTranscript
dataclass
¶
BackupTranscript(schema: str, created_at: str, tenants: tuple[dict[str, Any], ...], workspaces: tuple[dict[str, Any], ...], revisions: tuple[dict[str, Any], ...], logicals: tuple[dict[str, Any], ...] = (), aliases: tuple[dict[str, Any], ...] = (), promotions: tuple[dict[str, Any], ...] = (), environments: tuple[dict[str, Any], ...] = (), security_domains: tuple[dict[str, Any], ...] = ())
Structured backup transcript (scope-preserving).
dump_registry_sqlite
¶
Dump tenants, workspaces, and revisions from a registry SQLite engine.
write_backup_transcript
¶
Write a backup transcript JSON file.
read_backup_transcript
¶
Read a backup transcript JSON file.
load_registry_sqlite
¶
load_registry_sqlite(engine: Engine, transcript: BackupTranscript, *, create_tables: bool = True) -> SqlModelRegistryProvider
Restore tenants/workspaces/revisions into engine, preserving scope.
backup_round_trip
¶
Dump source and load into destination; return the transcript.
registry_search
¶
SQLModel-backed revision metadata search (CP2 / 040-O).
collect_revision_hits
¶
collect_revision_hits(provider: SqlModelRegistryProvider, ctx: ControlPlaneContext, *, logical_id: str | None = None, kind: str | None = None) -> Sequence[RevisionSearchHit]
Return metadata-only hits for ctx scope (no content bodies).
registry_stores
¶
SQLModel-backed RegistryProvider implementations (CP2 / 040-P).
Production deployments must apply versioned migrations — do not rely on
create_all / create_registry_tables as the sole schema path.
SqlModelTenantDirectory
dataclass
¶
SQLModel tenant directory with isolation and suspension fail-closed.
SqlModelWorkspaceDirectory
dataclass
¶
SQLModel workspace directory keyed by (tenant_id, workspace_id).
SqlModelRevisionRegistry
dataclass
¶
SqlModelRevisionRegistry(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None)
Append-only SQLModel revision store with aliases and promotions.
SqlModelRegistryProvider
dataclass
¶
SqlModelRegistryProvider(engine: Engine, tenants: SqlModelTenantDirectory | None = None, workspaces: SqlModelWorkspaceDirectory | None = None, revisions: SqlModelRevisionRegistry | None = None)
SQLModel :class:RegistryProvider with shared suspension checks.
create_registry_tables
¶
Create CP2 registry tables.
Intended for tests and local demos — not a production migration path.
Prefer :mod:etlantic_sqlmodel.migrations.
session
¶
Request-scoped SQLModel session helpers for control-plane stores.
create_sqlite_engine
¶
Create an engine; use a file URL for restart durability tests.
session_scope
¶
Yield a session that commits on success and rolls back on error.
make_session_factory
¶
Return a zero-arg factory that opens a short-lived Session.
request_scoped_session
¶
FastAPI-compatible dependency generator for a request-scoped session.
Sessions stay in the API layer — never pass them into pipeline runtimes.
stores
¶
SQLModel-backed DefinitionRepository and SubmissionStore implementations.
SQLModelDefinitionRepository
¶
Workspace-scoped definition registry backed by SQLModel.
SQLModelSubmissionStore
¶
Durable acceptance store with ADR-016 scoped idempotency and run observation.
SqlModelEventStore
¶
Minimal SQLModel-backed EventStore with tenant/workspace isolation.
create_control_plane_tables
¶
Create CP reference tables.
Intended for tests and local demos — not a production migration path.
migrations
¶
Lightweight versioned migrations for etlantic-sqlmodel control-plane tables.
Production must apply these migrations (or an equivalent Alembic chain). Do
not treat SQLModel.metadata.create_all / create_control_plane_tables
/ create_registry_tables as the sole production schema path.
current_version
¶
Return the applied migration version, or None on a fresh database.
upgrade
¶
Apply pending migrations up to target (default: latest).
downgrade
¶
Roll back migrations down to target (None = empty schema).
apply_migrations
¶
Upgrade to the latest migration (SQLite-friendly for tests).