planview

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package planview reads a stored plan back the way the operator reads it.

The SQL an operator applies lives in immutable PtahSchemaPlanChunk objects that a plan manifest binds by index, size and digest. Reading them by hand means reproducing that binding, and the binding is not a format: a chunk boundary falls wherever 512 KiB falls, which may be the middle of a SQL string, of a JSON escape, or of a UTF-8 character. This package resolves which plan a reader asked for, hands the reconstruction to the operator's own store, and returns bytes that have already been checked against everything the plan says about itself.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSchemaNotFound = errors.New("no such schema")
	ErrNoPlan         = errors.New("no such plan")
	ErrUnsupported    = errors.New("unsupported plan format")
)

Errors a caller distinguishes. Absence is not an empty plan: a reader who asked for SQL that is not there is told so, with a status to match.

View Source
var Formats = []Format{Text, SQL, JSON}

Formats are the accepted values, in the order the help lists them.

Functions

func Render

func Render(out io.Writer, view View, format Format) error

Render writes one view in the requested format.

Every format is written from the document the store verified. The JSON one is that document unchanged rather than a re-serialization of the decoded plan, so what a reader saves still matches the content digest above it.

Types

type Format

type Format string

Format is how a reader asked to see a plan.

const (
	// Text is the default: what the plan is, then the SQL it holds.
	Text Format = "text"
	// SQL is the statements alone, for piping somewhere else.
	SQL Format = "sql"
	// JSON is the stored document, byte for byte.
	JSON Format = "json"
)

type Selection

type Selection string

Selection is which stored plan a reader asked for.

They are two different questions and neither answers the other: the current plan is what the operator would run next, and the applied plan is what the last confirmed apply ran. A reader asking for one is never given the other, and neither is "the newest plan object in the namespace".

const (
	// Current is the plan the schema's status names now.
	Current Selection = "current"
	// Applied is the plan the last confirmed apply ran.
	Applied Selection = "applied"
)

type View

type View struct {
	Namespace   string
	Schema      string
	Selection   Selection
	PlanName    string
	PlanUID     types.UID
	Fingerprint string

	ContentDigest string
	Dialect       string
	Destructive   bool
	// PrivilegeChanges are the kinds of authority the plan object records. They
	// are what the manager decided on: any of them made the plan wait for an
	// approval under apply: Always.
	PrivilegeChanges []string
	// UnrecordedPrivilegeChanges are kinds this plugin reads in the SQL and the
	// plan object does not record. The manager that published the plan did not
	// hold the plan for them, so they are shown apart from the recorded ones
	// rather than as a reason the plan waited. They appear only where the
	// plugin and the manager are different builds.
	UnrecordedPrivilegeChanges []string
	StatementCount             int
	CreatedAt                  metav1.Time
	// CompletedAt is when the apply this plan belongs to finished. It is set
	// for an applied plan and empty for a current one, which has not run.
	CompletedAt *metav1.Time

	Document []byte
	Plan     dataplane.PlanFile
}

View is one verified plan.

Document holds the bytes the store reconstructed and checked against the plan's content digest. They are the plan as it was published, and printing them is how a reader gets a document that still matches that digest.

func Load

func Load(
	ctx context.Context,
	reader client.Reader,
	namespace, name string,
	selection Selection,
) (View, error)

Load resolves the selected plan, reconstructs it and verifies it.

Nothing reaches the caller before every check has held. A plan whose last chunk is corrupt produces an error and no document, rather than an error after half the SQL has already been handed over.

Jump to

Keyboard shortcuts

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