Skip to main content

Module deployment_snapshot

Module deployment_snapshot 

Source
Expand description

Deployment snapshot tracking.

This module provides functionality for capturing and comparing deployment state snapshots. Instead of hashing source files, it hashes normalized compiled objects so formatting and comment changes don’t trigger unnecessary redeployments.

A deployment snapshot captures the state of all deployed objects with their content hashes, enabling change detection (like git diff but for database objects) and supporting blue/green deployment workflows.

§What’s Hashed

Content hashes are computed by compute_typed_hash from the compiled AST representation of each object, not the source SQL file contents. The hash includes:

  • The main CREATE statement (via Hash on the AST node)
  • All indexes (sorted deterministically by cluster, on_name, name, key_parts)

Hashing uses SHA-256 (via a Sha256Hasher bridge to std::hash::Hash) for cross-platform stability. The output format is sha256:<hex>.

Key Insight: Because the hash is computed from the parsed AST, changes that are syntactically equivalent (whitespace, comment edits, identifier casing) produce identical hashes and do not trigger redeployment.

§Apply-Managed Exclusions

Tables, table-from-source, sources, secrets, and connections are excluded from snapshots by build_snapshot_from_planned because they are managed by the apply command path and should not participate in deployment hash change detection.

§Snapshot Storage

Snapshots are persisted in the _mz_deploy database:

  • _mz_deploy.public.deployments — per-schema deployment metadata
  • _mz_deploy.public.objects — per-object content hashes (append-only)

Structs§

DeploymentMetadata
Metadata collected during deployment.
DeploymentSnapshot
Represents a point-in-time snapshot of deployment state.
Sha256Hasher 🔒
A wrapper that bridges std::hash::Hasher to sha2::Digest.

Enums§

DeploymentSnapshotError
Error types for deployment snapshot operations.

Functions§

build_snapshot_from_planned 🔒
Build a deployment snapshot from a project graph by hashing all compiled objects.
compute_typed_hash 🔒
Compute a deterministic hash of a typed DatabaseObject. The hash includes:
load_from_database 🔒
Load the current deployment state snapshot from the database for a specific environment.
write_to_database 🔒
Write deployment snapshot to the database using the normalized schema.