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,6 +3,7 @@ package config
import (
"fmt"
"os"
"strings"
"git.mstar.dev/mstar/goutils/other"
"github.com/BurntSushi/toml"
@ -131,12 +132,12 @@ type ConfigExperimental struct {
// if the other server also requires authorized fetch for the server actor
// Changing this setting is not expected to cause permanent problems
AuthFetchForServerActor bool `toml:"auth_fetch_for_server_actor"`
// Use cuid2 for generation of new IDs that are expected to be used via Activitypub
// They are shorter than the main method used (uuid v4) but should still provide enough
// uniqueness such that collisions are not to be expected.
// Set the provider for ID generation.
// Default is "xid".
// Options are "uuid", "cuid" and "xid"
// Changing this option will only affect new ID generations, not update existing ones
// As of now, even that doesn't work due to implementation details
UseCuid2Ids bool `toml:"use_cuid2_ids"`
IdGenerator string `toml:"id_generator"`
}
type Config struct {
@ -220,6 +221,7 @@ var defaultConfig Config = Config{
Experimental: ConfigExperimental{
UseEd25519Keys: false,
AuthFetchForServerActor: false,
IdGenerator: "xid",
},
}
@ -322,6 +324,7 @@ func ReadAndWriteToGlobal(fileName string) error {
log.Error().Err(err).Bytes("config-data-raw", data).Msg("Failed to unmarshal config file")
return err
}
config.Experimental.IdGenerator = strings.ToLower(config.Experimental.IdGenerator)
GlobalConfig = config
log.Info().Str("config-file", fileName).Msg("Read and applied config file")
return nil