Expand description
db_ops_sync — Align db_ops/{backend}/migrations with the proto AST across all backends.
Inspired by the legacy_sql legacycore/db migration pattern. This module:
-
Discovers the
db_opsroot at sibling level relative to the UDB crate root (nearestCargo.toml). Override withUDB_DB_OPS_ROOTenv var. -
Creates
db_ops/<backend>/migrationsanddb_ops/<backend>/bootstrapfor each backend selected. Also creates the configured seeders directory (UDB_SEEDERS_PATH/UDB_SEEDER_PATH, default:db_ops/seeds) with a.gitkeep. -
If
<backend>/migrationsis empty → writes baseline artifacts derived from the current proto AST. These become the canonical audit trail. -
If
<backend>/migrationsis non-empty → runs a double-checksum check:- Computes the current proto manifest checksum (SHA-256 over sorted AST).
- Reads each artifact header for its
-- UDB:proto_manifest_checksum=<sha>(or_udb_meta.proto_manifest_checksumfor JSON,# UDB:proto_manifest_checksum:for YAML,// UDB:proto_manifest_checksum=for Cypher). - Files whose embedded checksum does not match the current proto checksum
are marked
Stale. Proto always wins. - By default, stale or headerless artifacts are refreshed in place so the checked-in baseline converges on the current proto state without manual steps.
- When
force_bootstrapis enabled, refreshed artifacts are written to<backend>/bootstrapfor operator review instead of overwritingmigrations/.
-
Returns a
MigrationSyncReportper backend, aggregated intoMultiBackendSyncReportbysync_all_backends.
§Directory layout produced
<db_ops_root>/
├── postgres/
│ ├── migrations/ ← baseline SQL (proto-derived, written once)
│ └── bootstrap/ ← updated SQL when proto changes
├── qdrant/
│ ├── migrations/ ← JSON collection definitions
│ └── bootstrap/
├── minio/
│ ├── migrations/ ← JSON bucket policies
│ └── bootstrap/
├── redis/
│ ├── migrations/ ← YAML key-schema docs
│ └── bootstrap/
├── mongodb/
│ ├── migrations/ ← JSON collection validators
│ └── bootstrap/
├── neo4j/
│ ├── migrations/ ← Cypher constraint scripts
│ └── bootstrap/
├── clickhouse/
│ ├── migrations/ ← ClickHouse DDL SQL
│ └── bootstrap/
└── seeds/
└── .gitkeep
When `UDB_SEEDERS_PATH` is set, the seeders directory is created at that
absolute path or, for relative values, relative to the repository root.Structs§
- DbOps
Sync Config - Configuration for
sync_db_opsandsync_all_backends. - Migration
File Record - Record for one SQL file processed during sync.
- Migration
Sync Report - Full report returned by
sync_db_ops. - Multi
Backend Sync Report - Aggregate report from
sync_all_backends.
Enums§
- Backend
Sync Target - Which backend(s) to sync during a
sync_db_ops/sync_all_backendsrun. - File
Sync Status - Per-file sync status after a
sync_db_opsrun. - Sync
Error
Functions§
- discover_
db_ ops_ root - Discover the
db_opsroot directory by walking up from the current working directory to the nearestCargo.tomlfile. - sync_
all_ backends - Synchronise all configured backends (or a specific one) with the current proto AST.
- sync_
db_ ops - Synchronise
db_ops/postgres/{migrations,bootstrap}with the current proto AST.