From 588849a6c23939d3c41ac99e5b538dffd10c2deb Mon Sep 17 00:00:00 2001 From: mstar Date: Thu, 27 Mar 2025 16:46:53 +0100 Subject: [PATCH] Big ol' note about string/uuid as primary key TODO: Apply the same tag change to other structs with uuid id too --- storage-new/models/User.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/storage-new/models/User.go b/storage-new/models/User.go index 37f546a..f229146 100644 --- a/storage-new/models/User.go +++ b/storage-new/models/User.go @@ -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