doc/md: docs for new globalid feature (#4344)

This commit is contained in:
Jannik Clausen
2025-02-25 12:42:25 +01:00
committed by GitHub
parent fed373ab2f
commit 7f5f143bd2
3 changed files with 193 additions and 42 deletions

View File

@@ -413,3 +413,24 @@ client.User.
// INSERT INTO "users" (...) VALUES ... ON CONFLICT WHERE ... DO UPDATE SET ... WHERE ...
```
### Globally Unique ID
By default, SQL primary-keys start from 1 for each table; which means that multiple entities of different types
can share the same ID. Unlike AWS Neptune, where node IDs are UUIDs.
This does not work well if you work with [GraphQL](https://graphql.org/learn/schema/#scalar-types), which requires
the object ID to be unique.
To enable the Universal-IDs support for your project, simply use the `--feature sql/globalid` flag.
:::warning Note
If you have used the `migrate.WithGlobalUniqueID(true)` migration option in the past, please read
[this guide](globalid-migrate) before you switch your project to use the new globalid feature.
:::
**How does it work?** `ent` migration allocates a 1<<32 range for the IDs of each entity (table),
and store this information alongside your generated code (`internal/globalid.go`). For example, type `A` will have the
range of `[1,4294967296)` for its IDs, and type `B` will have the range of `[4294967296,8589934592)`, etc.
Note that if this option is enabled, the maximum number of possible tables is **65535**.