workflow

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, db *sql.DB, opts ApplyOptions) (any, error)

func BundleFiles

func BundleFiles(files []File) (fs.FS, error)

func Decode

func Decode(data []byte, value any) error

func Unwrap

func Unwrap(data []byte) (json.RawMessage, []string, error)

func Validate

func Validate(opts ApplyOptions) error

Validate checks an artifact's integrity and acknowledgements without opening a database. Each artifact carries its own hash, which guards only that the file is what its planner wrote.

func Variables

func Variables(values []string) (map[string]cty.Value, error)

Types

type ApplyOptions

type ApplyOptions struct {
	Dialect     string
	Schema      string
	Artifact    json.RawMessage
	Acks        []string
	LockTimeout time.Duration
	CSV         csvdata.Options
}

ApplyOptions applies an artifact as reviewed: its own hash guards its integrity, and Acks acknowledge its destructive steps.

type ContentKind added in v1.3.0

type ContentKind string

ContentKind is what a bundle file holds: SQL scripts or HCL schema.

const (
	SQLContent ContentKind = "sql"
	HCLContent ContentKind = "hcl"
)

func DetectContent added in v1.3.0

func DetectContent(name, content string) (ContentKind, bool)

DetectContent is the kind of the file name holding content. A .sql or .hcl name is that kind whatever it holds, so its loader reports what is wrong with it. Any other file is HCL when it parses as an HCL body declaring something, SQL when its first word past comments opens a SQL statement, and neither otherwise.

type File

type File struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

func ClassifyFiles added in v1.3.0

func ClassifyFiles(files []File) ([]File, error)

ClassifyFiles names every file by the kind DetectContent finds, since the bundle loaders select files by extension: a .sql or .hcl path is kept, any other path's extension becomes the kind's. A file of neither kind, or two files named alike once classified, is an error.

type Options

type Options struct {
	Dialect    string
	Schema     string
	Source     Source
	Bundle     fs.FS
	Variables  []string
	Routines   string
	AllowDrops bool
	CSV        csvdata.Options
}

type PlanResult

type PlanResult struct {
	Dialect    string            `json:"dialect"`
	Schema     string            `json:"schema"`
	Artifact   json.RawMessage   `json:"artifact"`
	Hash       string            `json:"hash"`
	Acks       []string          `json:"acks"`
	Steps      []Step            `json:"steps"`
	Changes    []native.Change   `json:"changes"`
	Warnings   []string          `json:"warnings"`
	Applicable bool              `json:"applicable"`
	SQL        string            `json:"sql"`
	CSVPlan    *csvdata.Artifact `json:"csvPlan,omitempty"`
	// ScriptPlan is the plan file of a SQL Server script bundle.
	ScriptPlan *scriptplan.PlanFile `json:"scriptPlan,omitempty"`
	Original   json.RawMessage      `json:"-"`
}

func Plan

func Plan(ctx context.Context, db *sql.DB, opts Options) (PlanResult, error)

func Review

func Review(data []byte, dialect, schema string) (PlanResult, error)

type RunOptions

type RunOptions struct {
	Mode            string
	Target          dbtarget.OpenOptions
	Plan            Options
	Acks            []string
	ArtifactContent json.RawMessage
	LockTimeout     string
}

type RunResult

type RunResult struct {
	Plan     *PlanResult `json:"plan,omitempty"`
	Mode     string      `json:"mode"`
	Hash     string      `json:"hash,omitempty"`
	Acks     []string    `json:"acks,omitempty"`
	Artifact any         `json:"artifact,omitempty"`
	Result   any         `json:"result,omitempty"`
}

func Execute

func Execute(ctx context.Context, opts RunOptions, record *history.Record, t *task.Task) (payload RunResult, returnErr error)

type Source

type Source struct {
	Kind    string `json:"kind"`
	Content string `json:"content,omitempty"`
	Files   []File `json:"files,omitempty"`
}

type Step

type Step struct {
	ID          string `json:"id"`
	SQL         string `json:"sql"`
	Destructive bool   `json:"destructive"`
}

Jump to

Keyboard shortcuts

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