catalog

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: PostgreSQL Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const NONE = 0xdead

NONE is a special value used to indicate that the length, precision, or scale of a data type cannot be determined or is not applicable.

Variables

View Source
var RenderData = make(map[string]any)

RenderData stores global data root for all templates.

View Source
var SourceMap map[string]string = make(map[string]string)

SourceMap tracks path to source object

key is target path. value is source path. Two target objects may share the same source object. e.g. A check and text column share MySQL enum column source.

View Source
var StatsRegistry map[string]Stats = make(map[string]Stats)

StatsRegistry stores stats per source object.

Functions

func Exclude added in v0.26.0

func Exclude(ss ...string) bool

Exclude returns whether the path must be excluded from the migration.

func Find added in v0.20.0

func Find[T any](object any, path ...string) T

Find object by path

Uses reflection to browse deep object. Path is in format `<field>/<schema>.<name>(<signature>)/...`

Returns zero if not found.

func Include added in v1.0.0

func Include(ss ...string) bool

func InsertSorted added in v1.0.0

func InsertSorted[T stringer](s []T, v T) []T

InsertSorted inserts a value into a sorted slice of stringers.

func RegisterPatterns added in v1.0.0

func RegisterPatterns(inputs []string) error

func RegisterStats added in v1.0.0

func RegisterStats(path string, s Stats)

func Render added in v0.24.0

func Render(name string, o any) string

Render execute an SQL template

func SetupSourceAnalyze added in v0.15.0

func SetupSourceAnalyze(f analyzer)

func TruncateTask added in v0.20.0

func TruncateTask(t Table, reqs []string) dispatch.Task

TruncateTask instanciates TRUNCATE operation on a table

func Version added in v0.24.0

func Version(ctx context.Context) (software, version string, err error)

Version queries PostgreSQL server name and version

Types

type Association added in v0.30.0

type Association struct {
	Schema      string
	Object      string // name of table, view, materialized view, etc.
	CompType    string // partition, index, etc.
	CompName    string // name of component: e.g. partition name, index name
	SubType     string // subpartition, to associate columns to subpartitions.
	SubName     string // subpartition name
	FinalObject any    // The object to associate: column, table (for partition), constraint, etc.
}

Association holds a component and references to parent object.

Use it to scan components like columns, stats, partitions, etc.

See Associate method and fetch.CollectAndAssociateContext.

func RowToCheck added in v0.0.4

func RowToCheck(r *sql.Rows) (a Association, err error)

func RowToColumn added in v0.30.0

func RowToColumn(r *sql.Rows) (a Association, err error)

func RowToColumnExtended added in v1.0.0

func RowToColumnExtended(r *sql.Rows, extra ...any) (a Association, err error)

func RowToComponentStats added in v1.0.0

func RowToComponentStats(r *sql.Rows) (a Association, err error)

RowToComponentStats scan stats for association

Accept variadic queries with:

- schema - object - component type: e.g. column, partition - component name - values...

func RowToForeignKey added in v0.30.0

func RowToForeignKey(r *sql.Rows) (a Association, err error)

func RowToIdentity added in v0.25.0

func RowToIdentity(r *sql.Rows) (a Association, err error)

func RowToIndex added in v0.0.4

func RowToIndex(r *sql.Rows) (a Association, err error)

func RowToIndexColumn added in v0.30.0

func RowToIndexColumn(r *sql.Rows) (a Association, err error)

func RowToKey added in v0.30.0

func RowToKey(r *sql.Rows) (a Association, err error)

func RowToParameter added in v0.30.0

func RowToParameter(rows *sql.Rows) (a Association, err error)

func RowToStats added in v0.29.0

func RowToStats(r *sql.Rows) (a Association, err error)

RowToStats scan stats for association

Accept variadic queries with:

- schema - object - values...

func RowToSubComponentStats added in v1.0.0

func RowToSubComponentStats(r *sql.Rows) (a Association, err error)

RowToSubComponentStats scan stats for association

Accept variadic queries with:

- schema - object - component type: e.g. column, partition, index - component name - subcomponent type: e.g. partition, index - subcomponent name - values...

func RowToTrigger added in v0.0.8

func RowToTrigger(r *sql.Rows) (a Association, err error)

func (Association) Match added in v0.30.0

func (a Association) Match(s ...string) bool

Match parent object

Use to test whether the component should be appended to an object.

e.g. a.Match(t.Schema, t.Name, p.Name)

func (Association) String added in v0.30.2

func (a Association) String() string

type Catalog added in v1.0.0

type Catalog struct {
	Name       string
	Metadata   Metadata
	Roles      []Role
	Schemas    []Schema
	Sequences  []Sequence
	Tables     []Table
	Views      []View
	Procedures []Procedure
	Functions  []Function
	Servers    []Server
	Jobs       []Job
	audit.Annotable
	InitialAnnotations map[string][]string
}

func (Catalog) After added in v1.0.0

func (ctg Catalog) After(v string) bool

func (Catalog) Before added in v1.0.0

func (ctg Catalog) Before(v string) bool

func (Catalog) Exclude added in v1.0.0

func (ctg Catalog) Exclude(path string) bool

func (Catalog) SemVer added in v1.2.0

func (ctg Catalog) SemVer() string

SemVer computes a semver from actual version

Useful to compare version using semver package.

func (Catalog) Size added in v1.0.0

func (ctg Catalog) Size() int

func (Catalog) Target added in v1.0.0

func (ctg Catalog) Target() bool

type Check added in v0.0.4

type Check struct {
	Name          string
	GeneratedName bool
	Expression    string
	audit.Annotable
}

func (Check) BuildPath added in v0.29.0

func (c Check) BuildPath(tail ...string) string

func (Check) Create added in v1.0.0

func (c Check) Create(t Table) string

func (Check) String added in v0.0.4

func (c Check) String() string

type Column

type Column struct {
	Name       string
	Comment    string
	Type       DataType
	Nullable   bool
	Expression string // Default or virtual column expression
	Generated  string
	Identity   Identity       `json:",omitzero"`
	Ext        map[string]any `json:",omitempty"`
	audit.Annotable
}

func (Column) BuildPath added in v0.29.0

func (c Column) BuildPath(tail ...string) string

BuildPath returns column's catalog path relative to Annotable

Use table.BuildPath(c.BuildPath()) to get absolute path.

func (Column) Default

func (c Column) Default() string

Default determine default expression

func (Column) LOB added in v0.28.0

func (c Column) LOB() bool

func (Column) String

func (c Column) String() string

type DataType added in v0.23.0

type DataType struct {
	Name    string
	Params  []string `json:",omitempty"` // Whatever between parens: precision, scale, length, enum values, etc.
	Options string   `json:",omitempty"` // Additional options like "UNSIGNED", "WITH TIME ZONE", etc.
}

DataType stores extracted type information

Can represent: - a concrete type as found in database. - a match or conversion rule.

A rule may have wildcards or placeholders like `numeric(p)` or `enum(...)`. When converting, wildcard substitutes placeholder with value from input. See [Convert].

func MustParseType added in v0.25.0

func MustParseType(typ string) DataType

func ParseType added in v0.23.0

func ParseType(typ string) (DataType, error)

func (DataType) Convert added in v0.27.0

func (t DataType) Convert(in DataType) DataType

Convert applies conversion rules to a data type.

Essentially substitutes placeholders in the rule with values from the input.

Returns zero on parameters mismatch.

func (DataType) IsZero added in v0.24.0

func (t DataType) IsZero() bool

func (DataType) Match added in v0.27.0

func (t DataType) Match(in DataType) bool

Match checks if the target data type matches the rule.

A match is successful if: - The names are the same. - The number of parameters is the same, or the rule has a params placeholder "...". - The options are the same.

func (DataType) Precedence added in v0.27.0

func (t DataType) Precedence() int

Precedence of a data type.

Higher precedence means the rule is more specific.

func (DataType) Precision added in v0.23.0

func (t DataType) Precision() int

Precision returns the precision of the data type or NONE.

func (DataType) Scale added in v0.23.0

func (t DataType) Scale() int

Scale returns the scale of the data type or NONE.

func (DataType) String added in v0.23.0

func (t DataType) String() string

func (DataType) Values added in v0.23.0

func (t DataType) Values() []string

Values returns the values of an enum/set type.

type ForeignKey added in v0.0.4

type ForeignKey struct {
	Name               string
	GeneratedName      bool
	Columns            []string
	ForeignTableSchema string
	ForeignTableName   string
	ForeignColumns     []string
	Match              string // FULL, PARTIAL, SIMPLE
	OnUpdate           string // CASCADE, RESTRICT, NO ACTION, SET NULL, SET DEFAULT
	OnDelete           string // CASCADE, RESTRICT, NO ACTION, SET NULL, SET DEFAULT
	Deferrable         bool
	InitiallyDeferred  bool
	audit.Annotable
}

func (ForeignKey) BuildPath added in v0.29.0

func (fk ForeignKey) BuildPath(tail ...string) string

