Help us shape the future of Go! Take the 2026 Go Developer Survey

singleuser

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package singleuser turns a database that grew several users into one with a single owner. Run is called once at startup, after every store has created its tables: it keeps the oldest registered user, copies the database aside, and deletes every other user with all their data in one transaction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteMarker

func WriteMarker(ctx context.Context, tx *sql.Tx, keptUsername string, removedUsers int) error

WriteMarker records that the cleanup is settled for this database. Run calls it after deleting; the first passkey registration on an instance calls it too, because such an instance never held several users from before the upgrade, and a user invited later must survive a restart.

Types

type Result

type Result struct {
	// Ran is true when a cleanup was recorded this start.
	Ran bool
	// Kept is the username of the user the instance kept.
	Kept string
	// Removed is how many other users were deleted.
	Removed int
	// BackupPath is the copy taken before deleting, empty when none was needed.
	BackupPath string
}

Result says what Run did.

func Run

func Run(ctx context.Context, db *sql.DB, dbPath string, log *slog.Logger) (Result, error)

Run keeps the oldest user holding a passkey and deletes the rest. It does nothing on an empty database or after the marker was written. If the backup or the transaction fails nothing is deleted and the error is returned; the next start tries again.

Jump to

Keyboard shortcuts

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