Skip to content

Allow prefixing a cuid similar to Stripe and Slack does #3580

@SharadKumar

Description

@SharadKumar

Problem

I have a requirement on the project to be able to prefix all keys (all my Id fields are cuid() generated).

Suggested solution

Ideally:

model Customer {
  id            String         @default(cuid(prefix: "cust_")) @id
  email         String         @unique
  name          String?
}

model Product {
  id                String   @default(cuid(prefix: "sku_")) @id
  title             String?
}

Alternatives

Alternately, since cuid() is not executed at DB level, I could handle it in the app too. However, it will be good to see it enhanced in prisma itself.

Additional context

  • It would be good if there was a way to extend good for developers. Above is one use-case.
  • Lets say you have a Pages or Account table and you want @id to be a perma slug. Such table will ever have few hundred records and you'd want something Url friendly but not as long as cuid.
    https://github.com/ericelliott/cuid#short-urls

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions