Documentation
¶
Overview ¶
Package store owns MagicHandy's embedded SQLite datastore, schema migrations, transaction helpers, and legacy JSON import bookkeeping.
Index ¶
- Constants
- Variables
- func ArchiveLegacyJSON(path string) (string, error)
- func RecordLegacyImportTx(ctx context.Context, tx *sql.Tx, status LegacyImportStatus) error
- type DB
- func (db *DB) Close() error
- func (db *DB) DataDir() string
- func (db *DB) LegacyImportStatus(ctx context.Context, domain string) (LegacyImportStatus, bool, error)
- func (db *DB) Path() string
- func (db *DB) RecordLegacyImport(ctx context.Context, status LegacyImportStatus) error
- func (db *DB) Recovery() RecoveryStatus
- func (db *DB) SQL() *sql.DB
- func (db *DB) WithTx(ctx context.Context, fn func(*sql.Tx) error) error
- type LegacyImportStatus
- type RecoveryStatus
Constants ¶
const ( ChatCursorLimit = 4096 ChatCursorRetention = 24 * time.Hour )
ChatCursorLimit caps stored read markers. ChatCursorRetention governs normal reads and advancement; migration preserves legacy markers within the cap.
const ( // DatabaseFileName is the single app datastore under the resolved data dir. DatabaseFileName = "magichandy.db" // CurrentSchemaVersion is mirrored into PRAGMA user_version. CurrentSchemaVersion = 26 // LegacyStatusAbsent records that a legacy JSON file was not present. LegacyStatusAbsent = "absent" // LegacyStatusImported records that a legacy JSON file imported successfully. LegacyStatusImported = "imported" // LegacyStatusRecovered records that a legacy JSON file was unreadable or corrupt. LegacyStatusRecovered = "recovered" // LegacyStatusSkipped records that import was intentionally skipped. LegacyStatusSkipped = "skipped" )
const AuditRowLimit = 10000
AuditRowLimit bounds durable history independently of the number of accounts or control requests. Domain writes share this cap through an insert trigger.
Variables ¶
var ErrCorruptDatastore = errors.New("sqlite datastore is corrupt")
ErrCorruptDatastore classifies physical SQLite corruption that can be quarantined without interpreting or deleting the original bytes.
var ErrInvalidSchema = errors.New("sqlite schema is invalid")
ErrInvalidSchema reports a logically invalid schema that must not be replaced automatically because its rows may still be recoverable.
var ErrNewerSchema = errors.New("sqlite schema is newer than this binary")
ErrNewerSchema reports a DB created by a newer MagicHandy binary.
Functions ¶
func ArchiveLegacyJSON ¶
ArchiveLegacyJSON renames a successfully imported JSON file without deleting its contents. If the archive name already exists, the original is left alone.
func RecordLegacyImportTx ¶
RecordLegacyImportTx records a one-time import status inside an existing tx.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps the process-owned SQLite connection and schema helpers.
func (*DB) LegacyImportStatus ¶
func (db *DB) LegacyImportStatus(ctx context.Context, domain string) (LegacyImportStatus, bool, error)
LegacyImportStatus returns the recorded import state for a legacy JSON file.
func (*DB) RecordLegacyImport ¶
func (db *DB) RecordLegacyImport(ctx context.Context, status LegacyImportStatus) error
RecordLegacyImport records a one-time import status.
func (*DB) Recovery ¶
func (db *DB) Recovery() RecoveryStatus
Recovery reports whether Open quarantined a physically corrupt datastore and created a new one for this process.
func (*DB) SQL ¶
SQL exposes the underlying handle for package-owned reads. Production writes must use WithTx so every logical domain shares the serialized writer.
type LegacyImportStatus ¶
type LegacyImportStatus struct {
Domain string
SourcePath string
ArchivedPath string
Status string
Message string
ImportedAt string
}
LegacyImportStatus records one legacy JSON import attempt.
type RecoveryStatus ¶
RecoveryStatus describes a non-destructive physical-corruption recovery.