migrations

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const RuleAuthenticated = "@request.auth.id != ''"

RuleAuthenticated restricts access to authenticated PocketBase users.

Variables

View Source
var (
	ErrMigrationFailed    = errors.New("migration failed")
	ErrDuplicateMigration = errors.New("duplicate migration")
	ErrMigrationNotFound  = errors.New("migration not found")
	ErrCollectionNotFound = errors.New("collection not found")
)

Functions

This section is empty.

Types

type ConsumerOffsetsMigration added in v0.0.3

type ConsumerOffsetsMigration struct{}

ConsumerOffsetsMigration creates the consumer_offsets collection for tracking consumer progress.

func (*ConsumerOffsetsMigration) Down added in v0.0.3

func (*ConsumerOffsetsMigration) Name added in v0.0.3

func (m *ConsumerOffsetsMigration) Name() string

func (*ConsumerOffsetsMigration) Up added in v0.0.3

type Migration

type Migration interface {
	Name() string
	Up(ctx context.Context, client pbclient.AuthenticatedClient) error
	Down(ctx context.Context, client pbclient.AuthenticatedClient) error
}

Migration defines a reversible change applied through PocketBase using pbclient. Implementations must return a stable, sortable name (e.g. 20250121_add_users) and provide Up/Down hooks that perform the forward and rollback work.

func NewConsumerOffsetsMigration added in v0.0.3

func NewConsumerOffsetsMigration() Migration

NewConsumerOffsetsMigration creates a new consumer offsets migration instance.

type Option

type Option func(*Runner)

Option configures the Runner.

func WithAppName added in v0.0.3

func WithAppName(appName string) Option

WithAppName sets the application name for multi-app migration tracking. When set, migrations will be filtered by appname.

func WithAutoCreate

func WithAutoCreate(autoCreate bool) Option

WithAutoCreate controls whether the migrations collection is created automatically when missing. Defaults to true.

func WithCollectionName

func WithCollectionName(name string) Option

WithCollectionName overrides the default migrations log collection name.

func WithLogCollectionName

func WithLogCollectionName(name string) Option

WithLogCollectionName overrides the default migrations log collection name. Alias for WithCollectionName for clarity.

type PBTime

type PBTime struct {
	time.Time
}

PBTime handles the PocketBase datetime format returned by the API (with a space instead of T).

func (PBTime) After

func (t PBTime) After(u time.Time) bool

func (PBTime) Before

func (t PBTime) Before(u time.Time) bool

func (PBTime) IsZero

func (t PBTime) IsZero() bool

func (PBTime) MarshalJSON

func (t PBTime) MarshalJSON() ([]byte, error)

func (*PBTime) UnmarshalJSON

func (t *PBTime) UnmarshalJSON(data []byte) error

type Record

type Record struct {
	ID        string `json:"id"`
	AppName   string `json:"appname"`
	Name      string `json:"name"`
	AppliedAt PBTime `json:"applied_at"`
}

Record stores bookkeeping data for applied migrations inside PocketBase.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes registered migrations against PocketBase and records progress.

func NewRunner

func NewRunner(client pbclient.AuthenticatedClient, opts ...Option) *Runner

NewRunner constructs a Runner with optional configuration.

func (*Runner) Applied

func (r *Runner) Applied(ctx context.Context) ([]Record, error)

Applied returns the migration records stored in PocketBase.

func (*Runner) Down

func (r *Runner) Down(ctx context.Context, n int) error

Down rolls back the latest n applied migrations.

func (*Runner) Pending

func (r *Runner) Pending(ctx context.Context) ([]Migration, error)

Pending returns registered migrations that have not been applied.

func (*Runner) Register

func (r *Runner) Register(m Migration) error

Register adds a single migration, ensuring unique names.

func (*Runner) RegisterAll

func (r *Runner) RegisterAll(migrations ...Migration) error

RegisterAll adds multiple migrations in order.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes pending migrations in name order.

Jump to

Keyboard shortcuts

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