sqlstore

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sqlstore persists ddm.Store records in SQLite, PostgreSQL and MySQL.

Design

The store owns ddm_schema_migrations while reusing server/sqlstore/sqlcommon dialects and migration handling. It persists declarations, versions, sets, assignments, snapshots, status and pending changes. Exact byte columns preserve hashed content, timestamps use UTC and lists use keyset pagination. Mutations and their notification rows share a transaction.

No foreign key points to MDM enrollment tables, allowing a separate engine database. Lifecycle cleanup is coordinated by server/ddmsync. storage/ddm/ddmtest supplies the contract suite.

References

Index

Constants

View Source
const MigrationsTable = "ddm_schema_migrations"

MigrationsTable records the applied versions of the DDM schema, separate from the storage schema's table so the two version sequences never mix.

Variables

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

ErrUnsupportedDialect is returned for a dialect without embedded migrations (anything but sqlite, postgres, and mysql).

Functions

func Migrate

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

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

func MigrationSet

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

MigrationSet returns the DDM migrations for the dialect.

func Rollback

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

Rollback reverts DDM 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 DDM migration (0 when none).

Types

type Options

type Options struct {
	// Keyring encrypts retained declaration and snapshot bodies.
	Keyring *crypt.Keyring
	// 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 ddm.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) AddSetDeclaration

func (s *Store) AddSetDeclaration(ctx context.Context, set, identifier string, at time.Time) (changed bool, err error)

AddSetDeclaration implements ddm.SetStore.

func (*Store) AffectedEnrollments

func (s *Store) AffectedEnrollments(ctx context.Context, identifiers, sets []string) ([]mdm.EnrollmentID, error)

AffectedEnrollments implements ddm.AssignmentStore.

func (*Store) AssignDeclaration

func (s *Store) AssignDeclaration(ctx context.Context, id mdm.EnrollmentID, identifier string, at time.Time) (changed bool, err error)

AssignDeclaration implements ddm.AssignmentStore.

func (*Store) AssignSet

func (s *Store) AssignSet(ctx context.Context, id mdm.EnrollmentID, set string, at time.Time) (changed bool, err error)

AssignSet implements ddm.AssignmentStore.

func (*Store) ChangeStats

func (s *Store) ChangeStats(ctx context.Context, now time.Time) (pending, failed int64, err error)

ChangeStats implements ddm.ChangeStore.

func (*Store) ClearEnrollment

func (s *Store) ClearEnrollment(ctx context.Context, id mdm.EnrollmentID) error

ClearEnrollment implements ddm.Tx.

func (*Store) CompleteChanges

func (s *Store) CompleteChanges(ctx context.Context, seqs []int64) error

CompleteChanges implements ddm.ChangeStore.

func (*Store) DB

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

DB exposes the pool for health checks and tests.

func (*Store) DeclarationSets

func (s *Store) DeclarationSets(ctx context.Context, identifier string) ([]string, error)

DeclarationSets implements ddm.SetStore.

func (*Store) DeclarationStatus

func (s *Store) DeclarationStatus(ctx context.Context, id mdm.EnrollmentID) ([]ddm.DeclarationStatus, error)

DeclarationStatus implements ddm.StatusStore.

func (*Store) DeclarationStatusByIdentifier

func (s *Store) DeclarationStatusByIdentifier(ctx context.Context, identifier string, p paging.Page) (paging.Result[ddm.EnrollmentDeclarationStatus], error)

DeclarationStatusByIdentifier implements ddm.StatusStore.

func (*Store) DeleteDeclaration

func (s *Store) DeleteDeclaration(ctx context.Context, identifier string) error

DeleteDeclaration implements ddm.DeclarationStore.

func (*Store) DeleteSet

func (s *Store) DeleteSet(ctx context.Context, name string) error

DeleteSet implements ddm.SetStore.

func (*Store) EnrollmentDeclarations

func (s *Store) EnrollmentDeclarations(ctx context.Context, id mdm.EnrollmentID) ([]string, error)

EnrollmentDeclarations implements ddm.AssignmentStore.

func (*Store) EnrollmentIdentity

func (s *Store) EnrollmentIdentity(ctx context.Context, rawID string) (mdm.EnrollmentID, error)

EnrollmentIdentity implements ddm.AssignmentStore.

func (*Store) EnrollmentSets

func (s *Store) EnrollmentSets(ctx context.Context, id mdm.EnrollmentID) ([]string, error)

EnrollmentSets implements ddm.AssignmentStore.

func (*Store) FailChanges

func (s *Store) FailChanges(ctx context.Context, seqs []int64, msg string, nextAttempt time.Time) error

FailChanges implements ddm.ChangeStore.

func (*Store) GetDeclaration

func (s *Store) GetDeclaration(ctx context.Context, identifier string) (*ddm.Declaration, error)

GetDeclaration implements ddm.DeclarationStore.

func (*Store) GetDeclarationVersion

func (s *Store) GetDeclarationVersion(ctx context.Context, identifier, serverToken string) (*ddm.DeclarationVersion, error)

GetDeclarationVersion implements ddm.DeclarationStore.

func (*Store) GetSet

func (s *Store) GetSet(ctx context.Context, name string) (*ddm.Set, error)

GetSet implements ddm.SetStore.

func (*Store) ListDeclarations

func (s *Store) ListDeclarations(ctx context.Context, q ddm.DeclarationQuery, p paging.Page) (paging.Result[ddm.Declaration], error)

ListDeclarations implements ddm.DeclarationStore.

func (*Store) ListSets

func (s *Store) ListSets(ctx context.Context, p paging.Page) (paging.Result[ddm.Set], error)

ListSets implements ddm.SetStore.

func (*Store) PendingChanges

func (s *Store) PendingChanges(ctx context.Context, now time.Time, limit int) ([]ddm.Change, error)

PendingChanges implements ddm.ChangeStore.

func (*Store) PruneVersions

func (s *Store) PruneVersions(ctx context.Context) (int64, error)

PruneVersions implements ddm.DeclarationStore.

func (*Store) PutDeclaration

func (s *Store) PutDeclaration(ctx context.Context, d *ddm.Declaration) (changed bool, err error)

PutDeclaration implements ddm.DeclarationStore.

func (*Store) PutSet

func (s *Store) PutSet(ctx context.Context, name string, at time.Time) (created bool, err error)

PutSet implements ddm.SetStore.

func (*Store) PutSnapshot

func (s *Store) PutSnapshot(ctx context.Context, snap *ddm.Snapshot) error

PutSnapshot implements ddm.SnapshotStore.

func (*Store) PutStatus

func (s *Store) PutStatus(ctx context.Context, id mdm.EnrollmentID, u ddm.StatusUpdate) (out ddm.StatusOutcome, err error)

PutStatus implements ddm.StatusStore.

func (*Store) RecordChanges

func (s *Store) RecordChanges(ctx context.Context, ids []mdm.EnrollmentID, reason string, at time.Time) error

RecordChanges implements ddm.ChangeStore.

func (*Store) RemoveSetDeclaration

func (s *Store) RemoveSetDeclaration(ctx context.Context, set, identifier string) (changed bool, err error)

RemoveSetDeclaration implements ddm.SetStore.

func (*Store) Rewrap

func (s *Store) Rewrap(ctx context.Context) (int, error)

Rewrap rotates retained DDM values using bounded pages and guarded writes.

func (*Store) SetDeclarations

func (s *Store) SetDeclarations(ctx context.Context, set string) ([]string, error)

SetDeclarations implements ddm.SetStore.

func (*Store) SetEnrollments

func (s *Store) SetEnrollments(ctx context.Context, set string, p paging.Page) (paging.Result[mdm.EnrollmentID], error)

SetEnrollments implements ddm.AssignmentStore.

func (*Store) Snapshot

func (s *Store) Snapshot(ctx context.Context, id mdm.EnrollmentID) (*ddm.Snapshot, error)

Snapshot implements ddm.SnapshotStore.

func (*Store) StaticDeclarations

func (s *Store) StaticDeclarations(ctx context.Context, id mdm.EnrollmentID) ([]ddm.Declaration, error)

StaticDeclarations implements ddm.AssignmentStore.

func (*Store) StatusErrors

func (s *Store) StatusErrors(ctx context.Context, id mdm.EnrollmentID, p paging.Page) (paging.Result[ddm.StatusError], error)

StatusErrors implements ddm.StatusStore.

func (*Store) StatusReports

StatusReports implements ddm.StatusStore.

func (*Store) StatusValues

StatusValues implements ddm.StatusStore.

func (*Store) UnassignDeclaration

func (s *Store) UnassignDeclaration(ctx context.Context, id mdm.EnrollmentID, identifier string) (bool, error)

UnassignDeclaration implements ddm.AssignmentStore.

func (*Store) UnassignSet

func (s *Store) UnassignSet(ctx context.Context, id mdm.EnrollmentID, set string) (bool, error)

UnassignSet implements ddm.AssignmentStore.

func (*Store) Update

func (s *Store) Update(ctx context.Context, fn func(ddm.Tx) error) error

Update implements ddm.Store. fn runs in one transaction that commits when fn returns nil and rolls back otherwise. fn must use the Tx it is given; the Store's own methods would run outside the transaction.

Jump to

Keyboard shortcuts

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