Snapshot API¶
Snapshot bundle models.
- class sqldbagent.snapshot.models.SnapshotRequestModel(**data)[source]¶
Bases:
BaseModelSnapshot regeneration request.
- Variables:
datasource_name – Datasource identifier.
schema_name – Schema name captured by the snapshot.
sample_size – Sample size used for table profiling.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class sqldbagent.snapshot.models.SnapshotBundleModel(**data)[source]¶
Bases:
BaseModelNormalized persisted snapshot bundle.
- Variables:
snapshot_id – Stable snapshot identifier.
format_version – Snapshot format version.
created_at – Snapshot creation timestamp.
datasource_name – Datasource identifier.
schema_metadata – Normalized schema metadata.
relationship_edges – Relationship graph edges derived from foreign keys.
profiles – Per-table profiles captured with the snapshot.
content_hash – Deterministic content hash for deduplication and drift detection.
summary – Generated short summary.
regenerate – Request payload that can rebuild the snapshot later.
- Parameters:
data (
Any)snapshot_id (str)
format_version (int)
created_at (datetime)
datasource_name (str)
schema_metadata (SchemaModel)
relationship_edges (list[RelationshipEdgeModel])
profiles (list[TableProfileModel])
content_hash (str | None)
summary (str | None)
regenerate (SnapshotRequestModel)
- schema_metadata: SchemaModel¶
- relationship_edges: list[RelationshipEdgeModel]¶
- profiles: list[TableProfileModel]¶
- regenerate: SnapshotRequestModel¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class sqldbagent.snapshot.models.SnapshotInventoryEntryModel(**data)[source]¶
Bases:
BaseModelStored snapshot inventory entry.
- Variables:
datasource_name – Datasource identifier.
schema_name – Captured schema name.
snapshot_id – Snapshot identifier.
created_at – Snapshot creation timestamp.
content_hash – Snapshot content hash.
path – Relative snapshot path under the snapshot root.
summary – Summary context for the stored snapshot.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class sqldbagent.snapshot.models.TableDiffModel(**data)[source]¶
Bases:
BaseModelPer-table snapshot diff details.
- Variables:
table_name – Qualified or unqualified table name.
added_columns – Columns present only in the right snapshot.
removed_columns – Columns present only in the left snapshot.
changed_columns – Columns present in both snapshots but with changed metadata.
metadata_changed – Whether non-column metadata changed.
profile_changed – Whether the normalized table profile changed.
summary – Generated short summary.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
- class sqldbagent.snapshot.models.SnapshotDiffModel(**data)[source]¶
Bases:
BaseModelHigh-level diff between two snapshot bundles.
- Variables:
left_snapshot_id – Baseline snapshot identifier.
right_snapshot_id – Comparison snapshot identifier.
left_content_hash – Baseline content hash.
right_content_hash – Comparison content hash.
added_tables – Tables added in the right snapshot.
removed_tables – Tables removed from the right snapshot.
changed_tables – Tables present in both snapshots with metadata changes.
added_views – Views added in the right snapshot.
removed_views – Views removed from the right snapshot.
added_relationships – Relationships added in the right snapshot.
removed_relationships – Relationships removed from the right snapshot.
summary – Generated short summary.
- Parameters:
- changed_tables: list[TableDiffModel]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
Snapshot persistence service.
- class sqldbagent.snapshot.service.SnapshotService(*, datasource_name, inspector, profiler, artifacts)[source]¶
Bases:
objectCreate, persist, reload, and diff normalized snapshot bundles.
- Parameters:
datasource_name (
str)inspector (
SQLAlchemyInspectionService)profiler (
SQLAlchemyProfilingService)artifacts (
ArtifactSettings)
- __init__(*, datasource_name, inspector, profiler, artifacts)[source]¶
Initialize the snapshot service.
- Parameters:
datasource_name (
str) – Datasource identifier.inspector (
SQLAlchemyInspectionService) – Inspection service used for schema metadata.profiler (
SQLAlchemyProfilingService) – Profiling service used for table profiles.artifacts (
ArtifactSettings) – Artifact persistence settings.
- Return type:
None
- create_schema_snapshot(schema_name, *, sample_size=5)[source]¶
Create a snapshot bundle for one schema.
- Parameters:
- Returns:
Snapshot bundle.
- Return type:
- save_snapshot(bundle)[source]¶
Persist a snapshot bundle to disk and update the inventory index.
- Parameters:
bundle (
SnapshotBundleModel) – Snapshot bundle to persist.- Returns:
Snapshot file path.
- Return type:
- static load_snapshot(path)[source]¶
Load a snapshot bundle from disk.
- Parameters:
- Returns:
Loaded snapshot bundle.
- Return type:
- static diff_snapshots(left, right)[source]¶
Diff two snapshot bundles.
- Parameters:
left (
SnapshotBundleModel) – Baseline snapshot bundle.right (
SnapshotBundleModel) – Comparison snapshot bundle.
- Returns:
Snapshot diff payload.
- Return type:
- static list_saved_snapshots(artifacts, *, datasource_name=None, schema_name=None)[source]¶
List saved snapshots from the inventory index.
- Parameters:
artifacts (
ArtifactSettings) – Artifact persistence settings.datasource_name (
str|None, default:None) – Optional datasource filter.schema_name (
str|None, default:None) – Optional schema filter.
- Returns:
Matching saved snapshots.
- Return type:
- static load_latest_snapshot(artifacts, *, datasource_name, schema_name)[source]¶
Load the newest saved snapshot for a datasource/schema pair.
- Parameters:
artifacts (
ArtifactSettings) – Artifact persistence settings.datasource_name (
str) – Datasource identifier.schema_name (
str) – Captured schema name.
- Returns:
Latest matching snapshot.
- Return type:
- Raises:
FileNotFoundError – If no matching snapshot exists.
- property snapshot_dir: Path¶
Return the configured snapshot directory.
- Returns:
Snapshot directory path.
- Return type:
Path
- property artifacts: ArtifactSettings¶
Return the artifact settings bound to this service.