database

package
v1.5.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

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:

  1. Plaintext admin/user passwords are rehashed with bcrypt.
  2. Any remaining default user state is normalized (random password if a legacy backup contained the historical "admin" plaintext default).
  3. Indexes added by this fork are (re-)created if missing.
  4. 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

func CreateInBatchesSafe(tx *gorm.DB, slice any) error

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 GetDB

func GetDB() *gorm.DB

func GetDb

func GetDb(exclude string) ([]byte, error)

func ImportDB

func ImportDB(file multipart.File) error

func InitDB

func InitDB(dbPath string) error

func IsNotFound

func IsNotFound(err error) bool

func IsSQLiteDB

func IsSQLiteDB(file io.Reader) (bool, error)

func OpenDB

func OpenDB(dbPath string) error

func ParseBackupExcludes

func ParseBackupExcludes(exclude string) []string

func PrepareDbBackup added in v1.5.10

func PrepareDbBackup(exclude string) (backupPath string, cleanup func(), err error)

func RegisterResetHook

func RegisterResetHook(name string, fn func())

func ResetCaches

func ResetCaches(ctx context.Context) error

func SafeSQLiteBatchSize

func SafeSQLiteBatchSize(db *gorm.DB, modelValue any) int

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

func SaveInBatchesSafe(tx *gorm.DB, slice any) error

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

func SetSighupTimeoutForTest(d time.Duration)

SetSighupTimeoutForTest overrides the resolved timeout. Test helpers call this in t.Cleanup-bracketed pairs. Production must not call it.

Types

This section is empty.

Directories

Path Synopsis
Package importxui imports a 3x-ui SQLite database into the active s-ui database.
Package importxui imports a 3x-ui SQLite database into the active s-ui database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL