Remove id autogeneration from db models

Remove automatic uuid v4 ID generation from the models and replace it
with `shared.NewId()`, which generates an Id depending on the config
setting
This commit is contained in:
Melody Becker 2025-05-06 14:34:32 +02:00
parent 412a8be600
commit e182949a8d
Signed by: mstar
SSH key fingerprint: SHA256:vkXfS9FG2pVNVfvDrzd1VW9n8VJzqqdKQGljxxX8uK8
9 changed files with 24 additions and 12 deletions

View file

@ -3,15 +3,21 @@ package shared
import (
"github.com/google/uuid"
"github.com/nrednav/cuid2"
"github.com/rs/xid"
"git.mstar.dev/mstar/linstrom/config"
)
// Generate a new string ID
func NewId() string {
if config.GlobalConfig.Experimental.UseCuid2Ids {
return cuid2.Generate()
} else {
switch config.GlobalConfig.Experimental.IdGenerator {
case "uuid":
return uuid.NewString()
case "cuid":
return cuid2.Generate()
case "xid":
return xid.New().String()
default:
return xid.New().String()
}
}