Originally posted as an internal GitHub issue:
It can be useful for DB record IDs to include a prefix that represents their type. This is used by companies such as Stripe/etc, and improves developer experience, as well as providing other tangible benefits:
- https://dev.to/stripe/designing-apis-for-humans-object-ids-3o5a
Designing APIs for humans: Object IDs
Currently Prisma doesn't support generating IDs with prefixes natively in their schema definitions:
- prisma/prisma#3391
Support adding prefix to an
@id
field- Possible workaround from July 10 20222: prisma/prisma#3391 (comment)
- Possible workaround from February 6 2024: prisma/prisma#3391 (comment)
- Possible workaround from May 24 2024: prisma/prisma#3391 (comment)
- https://github.com/jetify-com/typeid-js
Official TypeID-JS Package
TypeScript implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
TypeIDs are a modern, type-safe, globally unique identifier based on the upcoming UUIDv7 standard. They provide a ton of nice properties that make them a great choice as the primary identifiers for your data in a database, APIs, and distributed systems. Read more about TypeIDs in their spec.
- https://github.com/jetify-com/typeid
TypeID A type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
TypeIDs are a modern, type-safe extension of UUIDv7. Inspired by a similar use of prefixes in Stripe's APIs.
TypeIDs are canonically encoded as lowercase strings consisting of three parts:
- A type prefix (at most 63 characters in all lowercase snake_case ASCII [a-z_]).
- An underscore '_' separator
- A 128-bit UUIDv7 encoded as a 26-character string using a modified base32 encoding.
- Possible workaround from September 29 2024: prisma/prisma#3391 (comment)
- prisma/prisma#6719
Support custom user defined ID patterns (on model and global basis)
- Possible workaround from July 8 2022: prisma/prisma#6719 (comment)
- Possible workaround from July 8 2022: prisma/prisma#6719 (comment) + amendment to it prisma/prisma#6719 (comment)
- Postgres workaround from October 21 2022: prisma/prisma#6719 (comment) + variation on it prisma/prisma#6719 (comment)
- Nanoid workaround from Jan 6 2023: prisma/prisma#6719 (comment)
- prisma/prisma#6930
Want to build a Prisma extension for
@default(<fn>)
, could you hint where I should look?@default(dbgenerated("gen_random_uuid()"))
: prisma/prisma#6930 (reply in thread)- Prisma client extension workaround from June 23 2023: prisma/prisma#6930 (reply in thread)
- prisma/prisma#12243
Prisma + PostgreSQL: Prefixing uuid-primary keys with
dbgenerated()
@default(dbgenerated("(concat('usr_', gen_random_uuid()))::TEXT"))
- prisma/prisma#12243 (comment)
It can be even shorter after ignoring type inference.
@default(dbgenerated("'user-' || gen_random_uuid()"))
- prisma/prisma#2396
Prefixed default values for model fields within the schema
- prisma/prisma#3580
Allow prefixing a cuid similar to Stripe and Slack does
- https://gist.github.com/0xdevalias
- https://github.com/0xdevalias
- Web App Tech Stack Things
- Design Systems (0xdevalias' gist)
- Web Extensions / Browser Extensions / Chrome Extensions / etc (0xdevalias' gist)
- Azure serverless functions and related features/patterns/etc (0xdevalias' gist)
- Editor Frameworks and Collaborative Editing/Conflict Resolution Tech (0xdevalias' gist)
- Copy on Write + Event Sourcing for Edit History (0xdevalias' gist)
- My Typesafe/Etc Stack(0xdevalias' gist)