Documentation
¶
Overview ¶
Package configstore persists configuration revisions in SQLite or in a PostgreSQL, MySQL or OceanBase database. Every table uses the smcp_ prefix; the store keeps its own schema version and fails closed on an unknown one.
Index ¶
- Constants
- Variables
- func Init(ctx context.Context, spec Spec, resolve Resolver) error
- type AdminAccount
- type Resolver
- type SQLStore
- func (s *SQLStore) Close() error
- func (s *SQLStore) Create(ctx context.Context, d revision.Draft) (revision.Revision, error)
- func (s *SQLStore) Get(ctx context.Context, id int64) (revision.Revision, error)
- func (s *SQLStore) GetAdmin(ctx context.Context, username string) (AdminAccount, error)
- func (s *SQLStore) ImportHistory(ctx context.Context, revs []revision.Revision) error
- func (s *SQLStore) List(ctx context.Context, limit int) ([]revision.Revision, error)
- func (s *SQLStore) ListAdmins(ctx context.Context) ([]AdminAccount, error)
- func (s *SQLStore) MutateAdmins(ctx context.Context, fn func(all []AdminAccount) ([]AdminAccount, error)) ([]AdminAccount, error)
- func (s *SQLStore) Publish(ctx context.Context, id, expectedCurrent int64, _ revision.Meta) (revision.Revision, error)
- func (s *SQLStore) Published(ctx context.Context) (revision.Revision, error)
- func (s *SQLStore) Rollback(ctx context.Context, expectedCurrent, target int64, m revision.Meta) (revision.Revision, error)
- type Spec
Constants ¶
const SchemaVersion = 2
SchemaVersion is the store table layout this build understands. Version 2 added administrator accounts.
const TablePrefix = config.StoreTablePrefix
TablePrefix prefixes every store table; see config.StoreTablePrefix.
Variables ¶
var ( ErrAdminExists = errors.New("configstore: admin account already exists") ErrAdminNotFound = errors.New("configstore: admin account not found") )
Admin account errors.
var ( ErrInvalidSpec = errors.New("configstore: invalid store spec") ErrNotInitialized = errors.New("configstore: store is not initialized; run `sql-mcp-server store init`") ErrNewerSchema = errors.New("configstore: store schema is newer than this build") )
Errors returned when opening a store.
Functions ¶
Types ¶
type AdminAccount ¶
type AdminAccount struct {
Username string
PasswordHash string
Permissions []string
Disabled bool
CreatedAt time.Time
UpdatedAt time.Time
}
AdminAccount is an administrator of the admin API. Accounts are stored outside configuration revisions, so changes take effect immediately and a configuration publish never alters administrator access.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore is a revision.Store backed by database/sql. IDs come from a counter row and every publish or rollback first updates a lock row, so all state transitions serialize on a row lock in every supported backend.
func Open ¶
Open connects to an initialized store. It fails with ErrNotInitialized when the tables are missing and with ErrNewerSchema on a newer layout.
func (*SQLStore) ImportHistory ¶
ImportHistory implements revision.Store.
func (*SQLStore) ListAdmins ¶
func (s *SQLStore) ListAdmins(ctx context.Context) ([]AdminAccount, error)
ListAdmins returns every account ordered by username.
func (*SQLStore) MutateAdmins ¶
func (s *SQLStore) MutateAdmins( ctx context.Context, fn func(all []AdminAccount) ([]AdminAccount, error), ) ([]AdminAccount, error)
MutateAdmins is the only way to change accounts. In one transaction serialized by the store lock it reads every account, calls fn, and writes the accounts fn returns: new usernames are inserted, known ones replaced. Concurrent calls run one after another, so a rule fn checks across all accounts (such as keeping an account manager) holds when it commits. It returns the written accounts with their timestamps.
func (*SQLStore) Publish ¶
func (s *SQLStore) Publish(ctx context.Context, id, expectedCurrent int64, _ revision.Meta) (revision.Revision, error)
Publish implements revision.Store.