jobs

package
v1.0.76 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package jobs implements RelSpec declarative job files.

A job file is a small YAML manifest that names one or more jobs and, for each job, the RelSpec command to run plus its inputs, output and options. It lets users run "relspec job run build-schema" instead of repeating long command lines.

The job-file system is deliberately NOT a shell: "command" is a closed enum of vetted RelSpec workflows, every path is resolved relative to the directory holding the job file and may not escape it, and remote database credentials are referenced by environment-variable name only - never embedded in the manifest. All discovery, parsing and validation in this package is side-effect free; nothing here reads input schemas, opens database connections or writes output. Execution lives in the CLI layer and only runs after Validate and the caller's pre-flight checks pass.

Index

Constants

View Source
const (
	CommandConvert     = "convert"      // read one or more schema files, optionally merge, write one output
	CommandMerge       = "merge"        // additive merge of two or more schema files into one output
	CommandScriptsList = "scripts-list" // deterministically list SQL scripts across one or more directories
)

Command names are a closed allow-list. Arbitrary strings are rejected.

View Source
const SchemaVersion = 1

SchemaVersion is the only job-file schema version this build understands.

Variables

SupportedCommands lists every accepted command, in help order.

Functions

func Discover

func Discover(dir string) ([]string, error)

Discover returns the job files in dir in deterministic order. The default file "relspec.yml"/"relspec.yaml" sorts first, followed by named files "relspec.<name>.yml"/"relspec.<name>.yaml" in lexical order.

func SafeJoin

func SafeJoin(root, rel string) (string, error)

SafeJoin resolves rel against root and guarantees the result stays inside root. It is the single choke point for turning a manifest path into a filesystem path.

Types

type File

type File struct {
	Version int             `yaml:"version"`
	Jobs    map[string]*Job `yaml:"jobs"`
}

File is the on-disk shape of a single job file.

type Input

type Input struct {
	Path string `yaml:"path"`
	// Format is the RelSpec reader format (dbml, json, yaml, pgsql, ...).
	Format string `yaml:"format"`
	// ConnEnv is the NAME of an environment variable holding a connection
	// string, used with database formats. The value is never stored here.
	ConnEnv string `yaml:"conn_env"`
}

Input is one declared input schema.

type Job

type Job struct {
	// Name and SourceFile are populated by Load, not parsed from YAML.
	Name       string `yaml:"-"`
	SourceFile string `yaml:"-"`

	Command     string   `yaml:"command"`
	Description string   `yaml:"description"`
	DependsOn   []string `yaml:"depends_on"`
	Inputs      []Input  `yaml:"inputs"`
	ScriptDirs  []string `yaml:"script_dirs"`
	Output      *Output  `yaml:"output"`
	Options     Options  `yaml:"options"`
	Logfile     string   `yaml:"logfile"`
}

Job is one named job within a job file.

func (*Job) Dir

func (j *Job) Dir() string

Dir returns the directory that a job's relative paths resolve against: the directory containing the job file that declared it.

type Options

type Options struct {
	FlattenSchema   bool   `yaml:"flatten_schema"`
	Schema          string `yaml:"schema"`
	Package         string `yaml:"package"`
	ContinueOnError bool   `yaml:"continue_on_error"`
	SkipRelations   bool   `yaml:"skip_relations"`
	SkipEnums       bool   `yaml:"skip_enums"`
	SkipViews       bool   `yaml:"skip_views"`
	SkipDomains     bool   `yaml:"skip_domains"`
	SkipSequences   bool   `yaml:"skip_sequences"`
}

Options carries the subset of command flags a job file may set.

type Output

type Output struct {
	Format    string `yaml:"format"`
	Path      string `yaml:"path"`
	ConnEnv   string `yaml:"conn_env"`
	Overwrite bool   `yaml:"overwrite"`
}

Output is the declared output target.

type Set

type Set struct {
	// Files is the sorted list of job files that contributed jobs.
	Files []string
	// Jobs is keyed by job name.
	Jobs map[string]*Job
}

Set is the merged view of all discovered/selected job files.

func Load

func Load(paths []string) (*Set, error)

Load parses every path, rejects unknown fields and unsupported versions, and merges all jobs into one Set. A job name defined by more than one file is a hard error. Load performs structural checks only; call Validate for full semantic validation.

func (*Set) Names

func (s *Set) Names() []string

Names returns all job names in deterministic (sorted) order.

func (*Set) Plan

func (s *Set) Plan(name string, includeDeps bool) ([]*Job, error)

Plan returns the jobs to execute for name in dependency order. When includeDeps is false only the named job is returned (its declared dependencies are still validated to exist and be acyclic by Validate).

func (*Set) Validate

func (s *Set) Validate() error

Validate runs full semantic validation over the whole set and returns a single error describing every problem found. It never touches the filesystem beyond what Load already read; existence of input files and environment variables is checked by the caller immediately before execution.

Jump to

Keyboard shortcuts

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