Repository navigation
Multi-region schema check (Drizzle + Prisma) - #1
Merged
Merged
Conversation
Port the Spring starter's startup locality check to TypeScript. Adds a
declarative locality marker per adapter and a shared check core.
- core/multiregion.ts: live-schema introspection (SHOW DATABASES /
SHOW REGIONS FROM CLUSTER / SHOW TABLES / information_schema.columns,
no crdb_internal), diff, report, and fix-up SQL reusing ddl.ts.
Modes none|warn|validate (default warn); a contradiction fails even in
warn; none and non-CockroachDB skip. Reads only.
- drizzle: crdbLocality(table, { locality, regionColumn? }) marker +
verifyMultiregionSchema(pool, schema, { mode }).
- prisma: PrismaLocalityConfig sidecar + verifyMultiregionSchema(client,
config, { mode }), enumerating models via the runtime data model.
- Unit tests for every diff branch, contradictions, and quoting; a gated
live integration test; CI runs it with CRDB_URL.
Bump core, drizzle, prisma, pg, ai, testing, continuum to 0.2.0 and inter-package refs to ^0.2.0 so the single-version Pages feed stays resolvable (caret 0.1.0 cannot match 0.2.0). Bump examples/ideas-board pins (pg/ai/continuum/testing) to ^0.2.0 in lockstep so the workspace resolves. cdc unchanged (no cross-package deps).
felipeg48
force-pushed
the
feature/multiregion-check
branch
from
November 24, 2026 20:26
970bd90 to
2b2dbec
Compare
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.
Faithful port of the Spring starter's startup multi-region locality check (
com.cockroachlabs.data.multiregion) to the TypeScript library, for the Drizzle and Prisma adapters. Rawpghas no model metadata, so it is out of scope.What's new
crdbLocality(table, { locality: 'GLOBAL' | 'REGIONAL_BY_ROW', regionColumn? })— a sidecarWeakMapkeyed by the drizzle table object; schema enumerated viadrizzle-ormis/Table/getTableName.PrismaLocalityConfigsidecar ({ Model: { locality, regionColumn? } }); models enumerated via the client's_runtimeDataModel(no doc-comment parsing).@cockroachdb/core(multiregion.ts): live-schema introspection, the diff, the report, and fix-up SQL (reusesddl.tssetPrimaryRegion/addRegion/setLocality*/ident).await verifyMultiregionSchema(poolOrClient, schemaOrConfig, { mode }).Faithful semantics (mirrors Spring)
none | warn | validate, defaultwarn. A contradiction (global-on-RBR, RBR-on-global, both markers, or entities disagreeing on one table) fails startup even inwarn;noneis off.SHOW+information_schema(nevercrdb_internal). Skips quietly when not CockroachDB. Both directions: declared-vs-table, and table-is-MR-but-entity-unmarked. Not-multi-region-but-markers is reported once withALTER DATABASE SET PRIMARY REGION / ADD REGION.Tests
core/multiregion.test.ts): every diff branch, all contradiction paths, identifier quoting,regionalByRowColumnparsing, report formatting, and a teeth-check that contradictions fail inwarn.pg/multiregion.integration.test.ts): gated onCRDB_URL; CI runs it in theintegrationjob. Tolerates fresh-schema timing by pollingSHOW TABLES.Notes
ddl.ts, which always-quotes identifiers ("table") and uses'region'literals — valid, keyword-safe CockroachDB, not Spring's conditional quoting.CrdbPool.connect(left opt-in via the verify function).