migrations

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 Migration

type Migration interface {
	Name() string
	Up(client *pbclient.Client) error
	Down(client *pbclient.Client) 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.

type Option

type Option func(*Runner)

Option configures the Runner.

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"`
	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.Client, 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