Repository navigation
Multi-region schema check for SeaORM (port of Spring starter) - #1
Merged
Merged
Conversation
Add a declarative locality marker and a startup schema check for the SeaORM path, mirroring the Spring Boot starter's multi-region check. - cockroachdb-macros: new #[derive(CrdbLocality)] with #[crdb(global)] / #[crdb(regional_by_row)] container markers and #[crdb(region)] field marker, generating impl CrdbLocality for Entity. - cockroachdb-core: new multiregion module with the pure diff logic (evaluate), report, identifier keyword-quoting, mode (none|warn|validate, default warn), and fails_startup. Contradictions fail even in warn. Reuses the ddl.rs fix-up builders (adds set_locality_regional_by_row_as). - cockroachdb-seaorm: describe/describe_plain turn entities into descriptors via the SeaORM metamodel; verify_multiregion loads the live schema (SHOW + information_schema, no crdb_internal) and runs the diff, returning Err on validate/contradiction and logging on warn. - Tests: full branch coverage of the diff (incl contradictions + keyword quoting) and a teeth-check for contradiction-fails-in-warn; derive + describe offline test; ignored live ITs that skip when the cluster has no regions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the Spring Boot starter's multi-region startup check to the Rust library, on the SeaORM path only (SQLx core has no entity model). Adds a declarative locality marker first (none existed), then the check.
What's new
cockroachdb-macros—#[derive(CrdbLocality)]#[crdb(global)]/#[crdb(regional_by_row)]; field marker#[crdb(region)](the SeaORM analogue of@GlobalTable/@RegionalByRow/@CrdbRegion).impl cockroachdb_core::multiregion::CrdbLocality for Entity.cockroachdb-core—multiregionmodule (pure, driver-free)evaluate()is a faithful port ofMultiregionCheck.evaluate: both directions (declared-vs-table and table-is-MR-but-entity-unmarked), the same contradiction rules, and identifier keyword-quoting (port ofIdentifiers).Mode=none | warn | validate, defaultwarn. A contradiction (global-on-RBR, RBR-on-global, both markers, or entities disagreeing on one table) fails even inwarn;noneis off.ddl.rsbuilders (added one sibling,set_locality_regional_by_row_as, for theAS <col>form).cockroachdb-seaorm— the driver halfdescribe::<E>()/describe_plain::<E>()turn entities into descriptors via the SeaORM metamodel (EntityTrait/EntityName).verify_multiregion(db, mode, tables)loads the live schema (SHOW+information_schema, nevercrdb_internal), skips non-CockroachDB (SELECT version()), runs the diff, returnsErron validate/contradiction and logs to stderr on warn. Opt-in, callable afterconnect().Semantics parity
Mirrors the Spring reference exactly: modes, contradiction-fails-in-warn, both-directions diff, the not-multi-region one-shot report with
SET PRIMARY REGION/ADD REGIONfix-ups, and the region-column type check (crdb_internal_region).Deliberate deviations (noted)
ddl.rsbuilders per the reuse requirement: regions are single-quoted (Spring double-quotes; both valid) andALTER TABLEuses the bare table name (correct for current-schema tables, the norm for SeaORM entities). Human-readable messages keep Spring's conditional keyword-quoting.#[sea_orm(column_name)]override on the region field is not read (documented ceiling).Tests
evaluatebranch, including both contradiction kinds and keyword quoting.#[derive(CrdbLocality)]+describeexercised offline (no DB).#[ignore]d and skip when the single-node cluster has no regions.No version bumps (lead handles release).