configstore

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

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

View Source
const SchemaVersion = 2

SchemaVersion is the store table layout this build understands. Version 2 added administrator accounts.

View Source
const TablePrefix = config.StoreTablePrefix

TablePrefix prefixes every store table; see config.StoreTablePrefix.

Variables

View Source
var (
	ErrAdminExists   = errors.New("configstore: admin account already exists")
	ErrAdminNotFound = errors.New("configstore: admin account not found")
)

Admin account errors.

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

func Init

func Init(ctx context.Context, spec Spec, resolve Resolver) error

Init creates the store tables when absent; it is a no-op on an initialized store of the same version.

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 Resolver

type Resolver func(string) (string, error)

Resolver expands DSN placeholders.

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

func Open(ctx context.Context, spec Spec, resolve Resolver) (*SQLStore, error)

Open connects to an initialized store. It fails with ErrNotInitialized when the tables are missing and with ErrNewerSchema on a newer layout.

func (*SQLStore) Close

func (s *SQLStore) Close() error

Close implements revision.Store.

func (*SQLStore) Create

Create implements revision.Store.

func (*SQLStore) Get

func (s *SQLStore) Get(ctx context.Context, id int64) (revision.Revision, error)

Get implements revision.Store.

func (*SQLStore) GetAdmin

func (s *SQLStore) GetAdmin(ctx context.Context, username string) (AdminAccount, error)

GetAdmin returns one account.

func (*SQLStore) ImportHistory

func (s *SQLStore) ImportHistory(ctx context.Context, revs []revision.Revision) error

ImportHistory implements revision.Store.

func (*SQLStore) List

func (s *SQLStore) List(ctx context.Context, limit int) ([]revision.Revision, error)

List 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.

func (*SQLStore) Published

func (s *SQLStore) Published(ctx context.Context) (revision.Revision, error)

Published implements revision.Store.

func (*SQLStore) Rollback

func (s *SQLStore) Rollback(
	ctx context.Context, expectedCurrent, target int64, m revision.Meta,
) (revision.Revision, error)

Rollback implements revision.Store.

type Spec

type Spec struct {
	Driver string // sqlite | postgres | mysql | oceanbase
	DSN    string
}

Spec is a parsed "<driver>:<dsn>" store location.

func ParseSpec

func ParseSpec(raw string) (Spec, error)

ParseSpec parses "<driver>:<dsn>". The DSN may contain ${ENV} or ${file:/path} placeholders, resolved by Open.

func (Spec) String

func (s Spec) String() string

String returns the spec without its DSN, safe for logs.

Jump to

Keyboard shortcuts

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