func (ForeignKey) Create added in v1.0.0

func (fk ForeignKey) Create(t Table) string

func (ForeignKey) ForeignPath added in v0.29.0

func (fk ForeignKey) ForeignPath(tail ...string) string

func (ForeignKey) String added in v0.0.4

func (fk ForeignKey) String() string

type Function added in v0.0.7

type Function struct {
	Schema     string `json:",omitempty"`
	Name       string
	Owner      string `json:",omitempty"`
	Signature  string // Comma separated list of parameter types.
	Parameters []Parameter
	Returns    DataType
	Source     Source
	audit.Annotable
}

func (Function) BuildPath added in v0.29.0

func (f Function) BuildPath(tail ...string) string

func (Function) BuildSignature added in v0.29.0

func (f Function) BuildSignature() string

func (Function) Is added in v0.19.0

func (f Function) Is(o Routine) bool

func (Function) String added in v0.0.7

func (f Function) String() string

type Identity added in v0.25.0

type Identity struct {
	Increment int
	Min       int
	Max       *big.Int
	Start     int64
	Cache     int
	Cycle     bool
}

Identity holds serial number generator metadata

Used by identity column and sequence.

func (Identity) IsDefault added in v1.0.0

func (id Identity) IsDefault() bool

IsDefault determines whether CREATE TABLE should use the default sequence options.

Start is ignored, as it is not part of the sequence definition but handled with data.

func (Identity) IsZero added in v1.0.0

func (id Identity) IsZero() bool

type Index

type Index struct {
	Name          string
	GeneratedName bool
	Uniqueness    bool
	Type          string
	Columns       []IndexColumn
	Include       []string
	NullsDistinct bool
	StorageParams map[string]string
	Tablespace    string
	Where         string
	Comment       string
	Invisible     bool
	audit.Annotable
}

func (Index) Associate added in v0.0.4

func (idx Index) Associate(a Association) (Index, bool)

func (Index) BuildPath added in v0.29.0

func (idx Index) BuildPath(tail ...string) string

BuildPath build canonical object path in catalog

Use catalog.Find() to fetch by path the object in a Catalog struct.

For a index, the path is of form `Indexes/<table>`. Append tail items as path segments.

func (Index) String

func (idx Index) String() string

type IndexColumn added in v0.0.4

type IndexColumn struct {
	Name              string
	Expression        string
	Collation         string
	OpClass           string
	OpClassParameters map[string]string
	Descending        bool
	NullsFirst        bool
	audit.Annotable
}

func (IndexColumn) BuildPath added in v0.29.0

func (c IndexColumn) BuildPath() string

BuildPath returns column path relative to index or table.

Get absolute path using idx.BuildPath(c.BuildPath())

func (IndexColumn) String added in v1.0.0

func (c IndexColumn) String() string

type Job added in v1.0.0

type Job struct {
	Schema   string
	Name     string
	Owner    string
	Active   bool
	Command  Source
	Schedule string         `json:",omitempty"`
	Last     time.Time      `json:",omitzero"`
	Ext      map[string]any `json:",omitempty"`
	audit.Annotable
}

func (*Job) BuildPath added in v1.0.0

func (j *Job) BuildPath(tail ...string) string

func (Job) String added in v1.0.0

func (j Job) String() string

type Key

type Key struct {
	Name          string
	GeneratedName bool
	Comment       string
	Columns       []string
	Primary       bool
	Unique        bool
	audit.Annotable
}

func (Key) BuildPath added in v0.29.0

func (k Key) BuildPath(tail ...string) string

func (Key) Create added in v1.0.0

func (k Key) Create(t Table) string

func (Key) String

func (k Key) String() string

type Metadata

type Metadata struct {
	Software  string
	Version   string
	Username  string
	Timestamp time.Time
	Ext       map[string]any
}

Metadata describe migration source

type Namespace added in v1.0.0

type Namespace map[string]bool

Namespace holds an identifier namespace

e.g. for relation name (pg_class.relname), constraints on a table, etc.

func (Namespace) Generate added in v1.0.0

func (ns Namespace) Generate(name1, name2, label string) string

Generate a unique identifier in namespace

Accepts empty name2.

Registers identifier in namespace for future calls to Generate.

func (Namespace) Register added in v1.0.0

func (ns Namespace) Register(nn ...string) bool

Register an identifier in namespace

Returns whether the identifier is new in namespace.

type Parameter added in v0.19.0

type Parameter struct {
	Name string
	Type DataType
	Mode string
}

