Documentation
¶
Index ¶
- func AdaptToCurrentVersion() error
- func CreateInBatchesSafe(tx *gorm.DB, slice any) error
- func GetDB() *gorm.DB
- func GetDb(exclude string) ([]byte, error)
- func ImportDB(file multipart.File) error
- func InitDB(dbPath string) error
- func IsNotFound(err error) bool
- func IsSQLiteDB(file io.Reader) (bool, error)
- func OpenDB(dbPath string) error
- func ParseBackupExcludes(exclude string) []string
- func PrepareDbBackup(exclude string) (backupPath string, cleanup func(), err error)
- func RegisterResetHook(name string, fn func())
- func ResetCaches(ctx context.Context) error
- func SafeSQLiteBatchSize(db *gorm.DB, modelValue any) int
- func SaveInBatchesSafe(tx *gorm.DB, slice any) error
- func SendSighup() error
- func SetSendSighupHook(hook func() error)
- func SetSighupTimeoutForTest(d time.Duration)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdaptToCurrentVersion ¶
func AdaptToCurrentVersion() error
AdaptToCurrentVersion performs idempotent post-migration adjustments that ensure a database imported from an older S-UI version is fully usable on the current build:
- Plaintext admin/user passwords are rehashed with bcrypt.
- Any remaining default user state is normalized (random password if a legacy backup contained the historical "admin" plaintext default).
- Indexes added by this fork are (re-)created if missing.
- The `settings.version` row is updated to the current version so that `cmd/migration` skips running again on the next startup.
All steps are idempotent: running the function multiple times is safe.
AdaptToCurrentVersion expects the package-level `db` to be open. It must be called after `InitDB` (so AutoMigrate already ran), but before the panel starts serving traffic.
func CreateInBatchesSafe ¶
CreateInBatchesSafe inserts slice into the given table while keeping each generated INSERT below SQLite's variable budget. Pass a pointer to a slice (`*[]model.X`) or a non-nil slice value. Empty slices are a no-op.
func IsNotFound ¶
func ParseBackupExcludes ¶
func PrepareDbBackup ¶ added in v1.5.10
func RegisterResetHook ¶
func RegisterResetHook(name string, fn func())
func ResetCaches ¶
func SafeSQLiteBatchSize ¶
SafeSQLiteBatchSize returns the largest batch size that keeps a multi-row INSERT within SQLite's variable budget for the given model. Pass either a pointer to a model value (`&model.Client{}`) or a slice of models.
func SaveInBatchesSafe ¶
SaveInBatchesSafe runs gorm.Save in chunks small enough for SQLite. Save is upsert-style (INSERT OR REPLACE), so the same variable budget applies as for CreateInBatches. Use for slices of pointers or values.
func SendSighup ¶
func SendSighup() error
func SetSendSighupHook ¶
func SetSendSighupHook(hook func() error)
func SetSighupTimeoutForTest ¶ added in v1.5.5
SetSighupTimeoutForTest overrides the resolved timeout. Test helpers call this in t.Cleanup-bracketed pairs. Production must not call it.
Types ¶
This section is empty.