sqlstore

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var ErrUnsupportedDialect = errors.New("sqlstore: unsupported dialect")

ErrUnsupportedDialect is returned for a dialect without embedded migrations.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB, d sqlcommon.Dialect) ([]int, error)

Migrate applies every pending audit migration and returns the versions applied.

func MigrationSet

func MigrationSet(d sqlcommon.Dialect) (sqlcommon.MigrationSet, error)

MigrationSet returns the audit migrations for the dialect.

func Rollback

func Rollback(ctx context.Context, db *sql.DB, d sqlcommon.Dialect, target int) ([]int, error)

Rollback reverts audit migrations newer than target (0 reverts all).

func Version

func Version(ctx context.Context, db *sql.DB, d sqlcommon.Dialect) (int, error)

Version returns the highest applied audit migration (0 when none).

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

func Open(ctx context.Context, db *sql.DB, d sqlcommon.Dialect, o Options) (*Store, error)

Open wraps an opened pool for the dialect and, unless o.SkipMigrate, applies pending migrations.

func (*Store) Append

func (s *Store) Append(ctx context.Context, rec audit.Record) (audit.Record, error)

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.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB exposes the pool for health checks and tests.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id int64) (audit.Record, error)

Get implements audit.Store.

func (*Store) List

List implements audit.Store, newest first.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, before time.Time) (int, error)

Prune implements audit.Store. Retention is the only way a record leaves the trail, so this is one statement with no filter but age.

Jump to

Keyboard shortcuts

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