Documentation
¶
Overview ¶
Package sqlstore implements persistent audit storage for SQLite, PostgreSQL and MySQL.
Open wraps a database pool supplied by the caller and applies the audit migrations unless SkipMigrate is set. The caller owns the pool and must close it. Audit migration versions are tracked separately from other server tables.
Records use database-generated identifiers for pagination. Lists return the newest records first, and appending an existing nonempty event ID returns the stored record instead of creating a duplicate.
See the audit design decision: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0038-persisted-audit-trail.md
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, db *sql.DB, d sqlcommon.Dialect) ([]int, error)
- func MigrationSet(d sqlcommon.Dialect) (sqlcommon.MigrationSet, error)
- func Rollback(ctx context.Context, db *sql.DB, d sqlcommon.Dialect, target int) ([]int, error)
- func Version(ctx context.Context, db *sql.DB, d sqlcommon.Dialect) (int, error)
- type Options
- type Store
- func (s *Store) Append(ctx context.Context, rec audit.Record) (audit.Record, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) Get(ctx context.Context, id int64) (audit.Record, error)
- func (s *Store) List(ctx context.Context, q audit.Query, p audit.Page) (audit.Result[audit.Record], error)
- func (s *Store) Prune(ctx context.Context, before time.Time) (int, error)
Constants ¶
const MigrationsTable = "audit_schema_migrations"
MigrationsTable records the applied versions of the audit schema, separate from the storage, DDM, DEP, ACME, and admin tables so the version sequences never mix.
Variables ¶
var ErrUnsupportedDialect = errors.New("sqlstore: unsupported dialect")
ErrUnsupportedDialect is returned for a dialect without embedded migrations.
Functions ¶
func MigrationSet ¶
func MigrationSet(d sqlcommon.Dialect) (sqlcommon.MigrationSet, error)
MigrationSet returns the audit migrations for the dialect.
Types ¶
type Options ¶
type Options struct {
// SkipMigrate leaves the schema alone; the caller has run Migrate.
SkipMigrate bool
}
Options tune Open.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements audit.Store over a *sql.DB it does not own: closing the pool is the caller's job.
func Open ¶
Open wraps an opened pool for the dialect and, unless o.SkipMigrate, applies pending migrations.
func (*Store) Append ¶
Append implements audit.Store.
The id is read back rather than assumed, because the three dialects assign it differently and the value is the pagination cursor.