seed

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package seed orchestrates loading YAML config into Postgres for the app/ arch. The flow:

  1. Parse every YAML in the source dir (multi-doc supported).
  2. List every row from each entity store to learn existing name→id bindings.
  3. For YAML names that have no PG row yet, mint a fresh UUIDv7 and add it to the resolver map.
  4. Translate each DTO → domain object via manifest.ToXxx using the merged resolver, stamping Meta.ID from the same map.
  5. Upsert in dependency order: Provider, Host, RateLimit, HostKey, Model, Policy, RelayKey.

Diffing, dry-run, and identity (User) handling are deliberately omitted — this is the minimal "make the rows be there" path. Idempotent: re-running over the same YAML is a no-op for unchanged rows and an in-place update for changed ones.

Index

Constants

View Source
const DefaultCatalogURLTemplate = "https://github.com/wyolet/relay-catalog/archive/{version}.tar.gz"

DefaultCatalogURLTemplate is where versioned catalog trees are fetched from when RELAY_CATALOG_URL is unset. "{version}" is replaced with the requested ref; GitHub serves source archives for any tag/branch/sha.

Variables

This section is empty.

Functions

func FetchCatalog added in v0.5.0

func FetchCatalog(ctx context.Context, urlTemplate, version, destDir string) (string, error)

FetchCatalog downloads the catalog source archive for version from urlTemplate ("{version}" substituted; empty = DefaultCatalogURLTemplate), extracts it under destDir, and returns the directory holding the catalog data tree. Only regular files and directories are extracted — symlinks and entries escaping destDir are rejected.

The returned root follows the source-archive convention: a top-level `data/` dir wins (directly under destDir, or inside a single wrapping directory the way GitHub archives unpack); otherwise destDir itself is assumed to be the data tree.

Types

type Options

type Options struct {
	Pool      *pgxpool.Pool
	YAMLDir   string
	MasterKey []byte // for stored-mode HostKey rows; nil disables them

	// ClearDirty re-seeds (overwrites) rows an operator has edited, resetting
	// them to the catalog version and clearing their dirty flag. Default false:
	// dirty rows are skipped so re-seeding never clobbers operator changes.
	ClearDirty bool
}

Options configures a seed run.

type Result

type Result struct {
	Providers    int
	Hosts        int
	RateLimits   int
	HostKeys     int
	Models       int
	Pricings     int
	HostBindings int
	Policies     int
	RelayKeys    int
	Skipped      int // dirty rows preserved (operator-edited; not re-seeded)
}

Result summarises a seed run.

func Run

func Run(ctx context.Context, opts Options) (*Result, error)

Run executes the seed pipeline end-to-end.

Jump to

Keyboard shortcuts

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