Documentation
¶
Overview ¶
Package seed loads reference data into a database from seed files. The consumer supplies the parts only it knows — the seed file system, a typed load function per table, and the step order — and the runner owns the mechanics: format selection by file extension, decoding, one transaction per step, and the outcome log. The package is stdlib-only, so it lives in the base module beside database.
Steps ¶
Table binds one seed file to a typed load function, producing an opaque Step; Runner.Run executes the steps in the order given, each in its own transaction, stopping at the first failure with the step's path in the error. Idempotency belongs to the load function's SQL — INSERT … ON CONFLICT DO NOTHING against the table's natural key — because the conflict target is knowledge the consumer holds, not the runner.
Formats ¶
Format decodes one seed file and owns the file extensions it claims. Formats are passed to New at construction — typed registration, no registry, no init side effects — and no two may claim the same extension. JSON ships with the package and decodes strictly: an unknown field or trailing content is a defect in a curated seed file, not data to ignore. Another format is one Format implementation, supplied by a sub-module or by the consumer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Format ¶
type Format interface {
// Extensions lists the file extensions this format owns, leading dot
// included, as ".json".
Extensions() []string
// Decode reads a whole seed file from r into v.
Decode(r io.Reader, v any) error
}
Format decodes one seed file into the shape a Step expects. A format owns one or more file extensions, and the Runner selects it by the extension of the step's path. Formats are passed at construction (New); there is no registry.
type JSON ¶
type JSON struct{}
JSON is the Format for .json seed files: one JSON document per file, decoded strictly. An unknown field or content after the document is a data defect in a curated seed file, so both fail the decode rather than pass silently.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes seed steps against a database, decoding each step's seed file with the format that owns its extension.
type Step ¶
type Step struct {
// contains filtered or unexported fields
}
Step is one ordered unit of a seed run: a seed file bound to the load function that inserts its rows. Construct steps with Table.