model

package
v1.58.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VolatilityVolatile = "VOLATILE"
	ParallelUnsafe     = "UNSAFE"
)

Volatility and parallel-safety values, and the defaults pg_get_functiondef leaves out of its output.

Variables

View Source
var JSONMarshalers = json.WithMarshalers(json.MarshalToFunc(marshalColumns))

JSONMarshalers holds what the JSON document pistachio writes needs on top of the struct tags. `parse` and `dump` both write through it, and the JSON Schema describes what it produces, so a test that takes a golden through it sees the bytes the commands write.

Functions

func CompositeTypeToSQL added in v1.20.0

func CompositeTypeToSQL(ct *CompositeType) string

func CompositeTypesToSQL added in v1.20.0

func CompositeTypesToSQL(compositeTypes *orderedmap.Map[string, *CompositeType]) string

func DollarQuote added in v1.30.0

func DollarQuote(s string) string

DollarQuote wraps s in the shortest dollar-quote delimiter it does not already contain.

func DomainToSQL added in v0.12.0

func DomainToSQL(d *Domain) string

func DomainsToSQL added in v0.12.0

func DomainsToSQL(domains *orderedmap.Map[string, *Domain]) string

func EnumToSQL added in v0.9.0

func EnumToSQL(e *Enum) string

func EnumsToSQL added in v0.9.0

func EnumsToSQL(enums *orderedmap.Map[string, *Enum]) string

func Ident

func Ident(names ...string) string

func QuoteLiteral

func QuoteLiteral(s string) string

func ResetStorageParamsSQL added in v1.36.0

func ResetStorageParamsSQL(fqtn string, names []string) string

ResetStorageParamsSQL returns the statement that hands the named storage parameters back to their defaults. RESET is the only way to say that: the catalog holds no entry for a parameter that was never set, so a SET has no default value to name.

func ResetViewStorageParamsSQL added in v1.45.0

func ResetViewStorageParamsSQL(fqvn, objType string, names []string) string

ResetViewStorageParamsSQL returns the statement that hands the named storage parameters back to their defaults. RESET is the only way to say that: the catalog holds no entry for a parameter that was never set, so a SET has no default value to name.

func RoutineToSQL added in v1.30.0

func RoutineToSQL(r *Routine) string

func RoutinesToSQL added in v1.30.0

func RoutinesToSQL(routines *orderedmap.Map[string, *Routine]) string

func SequenceToSQL added in v1.17.0

func SequenceToSQL(seq *Sequence) string

func SequencesToSQL added in v1.17.0

func SequencesToSQL(sequences *orderedmap.Map[string, *Sequence]) string

func SetCheckOptionSQL added in v1.44.0

func SetCheckOptionSQL(fqvn, option string) string

SetCheckOptionSQL returns the statement that puts the view's check option at option, or resets it when option is empty. Both forms leave the definition alone.

func SetCompressionSQL added in v1.32.0

func SetCompressionSQL(fqtn, col, compression string) string

SetCompressionSQL returns the statement that puts a column's TOAST compression at compression. An empty method hands the column back to default_toast_compression.

func SetStorageParamsSQL added in v1.36.0

func SetStorageParamsSQL(fqtn string, params []string) string

SetStorageParamsSQL returns the statement that sets the named storage parameters. It does not rewrite the table.

func SetStorageSQL added in v1.32.0

func SetStorageSQL(fqtn, col, storage string) string

SetStorageSQL returns the statement that puts a column's TOAST strategy at storage, one of the four keywords. It is a statement of its own because a column definition accepts STORAGE only from PostgreSQL 16 on.

func SetViewStorageParamsSQL added in v1.45.0

func SetViewStorageParamsSQL(fqvn, objType string, params []string) string

SetViewStorageParamsSQL returns the statement that sets the named storage parameters on a view, objType being what View.ObjType reports. It leaves the definition alone.

func SortedStorageParams added in v1.36.0

func SortedStorageParams(params map[string]string) *orderedmap.Map[string, string]

SortedStorageParams turns a name -> value map of storage parameters into an ordered map keyed in name order, so neither the comparison nor the dump depends on the order a file or the catalog kept them in.

func SplitQualifiedName added in v1.21.1

func SplitQualifiedName(s string) []string

SplitQualifiedName splits a qualified name into its parts, respecting quoting: `public."my.coll"` -> [`public`, `"my.coll"`].

func StripTypeSchema added in v1.30.0

func StripTypeSchema(typeName, schema string) string

StripTypeSchema removes a redundant "<schema>." qualifier from a type name, preserving any trailing "[]". The catalog reports a type in the search path unqualified (via format_type), while desired SQL may write it schema- qualified. Stripping the owning object's schema makes the two forms compare equal. A type in a different search-path schema than its owner is not covered.

func TableToSQL added in v0.3.0

func TableToSQL(t *Table) string

func TablesToSQL

func TablesToSQL(tables *orderedmap.Map[string, *Table]) string

func TriggerStateSQL added in v1.29.0

func TriggerStateSQL(fqtn, name string, state TriggerState) string

TriggerStateSQL renders the ALTER TABLE that puts a trigger in the given state. Exported so diff can reuse it for the case StateSQL suppresses: a trigger whose definition did not change going back to the default state.

func UnquoteIdent added in v1.21.1

func UnquoteIdent(s string) string

UnquoteIdent is the inverse of quoteIdent: it strips the surrounding double quotes and unescapes doubled ones. An unquoted identifier is folded to lower case, the way PostgreSQL reads it.

func ViewToSQL added in v0.3.0

func ViewToSQL(v *View) string

func ViewsToSQL

func ViewsToSQL(views *orderedmap.Map[string, *View]) string

Types

type Column

type Column struct {
	Name       string  `json:"name"`
	RenameFrom *string `json:"rename_from"`
	TypeName   string  `json:"type"`
	// SerialSequence names the sequence a serial column owns, schema
	// qualified. Only the catalog fills it: a type name says the column is a
	// serial, but not what PostgreSQL called its sequence. nil otherwise.
	SerialSequence *string        `json:"serial_sequence"`
	NotNull        bool           `json:"not_null"`
	NotNullName    *string        `json:"not_null_name"`
	Default        *string        `json:"default"`
	Identity       ColumnIdentity `json:"identity"`
	// IdentitySeq holds the sequence parameters of an identity column. It is
	// nil when the column is not an identity column.
	IdentitySeq *IdentitySequence `json:"identity_sequence"`
	Generated   ColumnGenerated   `json:"generated"`
	// Collation in quoted SQL form, ready to follow COLLATE
	// (e.g. `pg_catalog."C"`). nil for the default collation.
	Collation *string `json:"collation"`
	// StorageType is the column's TOAST strategy: plain, external, extended
	// or main. The desired side holds what the definition wrote, empty when
	// it wrote nothing or wrote DEFAULT.
	StorageType string `json:"storage_type"`
	// TypeStorage is the strategy the column's type defaults to. Only the
	// catalog fills it, since the desired side cannot know it, and the diff
	// resolves an unwritten StorageType against it.
	TypeStorage string `json:"type_storage"`
	// Compression is the column's TOAST compression method (pglz, lz4), empty
	// when the column carries none and default_toast_compression decides.
	Compression string  `json:"compression"`
	Comment     *string `json:"comment"`
}

func (*Column) String

func (col *Column) String() string

type ColumnGenerated

type ColumnGenerated byte

func (ColumnGenerated) IsGeneratedColumn

func (b ColumnGenerated) IsGeneratedColumn() bool

func (ColumnGenerated) IsStoredGeneratedColumn

func (b ColumnGenerated) IsStoredGeneratedColumn() bool

func (ColumnGenerated) IsVirtualGeneratedColumn

func (b ColumnGenerated) IsVirtualGeneratedColumn() bool

func (ColumnGenerated) MarshalJSON added in v1.51.0

func (b ColumnGenerated) MarshalJSON() ([]byte, error)

MarshalJSON writes the generation kind as a word instead of the pg_attribute character, since the JSON is read outside pistachio.

type ColumnIdentity

type ColumnIdentity byte

func (ColumnIdentity) IsGeneratedAlways

func (b ColumnIdentity) IsGeneratedAlways() bool

func (ColumnIdentity) IsGeneratedByDefault

func (b ColumnIdentity) IsGeneratedByDefault() bool

func (ColumnIdentity) IsIdentityColumn

func (b ColumnIdentity) IsIdentityColumn() bool

func (ColumnIdentity) MarshalJSON added in v1.51.0

func (b ColumnIdentity) MarshalJSON() ([]byte, error)

MarshalJSON writes the identity kind as a word instead of the pg_attribute character, since the JSON is read outside pistachio.

type CompositeAttribute added in v1.20.0

type CompositeAttribute struct {
	Name     string `json:"name"`
	TypeName string `json:"type"`
	// Collation in quoted SQL form, ready to follow COLLATE
	// (e.g. `pg_catalog."C"`). nil for the default collation.
	Collation *string `json:"collation"`
	// RenameFrom maps the attribute to the current attribute it renames. Set by
	// the parser from an inline -- pista:renamed-from directive; always nil on
	// the catalog side.
	RenameFrom *string `json:"rename_from"`
	Comment    *string `json:"comment"`
}

CompositeAttribute is one field of a composite type (CREATE TYPE ... AS (...)).

func (CompositeAttribute) TypeSQL added in v1.20.0

func (a CompositeAttribute) TypeSQL() string

TypeSQL renders the attribute's type with its COLLATE clause, e.g. "text" or "text COLLATE \"C\"".

type CompositeType added in v1.20.0

type CompositeType struct {
	OID        uint32                `json:"oid"`
	Schema     string                `json:"schema"`
	Name       string                `json:"name"`
	RenameFrom *string               `json:"rename_from"`
	Attributes []*CompositeAttribute `json:"attributes"`
	Comment    *string               `json:"comment"`
	// Ignore marks the composite type as unmanaged (set by -- pista:ignore).
	// Ignored objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore bool `json:"ignore"`
}

func (CompositeType) AttributeCommentSQLs added in v1.20.0

func (ct CompositeType) AttributeCommentSQLs() []string

AttributeCommentSQLs returns a COMMENT ON COLUMN statement for each attribute that carries a comment.

func (CompositeType) CommentSQL added in v1.20.0

func (ct CompositeType) CommentSQL() string

func (CompositeType) FQCN added in v1.20.0

func (ct CompositeType) FQCN() string

func (CompositeType) SQL added in v1.20.0

func (ct CompositeType) SQL() string

type Constraint

type Constraint struct {
	OID        uint32         `json:"oid"`
	Name       string         `json:"name"`
	RenameFrom *string        `json:"rename_from"`
	Type       ConstraintType `json:"type"`
	Definition string         `json:"definition"`
	Columns    []string       `json:"columns"`
	Deferrable bool           `json:"deferrable"`
	Deferred   bool           `json:"deferred"`
	Validated  bool           `json:"validated"`
	// Inherited marks a constraint a partition child holds only because its
	// parent has one. PostgreSQL refuses to alter or drop such a copy, and a
	// statement on the parent reaches it, so the diff leaves it alone. Only
	// the catalog sets it: a desired schema declares what it writes.
	Inherited bool `json:"inherited"`
	// IndexName is the index a desired constraint written
	// ADD CONSTRAINT ... USING INDEX takes over. Only the parser sets it:
	// the promotion renames the index to the constraint's name, so the
	// catalog has no such name to report. The diff keeps that index out of
	// the index drops and adds, and takes an existing constraint of the same
	// name, type and deferral as satisfying the declaration.
	IndexName string `json:"index_name"`
}

func (*Constraint) String

func (con *Constraint) String() string

type ConstraintType

type ConstraintType byte

func (ConstraintType) IsCheckConstraint

func (b ConstraintType) IsCheckConstraint() bool

func (ConstraintType) IsExclusionConstraint

func (b ConstraintType) IsExclusionConstraint() bool

func (ConstraintType) IsForeignKeyConstraint

func (b ConstraintType) IsForeignKeyConstraint() bool

func (ConstraintType) IsNotNullConstraint

func (b ConstraintType) IsNotNullConstraint() bool

func (ConstraintType) IsPrimaryKeyConstraint

func (b ConstraintType) IsPrimaryKeyConstraint() bool

func (ConstraintType) IsUniqueConstraint

func (b ConstraintType) IsUniqueConstraint() bool

func (ConstraintType) MarshalJSON added in v1.51.0

func (b ConstraintType) MarshalJSON() ([]byte, error)

MarshalJSON writes the constraint kind as a word instead of the pg_constraint character, since the JSON is read outside pistachio.

type Domain added in v0.12.0

type Domain struct {
	OID        uint32  `json:"oid"`
	Schema     string  `json:"schema"`
	Name       string  `json:"name"`
	RenameFrom *string `json:"rename_from"`
	BaseType   string  `json:"base_type"`
	NotNull    bool    `json:"not_null"`
	Default    *string `json:"default"`
	// Collation in quoted SQL form, ready to follow COLLATE
	// (e.g. `pg_catalog."C"`). nil for the default collation.
	Collation   *string             `json:"collation"`
	Constraints []*DomainConstraint `json:"constraints"`
	Comment     *string             `json:"comment"`
	// Ignore marks the domain as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore bool `json:"ignore"`
}

func (Domain) CommentSQL added in v0.12.0

func (d Domain) CommentSQL() string

func (Domain) FQDN added in v0.12.0

func (d Domain) FQDN() string

func (Domain) SQL added in v0.12.0

func (d Domain) SQL() string

type DomainConstraint added in v0.12.0

type DomainConstraint struct {
	Name       string `json:"name"`
	Definition string `json:"definition"`
	Validated  bool   `json:"validated"`
}

type Enum added in v0.9.0

type Enum struct {
	OID        uint32   `json:"oid"`
	Schema     string   `json:"schema"`
	Name       string   `json:"name"`
	RenameFrom *string  `json:"rename_from"`
	Values     []string `json:"values"`
	// ValueRenameFrom maps a desired value to the current value it renames.
	// Set by the parser from -- pista:renamed-from directives inside the
	// value list; always empty on the catalog side.
	ValueRenameFrom map[string]string `json:"value_rename_from"`
	Comment         *string           `json:"comment"`
	// Ignore marks the enum as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore bool `json:"ignore"`
}

func (Enum) CommentSQL added in v0.9.0

func (e Enum) CommentSQL() string

func (Enum) FQEN added in v0.9.0

func (e Enum) FQEN() string

func (Enum) SQL added in v0.9.0

func (e Enum) SQL() string

type ForeignKey

type ForeignKey struct {
	Constraint
	Schema    string  `json:"schema"`
	Table     string  `json:"table"`
	RefSchema *string `json:"ref_schema"`
	RefTable  *string `json:"ref_table"`
}

func (ForeignKey) SQL

func (fk ForeignKey) SQL(onPartitioned bool) string

SQL renders the ALTER TABLE that adds the key. onPartitioned says the owning table is partitioned, where PostgreSQL rejects ONLY outright; a foreign key is not inherited either way, so the word only tracks what pg_dump writes.

func (*ForeignKey) String

func (fk *ForeignKey) String() string

type IdentitySequence added in v1.40.0

type IdentitySequence struct {
	Start     int64 `json:"start"`
	Min       int64 `json:"min"`
	Max       int64 `json:"max"`
	Increment int64 `json:"increment"`
	Cache     int64 `json:"cache"`
	Cycle     bool  `json:"cycle"`
}

IdentitySequence holds the parameters of the sequence behind an identity column, the sequence_options of GENERATED ... AS IDENTITY. PostgreSQL takes the sequence data type from the column, so there is no data type here.

Both the catalog and the parser fill in every field, applying the defaults PostgreSQL derives from the column type and the increment, so the diff is a plain comparison. It is nil for a column that is not an identity column.

func DefaultIdentitySequence added in v1.40.0

func DefaultIdentitySequence(typeName string, increment int64) IdentitySequence

DefaultIdentitySequence returns the parameters PostgreSQL gives an identity column of typeName whose definition writes no option other than the increment. The increment decides the direction, and the direction decides the bounds and the start, so it has to be resolved first.

func (*IdentitySequence) Options added in v1.40.0

func (s *IdentitySequence) Options(typeName string) []string

Options returns the sequence options that differ from the defaults for a column of typeName, each as a clause such as "START WITH 100". A column left entirely at the defaults returns nothing, so the common identity column keeps its short form.

func (*IdentitySequence) OptionsSQL added in v1.40.0

func (s *IdentitySequence) OptionsSQL(typeName string) string

OptionsSQL renders Options in the parenthesized form that follows GENERATED ... AS IDENTITY, with a leading space. It returns an empty string when every option is at its default.

func (*IdentitySequence) RetypedTo added in v1.40.0

func (s *IdentitySequence) RetypedTo(oldType, newType string) *IdentitySequence

RetypedTo returns the parameters the sequence has once the column's type changes from oldType to newType. PostgreSQL moves a bound sitting at the old type's extreme to the new type's extreme, in either direction, and leaves any other bound alone; the start does not move. A diff that follows a type change reads the current side through this, or it plans a bound the retype already set.

type Index

type Index struct {
	OID          uint32  `json:"oid"`
	Schema       string  `json:"schema"`
	Name         string  `json:"name"`
	RenameFrom   *string `json:"rename_from"`
	Table        string  `json:"table"`
	Definition   string  `json:"definition"`
	TableSpace   *string `json:"table_space"`
	Concurrently bool    `json:"concurrently"`
	Comment      *string `json:"comment"`
	// Attached marks an index attached to an index on the partitioned parent.
	// PostgreSQL rejects a DROP of one and drops it with the parent's. Only the
	// catalog sets it.
	Attached bool `json:"attached"`
	// Size is the size estimate dump --explain writes in a comment above the
	// index. Only dump sets it.
	Size string `json:"-"`
}

func (Index) CommentSQL added in v1.46.0

func (idx Index) CommentSQL() string

CommentSQL renders the index's own COMMENT ON, or an empty string when it carries none. COMMENT ON INDEX names the index alone, never the relation it sits on.

func (Index) DumpSQL added in v1.58.0

func (idx Index) DumpSQL() string

DumpSQL is SQL with the size comment dump --explain puts above it.

func (Index) FQTN

func (idx Index) FQTN() string

func (Index) SQL

func (idx Index) SQL() string

type Policy added in v1.3.0

type Policy struct {
	Name       string        `json:"name"`
	RenameFrom *string       `json:"rename_from"`
	Schema     string        `json:"schema"`
	Table      string        `json:"table"`
	Permissive bool          `json:"permissive"`
	Command    PolicyCommand `json:"command"`
	Roles      []string      `json:"roles"`
	Using      *string       `json:"using"`
	WithCheck  *string       `json:"with_check"`
}

func (Policy) SQL added in v1.3.0

func (p Policy) SQL() string

SQL renders a CREATE POLICY statement.

func (*Policy) String added in v1.3.0

func (p *Policy) String() string

type PolicyCommand added in v1.3.0

type PolicyCommand byte

PolicyCommand mirrors pg_policy.polcmd:

'*' ALL, 'r' SELECT, 'a' INSERT, 'w' UPDATE, 'd' DELETE

func (PolicyCommand) IsAll added in v1.3.0

func (c PolicyCommand) IsAll() bool

func (PolicyCommand) MarshalJSON added in v1.51.0

func (c PolicyCommand) MarshalJSON() ([]byte, error)

MarshalJSON writes the command keyword instead of the pg_policy character, since the JSON is read outside pistachio.

func (PolicyCommand) String added in v1.3.0

func (c PolicyCommand) String() string

type Routine added in v1.30.0

type Routine struct {
	OID       uint32        `json:"oid"`
	Schema    string        `json:"schema"`
	Name      string        `json:"name"`
	Procedure bool          `json:"procedure"`
	Args      []*RoutineArg `json:"args"`
	// ReturnType is empty for a procedure. RETURNS TABLE is stored as "record"
	// with ReturnsSet true; the columns live in Args with mode TABLE.
	ReturnType string `json:"return_type"`
	ReturnsSet bool   `json:"returns_set"`
	Language   string `json:"language"`
	// Body is the string in the AS clause. For LANGUAGE c the AS clause names
	// two strings, and Body holds the link symbol while ObjFile holds the
	// object file.
	Body            string `json:"body"`
	ObjFile         string `json:"obj_file"`
	Volatility      string `json:"volatility"` // IMMUTABLE, STABLE or VOLATILE
	Strict          bool   `json:"strict"`
	SecurityDefiner bool   `json:"security_definer"`
	Leakproof       bool   `json:"leakproof"`
	Parallel        string `json:"parallel"` // SAFE, RESTRICTED or UNSAFE
	// Cost and Rows are nil when the routine carries the default for its
	// language, matching pg_get_functiondef, which prints neither.
	Cost   *float64         `json:"cost"`
	Rows   *float64         `json:"rows"`
	Config []*RoutineConfig `json:"config"`
	// Comment is read from pg_description on the catalog side and from
	// COMMENT ON FUNCTION / PROCEDURE on the desired side.
	Comment *string `json:"comment"`
	// Ignore marks the routine as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore bool `json:"ignore"`
}

Routine holds metadata for a PostgreSQL function or procedure (pg_proc rows with prokind 'f' or 'p'). Aggregates and window functions are not managed, and neither is a function whose body is written in the SQL-standard BEGIN ATOMIC form: such a body records real pg_depend entries on the tables it reads, which contradicts the create order pistachio uses for routines.

func (Routine) CommentSQL added in v1.30.0

func (r Routine) CommentSQL() string

func (Routine) DropSQL added in v1.30.0

func (r Routine) DropSQL() string

DropSQL returns the DROP statement for the routine.

func (Routine) FQRN added in v1.30.0

func (r Routine) FQRN() string

FQRN returns the key the diff matches routines by: the schema-qualified name with the identity argument list, in the shape pg_get_function_identity_arguments produces. Two routines in one schema can share a name, so the argument list is part of it.

A type in the routine's own schema loses that qualifier here. The catalog reports such a type bare when search_path reaches it while a desired schema may write it qualified, and without this the two spellings would key as two routines, so a plan would create one and drop the other on every run. Signature renders the types as they were read, for the SQL that has to resolve them.

func (Routine) Kind added in v1.30.0

func (r Routine) Kind() string

Kind returns the keyword the DDL for this routine uses.

func (Routine) SQL added in v1.30.0

func (r Routine) SQL() string

SQL returns the canonical CREATE statement. Both sides of the diff build a Routine through the parser and render it here, so a dump fed back as the desired schema produces the same text again.

func (Routine) Signature added in v1.30.0

func (r Routine) Signature() string

Signature returns the schema-qualified name and identity argument list with the type names as read, for a DROP or a COMMENT that PostgreSQL has to resolve under the same search_path the types were reported through.

func (Routine) String added in v1.30.0

func (r Routine) String() string

String returns a debug-friendly representation.

func (Routine) TableArgs added in v1.30.0

func (r Routine) TableArgs() []*RoutineArg

TableArgs returns the RETURNS TABLE columns, empty for any other routine.

type RoutineArg added in v1.30.0

type RoutineArg struct {
	// Mode is "", "OUT", "INOUT", "VARIADIC" or "TABLE". An empty Mode is IN.
	Mode string `json:"mode"`
	Name string `json:"name"`
	// Type carries no type modifier: PostgreSQL discards one on a parameter,
	// so keeping it would differ from what the catalog reports back.
	Type string `json:"type"`
	// Default is the deparsed default expression, empty when the parameter
	// has none.
	Default string `json:"default"`
}

RoutineArg is one entry of a routine's parameter list.

func (RoutineArg) InArg added in v1.30.0

func (a RoutineArg) InArg() bool

InArg reports whether the parameter is part of the routine's identity. PostgreSQL keys pg_proc by the IN, INOUT and VARIADIC parameter types, so those are the ones FQRN spells out.

func (RoutineArg) String added in v1.30.0

func (a RoutineArg) String() string

type RoutineConfig added in v1.30.0

type RoutineConfig struct {
	Name string   `json:"name"`
	Args []string `json:"args"`
}

RoutineConfig is one SET clause on a routine (pg_proc.proconfig).

func (RoutineConfig) SQL added in v1.30.0

func (c RoutineConfig) SQL() string

SQL renders one SET clause. PostgreSQL parses SET x TO y and SET x TO 'y' to the same value, so either spelling in the desired schema matches what the catalog reports.

type Sequence

type Sequence struct {
	OID       uint32 `json:"oid"`
	Schema    string `json:"schema"`
	Name      string `json:"name"`
	DataType  string `json:"data_type"`
	Start     int64  `json:"start"`
	Min       int64  `json:"min"`
	Max       int64  `json:"max"`
	Increment int64  `json:"increment"`
	Cache     int64  `json:"cache"`
	Cycle     bool   `json:"cycle"`
	Unlogged  bool   `json:"unlogged"`
	// OwnerTable and OwnerColumn are set from the OWNED BY relationship
	// (pg_depend deptype 'a' for serial, 'i' for identity). They are nil for
	// standalone sequences, which are the only ones the pipeline manages.
	OwnerTable  *string `json:"owner_table"`
	OwnerColumn *string `json:"owner_column"`
	RenameFrom  *string `json:"rename_from"`
	Comment     *string `json:"comment"`
	// Ignore marks the sequence as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the catalog
	// side.
	Ignore bool `json:"ignore"`
}

Sequence holds metadata for a standalone PostgreSQL sequence (one created by CREATE SEQUENCE, not the sequence auto-generated behind a serial or identity column). Sequences owned by a table column are handled as column attributes and are excluded from the sequence diff pipeline.

func (Sequence) CommentSQL added in v1.17.0

func (seq Sequence) CommentSQL() string

func (Sequence) FQN added in v1.17.0

func (seq Sequence) FQN() string

func (Sequence) Owned added in v1.17.0

func (seq Sequence) Owned() bool

Owned reports whether the sequence is owned by a table column (serial or identity). Owned sequences are not managed as standalone objects.

func (Sequence) SQL added in v1.17.0

func (seq Sequence) SQL() string

func (Sequence) String

func (seq Sequence) String() string

String returns a debug-friendly representation.

type Table

type Table struct {
	OID        uint32  `json:"oid"`
	Schema     string  `json:"schema"`
	Name       string  `json:"name"`
	RenameFrom *string `json:"rename_from"`
	BulkAlter  bool    `json:"bulk_alter"`
	// Ignore marks the table as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore     bool    `json:"ignore"`
	TableSpace *string `json:"table_space"`
	// StorageParams holds the table's storage parameters, pg_class.reloptions,
	// keyed by parameter name and ordered by it. A `toast.` prefix names a
	// parameter of the TOAST relation, which is where pg_dump writes it too.
	StorageParams    *orderedmap.Map[string, string]      `json:"storage_params"`
	Unlogged         bool                                 `json:"unlogged"`
	Partitioned      bool                                 `json:"partitioned"`
	PartitionDef     *string                              `json:"partition_def"`
	PartitionOf      *string                              `json:"partition_of"`
	PartitionBound   *string                              `json:"partition_bound"`
	RowSecurity      bool                                 `json:"row_security"`
	ForceRowSecurity bool                                 `json:"force_row_security"`
	Columns          *orderedmap.Map[string, *Column]     `json:"columns"`
	Constraints      *orderedmap.Map[string, *Constraint] `json:"constraints"`
	ForeignKeys      *orderedmap.Map[string, *ForeignKey] `json:"foreign_keys"`
	Indexes          *orderedmap.Map[string, *Index]      `json:"indexes"`
	Policies         *orderedmap.Map[string, *Policy]     `json:"policies"`
	Triggers         *orderedmap.Map[string, *Trigger]    `json:"triggers"`
	Comment          *string                              `json:"comment"`
	// Size is the size estimate dump --explain writes after the table's name
	// in the comment above its CREATE TABLE. Only dump sets it.
	Size string `json:"-"`
}

func (Table) CommentSQL

func (t Table) CommentSQL() string

func (Table) FQTN

func (t Table) FQTN() string

func (Table) FkSQL

func (t Table) FkSQL() string

FkSQL renders the table's foreign keys. A partition's copy of a key its parent declares is left out: the parent's statement creates the copy, so writing it as well gives a file that does not reload. pg_dump leaves it out the same way.

func (Table) IdxSQL

func (t Table) IdxSQL() string

func (Table) IsInheritsChild added in v1.43.0

func (t Table) IsInheritsChild() bool

IsInheritsChild reports whether the table inherits from a parent without being a partition of it, which is the case the bound separates from the one IsPartitionChild reports. Such a child declares columns and constraints of its own alongside the ones it inherits, and both sides of the diff carry the local half alone: the catalog filters on attislocal and conislocal, and a desired schema names what the child's CREATE TABLE writes.

func (Table) IsPartitionChild added in v1.34.0

func (t Table) IsPartitionChild() bool

IsPartitionChild reports whether the table is a partition of a declarative partitioned table. An INHERITS child also carries PartitionOf, but no bound, so the bound is what separates the two.

func (Table) NotValidConSQL added in v1.42.0

func (t Table) NotValidConSQL() string

NotValidConSQL renders the table's NOT VALID check constraints, each as its own ALTER TABLE after the table. ONLY is dropped on a partitioned table, which rejects it once a partition exists. A partition child renders nothing: its unvalidated entries are the clones the parent's statement creates. An INHERITS child carries only its own constraints, so it renders them the way a plain table does; writing one inline would restore it validated.

func (Table) RLSSQL added in v1.3.0

func (t Table) RLSSQL() string

func (Table) SQL

func (t Table) SQL() string

func (Table) StorageParamsSQL added in v1.36.0

func (t Table) StorageParamsSQL() string

StorageParamsSQL renders the table's storage parameters as the WITH clause of a CREATE TABLE, or "" when it holds none. Every value is quoted. PostgreSQL accepts that for any parameter, so the renderer does not have to decide which spellings pass as a bare identifier.

func (Table) StorageSQL added in v1.32.0

func (t Table) StorageSQL() string

StorageSQL renders the columns whose TOAST storage or compression is not the default. A partition child and an INHERITS child declare no columns of their own, and a partition copies both off the parent attribute as it is created, so neither is rendered.

func (Table) TrigSQL added in v1.29.0

func (t Table) TrigSQL() string

TrigSQL renders the table's triggers, each followed by the ALTER TABLE that puts it in a non-default enable state.

type Trigger added in v1.29.0

type Trigger struct {
	Schema     string  `json:"schema"`
	Table      string  `json:"table"`
	Name       string  `json:"name"`
	RenameFrom *string `json:"rename_from"`
	// Definition is the whole CREATE TRIGGER statement without its
	// terminator: what pg_get_triggerdef writes on the catalog side, and what
	// pg_query deparses on the desired side. The two renderings differ in
	// places, so the diff cannot compare this text directly; see
	// diff.equalTriggerDef.
	Definition string       `json:"definition"`
	State      TriggerState `json:"state"`
}

func (Trigger) FQTN added in v1.29.0

func (trg Trigger) FQTN() string

FQTN returns the qualified name of the table or view the trigger is on.

func (Trigger) SQL added in v1.29.0

func (trg Trigger) SQL() string

func (Trigger) StateSQL added in v1.29.0

func (trg Trigger) StateSQL() string

StateSQL renders the ALTER TABLE that leaves the trigger in a non-default state, and "" for the default one, which CREATE TRIGGER already produces.

func (*Trigger) String added in v1.29.0

func (trg *Trigger) String() string

type TriggerState added in v1.29.0

type TriggerState byte

TriggerState mirrors pg_trigger.tgenabled:

'O' fires in origin and local sessions, which is where CREATE TRIGGER
leaves a new trigger, 'D' never fires, 'R' fires in replica mode only,
and 'A' fires in every mode.
const TriggerStateDefault TriggerState = 'O'

TriggerStateDefault is the state CREATE TRIGGER leaves behind.

func (TriggerState) Action added in v1.29.0

func (s TriggerState) Action() string

Action returns the ALTER TABLE action that puts a trigger in the state.

func (TriggerState) IsDefault added in v1.29.0

func (s TriggerState) IsDefault() bool

IsDefault reports the state a bare CREATE TRIGGER produces. The zero value counts, so a trigger built without a state reads as enabled.

func (TriggerState) MarshalJSON added in v1.51.0

func (s TriggerState) MarshalJSON() ([]byte, error)

MarshalJSON writes the state as a word instead of the pg_trigger character, since the JSON is read outside pistachio.

type View

type View struct {
	OID          uint32  `json:"oid"`
	Schema       string  `json:"schema"`
	Name         string  `json:"name"`
	RenameFrom   *string `json:"rename_from"`
	Definition   string  `json:"definition"`
	Materialized bool    `json:"materialized"`
	// CheckOption is the view's WITH CHECK OPTION, "local" or "cascaded", and
	// empty when the view has none. A materialized view never has one.
	CheckOption string `json:"check_option"`
	// StorageParams holds the view's storage parameters, pg_class.reloptions,
	// keyed by parameter name and ordered by it. check_option sits in the same
	// column but is read as the view's WITH CHECK OPTION, so it is not here. A
	// plain view takes security_barrier and security_invoker, a materialized
	// view what a table takes, including a `toast.` parameter of its TOAST
	// relation.
	StorageParams *orderedmap.Map[string, string]   `json:"storage_params"`
	Indexes       *orderedmap.Map[string, *Index]   `json:"indexes"`
	Triggers      *orderedmap.Map[string, *Trigger] `json:"triggers"`
	Comment       *string                           `json:"comment"`
	// Size is the size estimate dump --explain writes after a materialized
	// view's name in the comment above it. Only dump sets it.
	Size string `json:"-"`
	// ColumnComments maps a column name to its comment. A column without a
	// comment has no entry.
	ColumnComments *orderedmap.Map[string, string] `json:"column_comments"`
	// Ignore marks the view as unmanaged (set by -- pista:ignore). Ignored
	// objects are not created, altered, or dropped; always false on the
	// catalog side.
	Ignore bool `json:"ignore"`
}

func (View) CommentSQL

func (v View) CommentSQL() string

func (View) FQVN

func (v View) FQVN() string

func (View) ObjType added in v1.45.0

func (v View) ObjType() string

ObjType returns the keyword a statement names the view with, VIEW or MATERIALIZED VIEW.

func (View) SQL

func (v View) SQL() string

func (View) TrigSQL added in v1.29.0

func (v View) TrigSQL() string

TrigSQL renders the view's INSTEAD OF triggers. PostgreSQL rejects ALTER TABLE ... DISABLE TRIGGER on a view, so there is no state to write.

Jump to

Keyboard shortcuts

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