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

store

package
v0.1.94 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const LockFileName = ".oddk.lock"

LockFileName is the advisory lock guarding a data directory. Both the daemon and 'snapshot apply' take it, so the two can never operate on the same deployment concurrently.

Variables

This section is empty.

Functions

func OpenAuthOnly

func OpenAuthOnly(dbPath string) (*auth.AuthStore, *sqlx.DB, error)

OpenAuthOnly opens an EXISTING oddk database for the narrow purpose of managing CLI auth tokens from a separate process (the `oddk auth` commands). Unlike NewStore it runs no migrations and no startup writes - those belong to the daemon and would race (and MustExec-panic) against a running daemon. A busy_timeout lets the single token INSERT wait out the daemon's writer lock rather than failing immediately. The caller must Close the returned *sqlx.DB.

Types

type AuthToken

type AuthToken struct {
	ID          int64  `db:"id"`
	TokenPrefix string `db:"token_prefix"`
	TokenHash   string `db:"token_hash"`
	CreatedAt   string `db:"created_at"`
}

type DataDirLock added in v0.1.59

type DataDirLock struct {
	// contains filtered or unexported fields
}

DataDirLock is an exclusive advisory lock on a data directory.

func AcquireDataDirLock added in v0.1.59

func AcquireDataDirLock(dataDir string) (*DataDirLock, error)

AcquireDataDirLock takes an exclusive, non-blocking flock on <dataDir>/.oddk.lock.

This is what actually prevents two writers. A point-in-time port probe cannot: the systemd unit sets Restart=always/RestartSec=5, so a daemon that is killed rather than stopped returns within seconds — possibly mid-apply, at which point both processes drive Docker and write oddk.db, and the daemon's startup sweep force-removes the helper containers the restore is using.

flock is released by the kernel when the process exits or the fd closes, so unlike a lock row in SQLite it cannot be left stale by a crash or a SIGKILL.

func (*DataDirLock) Release added in v0.1.59

func (l *DataDirLock) Release()

Release drops the lock. Safe to call more than once.

type Store

type Store struct {
	Sqlx          *sqlx.DB
	Auth          *auth.AuthStore
	Instances     *instances.InstanceStore
	Backup        *backup.BackupStore
	Cron          *cron.CronStore
	Notifications *notifications.NotificationStore
	Parameters    *parameters.ParameterStore
	Health        *health.HealthStore
	KV            *kvstore.KVStore
	Offsite       *offsite.OffsiteStore
	Snapshot      *snapshot.SnapshotStore
}

func NewStore

func NewStore(dbPath, dataDir string, masterKey []byte) (*Store, error)

NewStore opens (creating if needed) the ODDK database and migrates it.

masterKey is the 32-byte key from {dataDir}/master.key. It is required, not optional: the notification store encrypts its `config` column with it, and a store built without one could only fall back to writing those credentials in cleartext — the failure this parameter exists to make impossible.

func (*Store) AppliedMigrations added in v0.1.59

func (s *Store) AppliedMigrations() ([]string, error)

AppliedMigrations returns the names of migrations applied to this store, in application order. A snapshot records these so a restore can reason about schema compatibility more precisely than a version string allows.

func (*Store) VacuumInto added in v0.1.59

func (s *Store) VacuumInto(path string) error

VacuumInto writes a consistent copy of the store to path using SQLite's VACUUM INTO. It is safe against a live database — SQLite serialises it with other work — so a snapshot can be taken without stopping the daemon. The destination must not already exist.

The copy is also compacted, which matters because a snapshot embeds it.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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