Skip to content

Cannot use crdb_region in CockroachDB #11127

Description

@ppoddar-affordably

Bug description

I'm using Prisma to query a dedicated CockroachDB multi-region instance. For REGIONAL BY ROW tables, there is a hidden internal crdb_region column created by CockroachDB. This column has an internal enum type crdb_internal_region that is composed of the different cloud regions where the DB Nodes are hosted. In the hosted offering, these are set by CockroachDB to be values like gcp-us-east1 (with dashes) and cannot be changed afaik.

If I try to explicitly insert or read values to crdb_region, then I have to include crdb_region in my Prisma schema for that model for it to show up in the client. However, because crdb_region is represented as an enum in Cockroach, I can't represent crdb_region as a String type. I tried defining an enum in Prisma like:

enum crdb_internal_region {
  gcp-us-east1
  gcp-europe-west1
  gcp-asia-south1
}

but there is an error since these enum values have dashes in them which are not currently allowed. As of now, I have no way to proceed.

References:
[0] https://www.cockroachlabs.com/blog/under-the-hood-multi-region/
[1] https://www.cockroachlabs.com/docs/stable/set-locality.html
[2] #273

Prisma information

Example schema:

model self_stated {
  id                             String
  user_id                        String
  created_at                     DateTime             @default(now()) @db.Timestamptz(6)
  updated_at                     DateTime             @default(now()) @db.Timestamptz(6)
  users                          users                @relation(fields: [crdb_region, user_id], references: [crdb_region, id], onDelete: Cascade, map: "self_stated_users_id_fk")
  crdb_region                    String  // Doesn't work!
  user_country_code              String

  @@id([crdb_region, id])
  @@index([user_id], map: "self_stated_user_id_index")
}

Error is:
Attempted to serialize scalar 'gcp-us-east1' with incompatible type 'String' for field crdb_region

Environment & setup

  • OS: Debian
  • Database: CockroachDB
  • Node.js version: v16.13.1

Prisma Version

prisma                  : 3.8.0
@prisma/client          : Not found
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../home/node/.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../home/node/.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../home/node/.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../home/node/.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                  : 0.452.0

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions