Big ol' note about string/uuid as primary key
Some checks are pending
/ test (push) Waiting to run

TODO: Apply the same tag change to other structs with uuid id too
This commit is contained in:
Melody Becker 2025-03-27 16:46:53 +01:00
parent 68859642f3
commit 588849a6c2
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI

View file

@ -19,7 +19,19 @@ import (
// - AP remote links
// - Auth methods and tokens (hashed pw, totp key, passkey id)
type User struct {
ID string `gorm:"primarykey"` // ID is a uuid for this account
// ID is a uuid for this account
//
// NOTE: Performance and storage wise, using a UUID (as string) for the primary key
// is not the best idea and it would be better to use incrementing integers
// Additionally, there is a risk with inconsistency if postgres crashes during a commit
// in which case the new entry might not have a valid Id with which it could be found
// and the username is lost until manual recovery
// However, a UUID is still necessary in some way to provide a (secondary) stable
// identifier for users and other servers, especially when changing the username
// (username != display name) might be a future feature
// Same also applies for other types that use a UUID as primary key
// TODO: Copy the default value and gorm type to those other types as well
ID string `gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
// Username of the user (eg "max" if the full username is @max@example.com)
// Assume unchangable (once set by a user) to be kind to other implementations
// Would be an easy avenue to fuck with them though