func (*Parameter) String added in v0.19.0

func (p *Parameter) String() string

type Procedure added in v0.0.7

type Procedure struct {
	Schema     string `json:",omitempty"`
	Name       string
	Owner      string `json:",omitempty"`
	Signature  string // Comma separated list of parameter types.
	Parameters []Parameter
	Source     Source
	audit.Annotable
}

func (Procedure) BuildPath added in v0.29.0

func (p Procedure) BuildPath(tail ...string) string

func (Procedure) BuildSignature added in v0.29.0

func (p Procedure) BuildSignature() string

func (Procedure) Is added in v0.19.0

func (p Procedure) Is(o Routine) bool

func (Procedure) String added in v0.0.7

func (p Procedure) String() string

type Role added in v0.26.0

type Role struct {
	Name  string
	Login bool
	Super bool
	Ext   map[string]any `json:",omitempty"`
	audit.Annotable
}

func (Role) BuildPath added in v0.29.0

func (r Role) BuildPath(tail ...string) string

func (Role) Create added in v0.26.0

func (r Role) Create() string

func (Role) Drop added in v0.26.0

func (r Role) Drop() string

func (*Role) Scan added in v0.26.0

func (r *Role) Scan(rw *sql.Rows) error

func (Role) String added in v0.26.0

func (r Role) String() string

type Routine added in v0.0.7

type Routine struct {
	Schema     string
	Name       string
	Owner      string
	Type       string
	Parameters []Parameter
	Returns    DataType
	Source     Source
}

Routine holds a generic database routine.

Use Routine to scan all procedures, functions, etc. from a single query.

func RowToRoutine added in v0.0.7

func RowToRoutine(rows *sql.Rows) (r Routine, err error)

func (Routine) Associate added in v0.19.0

func (r Routine) Associate(a Association) (Routine, bool)

func (Routine) MakeFunction added in v0.0.7

func (r Routine) MakeFunction() Function

func (Routine) MakeProcedure added in v0.0.7

func (r Routine) MakeProcedure() Procedure

func (*Routine) Scan added in v0.0.7

func (r *Routine) Scan(rows *sql.Rows) error

type Schema

type Schema struct {
	Name     string
	Owner    string
	Comment  string
	Triggers []Trigger `json:",omitempty" `
	audit.Annotable
}

func RowToSchema

func RowToSchema(r *sql.Rows) (Schema, error)

func (Schema) Associate added in v1.0.0

func (s Schema) Associate(a Association) (Schema, bool)

func (Schema) BuildPath added in v0.29.0

func (s Schema) BuildPath(tail ...string) string

func (Schema) Create added in v0.20.0

func (s Schema) Create() string

func (Schema) Drop added in v0.24.0

func (s Schema) Drop() string

func (Schema) Format added in v1.0.0

func (s Schema) Format(f fmt.State, _ rune)

func (Schema) IsZero added in v1.0.0

func (s Schema) IsZero() bool

func (*Schema) Scan

func (s *Schema) Scan(r *sql.Rows) error

func (Schema) String

func (s Schema) String() string

type Sequence added in v0.0.7

type Sequence struct {
	Schema string
	Name   string
	Owner  string
	Identity
	audit.Annotable
}

Sequence holds a named number generator.

func RowToSequence added in v0.0.7

func RowToSequence(r *sql.Rows) (s Sequence, err error)

func (Sequence) BuildPath added in v0.29.0

func (s Sequence) BuildPath(tail ...string) string

BuildPath build canonical object path in catalog

Use catalog.Find() to fetch by path the object in a Catalog struct.

func (Sequence) Create added in v0.25.0

func (s Sequence) Create() string

func (*Sequence) Scan added in v0.0.7

func (s *Sequence) Scan(r *sql.Rows) error

func (Sequence) String added in v0.0.7

func (s Sequence) String() string

type Server added in v1.0.0

type Server struct {
	Name               string
	Type               string
	Version            string
	ForeignDataWrapper string
	Options            map[string]string
	audit.Annotable
}

func (Server) BuildPath added in v1.0.0

func (s Server) BuildPath(tail ...string) string

func (Server) String added in v1.0.0

func (s Server) String() string

type Source added in v0.15.0

type Source struct {
	Code        string
	Lines       int
	Hints       int
	DDL         int
	Dynamic     int
	Exception   int
	Pragma      int
	Transaction int
	SystemAPI   int
	Unparsed    int
}

func (*Source) Analyze added in v0.15.0

func (s *Source) Analyze(o annotater) (ast.Node, float32)

Analyze parses source code.

func (Source) IsZero added in v0.18.0

func (s Source) IsZero() bool

type Stats added in v0.29.0

type Stats map[string]any

Stats holds size and row count of a object.

func (Stats) Int added in v1.0.0

func (s Stats) Int(k string) int

func (Stats) Rows added in v0.29.0

func (s Stats) Rows() int

func (Stats) Size added in v0.29.0

func (s Stats) Size() int

func (Stats) String added in v0.29.0

func (s Stats) String() string

type Table

type Table struct {
	Schema          string `json:",omitempty"`
	Name            string
	Owner           string `json:",omitempty"`
	Temporary       bool
	Comment         string
	Columns         []Column
	Keys            []Key
	ForeignKeys     []ForeignKey
	Checks          []Check
	Triggers        []Trigger
	PartitionBy     string // LIST, RANGE, HASH, etc.
	PartitionKey    string // column names
	Partitions      []Table
	PartitionBounds string // DEFAULT, FROM, TO, etc.
	Indexes         []Index
	Ext             map[string]any `json:",omitempty"`
	audit.Annotable
	// contains filtered or unexported fields
}

func (Table) AlterDefaults added in v0.30.0

func (t Table) AlterDefaults() string

func (Table) Associate added in v0.0.3

func (t Table) Associate(a Association) (Table, bool)

func (Table) BuildPath added in v0.29.0

func (t Table) BuildPath(tail ...string) string

BuildPath build canonical object path in catalog

Use catalog.Find() to fetch by path the object in a Catalog struct.

For a table, the path is of form `Tables/<schema>.<table>`. Append tail items as path segments.

e.g.: parent.BuildPath(partition.BuildPath()).

func (Table) Column added in v0.0.4

func (t Table) Column(name string) Column

func (Table) Create added in v0.20.0

func (t Table) Create() string

func (Table) CreateIndex added in v0.29.0

func (t Table) CreateIndex(idx Index) string

Create generates DDL for index

func (Table) Drop added in v1.0.0

func (t Table) Drop() string

func (Table) ExpressionColumns added in v1.0.0

func (t Table) ExpressionColumns(objectpath string, expr string) []string

func (Table) HasIdentity added in v1.0.0

func (t Table) HasIdentity() bool

func (Table) Is

func (t Table) Is(o Table) bool

func (Table) IsZero added in v0.20.0

func (t Table) IsZero() bool

func (Table) Priority added in v0.28.0

func (t Table) Priority() int

Priority compute table processing order

Combine total size and average row size to priorize big table and big rows. Requires full StatsRegistry.

To use for create, truncate, copy and other table tasks.

func (Table) Reference added in v1.0.0

func (t Table) Reference(n string, ctg any) (fc Column)

Reference return foreign column from local column

Returns zero value if not found.

func (Table) ReplaceColumn added in v0.28.0

func (t Table) ReplaceColumn(n Column)

func (*Table) SaveStats added in v0.30.0

func (t *Table) SaveStats(s Stats)

func (Table) String

func (t Table) String() string

type Trigger added in v0.0.7

type Trigger struct {
	Name   string
	Owner  string `json:",omitempty"`
	Timing string // BEFORE, AFTER, INSTEAD OF
	Event  string // INSERT, UPDATE, DELETE, TRUNCATE, etc.
	Source Source
	audit.Annotable
}

func (Trigger) BuildPath added in v0.29.0

func (t Trigger) BuildPath(tail ...string) string

func (Trigger) String added in v0.0.7

func (t Trigger) String() string

type Type added in v0.0.5

type Type struct {
	Schema string `json:",omitempty"`
	Name   string
	Owner  string `json:",omitempty"`
	Source string
	audit.Annotable
}

func (Type) String added in v0.0.5

func (t Type) String() string

type View added in v0.0.4

type View struct {
	Schema      string
	Name        string
	Owner       string
	Comment     string
	Updatable   bool
	Query       Source
	Columns     []string
	Options     map[string]string
	CheckOption string // "LOCAL" ou "CASCADED"
	Triggers    []Trigger
	audit.Annotable
}

func RowToView added in v0.0.4

func RowToView(r *sql.Rows) (v View, err error)

func (View) Associate added in v1.0.0

func (v View) Associate(a Association) (View, bool)

func (View) BuildPath added in v0.29.0

func (v View) BuildPath(tail ...string) string

func (*View) Scan added in v0.0.4

func (v *View) Scan(r *sql.Rows) error

func (View) String added in v0.0.4

func (v View) String() string

Jump to

Keyboard shortcuts

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