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 ¶
- Decision record 0020: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0020-ddm-engine-membership-and-storage.md
- Decision record 0021: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0021-status-reports-and-subscriptions.md
- Decision record 0022: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0022-change-notifier.md
- Decision record 0012: https://github.com/deploymenttheory/go-apple-dm/blob/main/docs/research/decisions/0012-sql-storage-backends.md (dialects and migrations)
- Migrations: ddm/sqlstore/migrations/{sqlite,postgres,mysql}/0001_init.sql
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) AddSetDeclaration(ctx context.Context, set, identifier string, at time.Time) (changed bool, err error)
- func (s *Store) AffectedEnrollments(ctx context.Context, identifiers, sets []string) ([]mdm.EnrollmentID, error)
- func (s *Store) AssignDeclaration(ctx context.Context, id mdm.EnrollmentID, identifier string, at time.Time) (changed bool, err error)
- func (s *Store) AssignSet(ctx context.Context, id mdm.EnrollmentID, set string, at time.Time) (changed bool, err error)
- func (s *Store) ChangeStats(ctx context.Context, now time.Time) (pending, failed int64, err error)
- func (s *Store) ClearEnrollment(ctx context.Context, id mdm.EnrollmentID) error
- func (s *Store) CompleteChanges(ctx context.Context, seqs []int64) error
- func (s *Store) DB() *sql.DB
- func (s *Store) DeclarationSets(ctx context.Context, identifier string) ([]string, error)
- func (s *Store) DeclarationStatus(ctx context.Context, id mdm.EnrollmentID) ([]ddm.DeclarationStatus, error)
- func (s *Store) DeclarationStatusByIdentifier(ctx context.Context, identifier string, p paging.Page) (paging.Result[ddm.EnrollmentDeclarationStatus], error)
- func (s *Store) DeleteDeclaration(ctx context.Context, identifier string) error
- func (s *Store) DeleteSet(ctx context.Context, name string) error
- func (s *Store) EnrollmentDeclarations(ctx context.Context, id mdm.EnrollmentID) ([]string, error)
- func (s *Store) EnrollmentIdentity(ctx context.Context, rawID string) (mdm.EnrollmentID, error)
- func (s *Store) EnrollmentSets(ctx context.Context, id mdm.EnrollmentID) ([]string, error)
- func (s *Store) FailChanges(ctx context.Context, seqs []int64, msg string, nextAttempt time.Time) error
- func (s *Store) GetDeclaration(ctx context.Context, identifier string) (*ddm.Declaration, error)
- func (s *Store) GetDeclarationVersion(ctx context.Context, identifier, serverToken string) (*ddm.DeclarationVersion, error)
- func (s *Store) GetSet(ctx context.Context, name string) (*ddm.Set, error)
- func (s *Store) ListDeclarations(ctx context.Context, q ddm.DeclarationQuery, p paging.Page) (paging.Result[ddm.Declaration], error)
- func (s *Store) ListSets(ctx context.Context, p paging.Page) (paging.Result[ddm.Set], error)
- func (s *Store) PendingChanges(ctx context.Context, now time.Time, limit int) ([]ddm.Change, error)
- func (s *Store) PruneVersions(ctx context.Context) (int64, error)
- func (s *Store) PutDeclaration(ctx context.Context, d *ddm.Declaration) (changed bool, err error)
- func (s *Store) PutSet(ctx context.Context, name string, at time.Time) (created bool, err error)
- func (s *Store) PutSnapshot(ctx context.Context, snap *ddm.Snapshot) error
- func (s *Store) PutStatus(ctx context.Context, id mdm.EnrollmentID, u ddm.StatusUpdate) (out ddm.StatusOutcome, err error)
- func (s *Store) RecordChanges(ctx context.Context, ids []mdm.EnrollmentID, reason string, at time.Time) error
- func (s *Store) RemoveSetDeclaration(ctx context.Context, set, identifier string) (changed bool, err error)
- func (s *Store) Rewrap(ctx context.Context) (int, error)
- func (s *Store) SetDeclarations(ctx context.Context, set string) ([]string, error)
- func (s *Store) SetEnrollments(ctx context.Context, set string, p paging.Page) (paging.Result[mdm.EnrollmentID], error)
- func (s *Store) Snapshot(ctx context.Context, id mdm.EnrollmentID) (*ddm.Snapshot, error)
- func (s *Store) StaticDeclarations(ctx context.Context, id mdm.EnrollmentID) ([]ddm.Declaration, error)
- func (s *Store) StatusErrors(ctx context.Context, id mdm.EnrollmentID, p paging.Page) (paging.Result[ddm.StatusError], error)
- func (s *Store) StatusReports(ctx context.Context, id mdm.EnrollmentID, p paging.Page) (paging.Result[ddm.StatusReportRecord], error)
- func (s *Store) StatusValues(ctx context.Context, id mdm.EnrollmentID, q ddm.StatusValueQuery, ...) (paging.Result[ddm.StatusValue], error)
- func (s *Store) UnassignDeclaration(ctx context.Context, id mdm.EnrollmentID, identifier string) (bool, error)
- func (s *Store) UnassignSet(ctx context.Context, id mdm.EnrollmentID, set string) (bool, error)
- func (s *Store) Update(ctx context.Context, fn func(ddm.Tx) error) error
Constants ¶
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 ¶
var ErrUnsupportedDialect = errors.New("sqlstore: unsupported dialect")
ErrUnsupportedDialect is returned for a dialect without embedded migrations (anything but sqlite, postgres, and mysql).
Functions ¶
func MigrationSet ¶
func MigrationSet(d sqlcommon.Dialect) (sqlcommon.MigrationSet, error)
MigrationSet returns the DDM migrations for the dialect.
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 ¶
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 ¶
ChangeStats implements ddm.ChangeStore.
func (*Store) ClearEnrollment ¶
ClearEnrollment implements ddm.Tx.
func (*Store) CompleteChanges ¶
CompleteChanges implements ddm.ChangeStore.
func (*Store) DeclarationSets ¶
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 ¶
DeleteDeclaration implements ddm.DeclarationStore.
func (*Store) EnrollmentDeclarations ¶
EnrollmentDeclarations implements ddm.AssignmentStore.
func (*Store) EnrollmentIdentity ¶
EnrollmentIdentity implements ddm.AssignmentStore.
func (*Store) EnrollmentSets ¶
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 ¶
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) 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) PendingChanges ¶
PendingChanges implements ddm.ChangeStore.
func (*Store) PruneVersions ¶
PruneVersions implements ddm.DeclarationStore.
func (*Store) PutDeclaration ¶
PutDeclaration implements ddm.DeclarationStore.
func (*Store) PutSnapshot ¶
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) SetDeclarations ¶
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) 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 ¶
func (s *Store) StatusReports(ctx context.Context, id mdm.EnrollmentID, p paging.Page) (paging.Result[ddm.StatusReportRecord], error)
StatusReports implements ddm.StatusStore.
func (*Store) StatusValues ¶
func (s *Store) StatusValues(ctx context.Context, id mdm.EnrollmentID, q ddm.StatusValueQuery, p paging.Page) (paging.Result[ddm.StatusValue], error)
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 ¶
UnassignSet implements ddm.AssignmentStore.