Skip to content

Multi-region schema check for SeaORM (port of Spring starter) - #1

Merged
felipeg48 merged 2 commits into
mainfrom
feature/multiregion-check
Nov 24, 2026
Merged

felipeg48 merged 2 commits into
mainfrom
feature/multiregion-check

Conversation

@felipeg48

Copy link
Copy Markdown
Contributor

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)]

  • Container markers #[crdb(global)] / #[crdb(regional_by_row)]; field marker #[crdb(region)] (the SeaORM analogue of @GlobalTable / @RegionalByRow / @CrdbRegion).
  • Generates impl cockroachdb_core::multiregion::CrdbLocality for Entity.

cockroachdb-core — multiregion module (pure, driver-free)

  • evaluate() is a faithful port of MultiregionCheck.evaluate: both directions (declared-vs-table and table-is-MR-but-entity-unmarked), the same contradiction rules, and identifier keyword-quoting (port of Identifiers).
  • Mode = none | warn | validate, default warn. A contradiction (global-on-RBR, RBR-on-global, both markers, or entities disagreeing on one table) fails even in warn; none is off.
  • Fix-up SQL is built from the existing ddl.rs builders (added one sibling, set_locality_regional_by_row_as, for the AS <col> form).

cockroachdb-seaorm — the driver half

  • describe::<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, never crdb_internal), skips non-CockroachDB (SELECT version()), runs the diff, returns Err on validate/contradiction and logs to stderr on warn. Opt-in, callable after connect().

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 REGION fix-ups, and the region-column type check (crdb_internal_region).

Deliberate deviations (noted)

  • Fix-up SQL uses the shared ddl.rs builders per the reuse requirement: regions are single-quoted (Spring double-quotes; both valid) and ALTER TABLE uses the bare table name (correct for current-schema tables, the norm for SeaORM entities). Human-readable messages keep Spring's conditional keyword-quoting.
  • The region column is taken from the field name (SeaORM's default column name); a #[sea_orm(column_name)] override on the region field is not read (documented ceiling).

Tests

  • Core unit tests cover every evaluate branch, including both contradiction kinds and keyword quoting.
  • A teeth-check asserts contradiction-fails-in-warn; verified red when reverted, then restored.
  • #[derive(CrdbLocality)] + describe exercised offline (no DB).
  • Live ITs are #[ignore]d and skip when the single-node cluster has no regions.

No version bumps (lead handles release).

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.
@felipeg48
felipeg48 merged commit 867b05a into main Nov 24, 2026
3 of 4 checks passed
@felipeg48
felipeg48 deleted the feature/multiregion-check branch November 24, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant