Help us shape the future of Go! Take the 2026 Go Developer Survey

seed

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package seed runs explicitly registered data seeders through normal Foundry transactions. It never resets tables or treats repeated execution as a wipe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	ID       ID
	Requires []ID
	Run      func(context.Context, *database.Tx) error
}

Definition declares normal transactional domain work and its prerequisites. Run must use the supplied Tx. Idempotence is its own business contract; no history table silently suppresses later explicit invocations.

type ID

type ID string

ID names a seeder once at registration. Use namespaces such as app.countries to distinguish application and plugin contributions.

type Registry

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

Registry snapshots declarations and validates dependencies before execution. Shared callbacks must be concurrency-safe if applications invoke Run concurrently.

func New

func New(definitions ...Definition) (*Registry, error)

New validates and snapshots seeder declarations and orders them by dependency. It rejects invalid, duplicate, missing or cyclic dependencies before execution.

func (*Registry) IDs

func (r *Registry) IDs() []ID

IDs returns an owned copy of the deterministic dependency order.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, db *database.DB, selected ...ID) (Result, error)

Run executes selected seeders and their dependencies once in deterministic order. Omit selected to run the whole registry. Selection errors fail before database I/O. Each seeder uses a separate transaction; earlier commits remain if a later seeder fails. The same seeder may run again in a later explicit call.

type Result

type Result struct {
	Committed []ID `json:"committed"`
	StoppedAt *ID  `json:"stopped_at,omitempty"`
}

Result lists seeders whose database transactions are confirmed committed. StoppedAt identifies the invocation that returned an error. It can also appear in Committed when only an after-commit callback failed. Inspect database error outcomes before retrying; the framework never retries arbitrary domain work.

Jump to

Keyboard shortcuts

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