db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB is the global GORM database handle.

Functions

func Close

func Close()

Close releases the underlying database connection.

func EncryptionSalt

func EncryptionSalt() ([]byte, error)

EncryptionSalt returns this deployment's scrypt salt, generating it the first time the database is used.

The salt is not a secret — it lives in the same file as the data it protects. Its job is to make the derived key specific to this deployment, so that a precomputed table built against a shared salt is worthless here.

It must never change: the key is derived from (passphrase, salt), so a new salt is a new key and every stored credential becomes unreadable. That is also why it is stored with the data rather than in configuration — a database restored from backup brings its own salt with it.

func Open

func Open() error

Open opens the SQLite database, creating parent directories as needed, and runs AutoMigrate for all persistent models.

func VerifyEncryptionCanary

func VerifyEncryptionCanary() error

VerifyEncryptionCanary checks that the key derived at startup is the one this database was encrypted with, and records the canary on first use.

Without it a changed passphrase starts cleanly and fails later, once per migration, as a scatter of unrelated-looking decrypt errors. Here it is one message at startup, before anything runs.

Types

type Meta

type Meta struct {
	Key   string `gorm:"primaryKey;column:meta_key"`
	Value string `gorm:"column:meta_value"`
}

Meta is an internal key/value table for deployment state that has to outlive a restart but is never exposed through the API: the encryption salt and the key canary. It is deliberately not a REST model — nothing here is ever serialised into a response.

func (Meta) TableName

func (Meta) TableName() string

TableName pins the table name. The columns are meta_key/meta_value rather than key/value so no driver has to decide whether "key" needs quoting.

Jump to

Keyboard shortcuts

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