catalog

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: PostgreSQL Imports: 24 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

This section is empty.

Functions

func Exclude added in v0.26.0

func Exclude(path string) bool

Exclude returns wether 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 `<schema>/<field>/<name>/...`

Schema can be `-` to match any schema. Bare `name` means `-/Schemas/name`.

Returns zero if not found.

func QuoteIdentifier added in v0.25.0

func QuoteIdentifier(names ...any) string

func RegisterExcludePatterns added in v0.27.0

func RegisterExcludePatterns(patterns []string) error

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(p parser, 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 Annotable added in v0.0.4

type Annotable struct {
	Score       float32
	Annotations []string
	ObjectPath  string `json:"objectPath"`
	ObjectType  string `json:"objectType"`
}

func (*Annotable) Annotate added in v0.0.4

func (a *Annotable) Annotate(annotation string, score float32)

Annotate append an annotation and increment score

Use empty string to simply increase score.

type Association added in v0.30.0

type Association struct {
	Schema, Parent, SubType, SubParent string
	Component                          any
}

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 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)

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 Check added in v0.0.4

type Check struct {
	Name       string
	Expression string
	Annotable
}

func (Check) BuildPath added in v0.29.0

func (c Check) BuildPath() 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
	Default   string
	Generated string
	Identity  Sequence       `json:",omitzero"`
	Ext       map[string]any `json:",omitempty"`
	Annotable
}

func (Column) BuildPath added in v0.29.0

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

BuildPath returns column's model path relative to Annotable

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

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
	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
	Annotable
}

func (ForeignKey) BuildPath added in v0.29.0

func (fk ForeignKey) BuildPath() 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
	Signature  string // Comma separated list of parameter types.
	Parameters []Parameter
	Returns    DataType
	Source     Source
	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 Index

type Index struct {
	Name          string
	Uniqueness    bool
	Type          string
	Columns       []IndexColumn
	Include       []string
	NullsDistinct bool
	StorageParams map[string]string
	Tablespace    string
	Where         string
	Comment       string
	Invisible     bool
	Size          int
	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 model

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

For a index, the path is of form `<schema>/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
	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())

type Key

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

func (Key) BuildPath added in v0.29.0

func (k Key) BuildPath() 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 Model added in v0.25.0

type Model struct {
	Name       string
	Size       int
	Metadata   Metadata
	Roles      []Role
	Schemas    []Schema
	Sequences  []Sequence
	Tables     []Table
	Views      []View
	Indexes    []Index
	Procedures []Procedure
	Functions  []Function
	Triggers   []Trigger
	Annotable
}

func (Model) AlterTablesDefaults added in v0.30.0

func (mdl Model) AlterTablesDefaults(p dispatch.TaskAdder)

func (Model) CreateIndexes added in v0.29.0

func (mdl Model) CreateIndexes(p dispatch.TaskAdder)

func (Model) CreateRoles added in v0.26.0

func (mdl Model) CreateRoles(p dispatch.TaskAdder)

func (Model) CreateSchemas added in v0.25.0

func (mdl Model) CreateSchemas(p dispatch.TaskAdder)

CreateSchemas generates CREATE SCHEMA tasks

func (Model) CreateSequences added in v0.25.0

func (mdl Model) CreateSequences(p dispatch.TaskAdder)

CreateSequences generates CREATE SEQUENCE tasks

func (Model) CreateTables added in v0.25.0

func (mdl Model) CreateTables(p dispatch.TaskAdder)

CreateTables generates CREATE TABLE tasks

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
	Signature  string // Comma separated list of parameter types.
	Parameters []Parameter
	Source     Source
	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"`
	Annotable
}

func RowToRole added in v0.26.0

func RowToRole(rw *sql.Rows) (r Role, err error)

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
	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) MakeTrigger added in v0.0.7

func (r Routine) MakeTrigger() Trigger

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
	Annotable
}

func RowToSchema

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

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) 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 `json:",omitempty"`
	Name      string `json:",omitempty"`
	Increment int
	Min       int
	Max       *big.Int
	Start     int64
	Cache     int
	Cycle     bool
	Annotable
}

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 model

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

func (Sequence) Create added in v0.25.0

func (s Sequence) Create() string

func (Sequence) IsDefault added in v0.25.0

func (s Sequence) 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 (Sequence) IsZero added in v0.25.0

func (s Sequence) IsZero() bool

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 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
}

func (*Source) Analyze added in v0.15.0

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

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 struct {
	Size int
	Rows int
	Ext  map[string]any `json:",omitempty"`
}

Stats holds size and row count of a object.

func (Stats) String added in v0.29.0

func (s Stats) String() string

type Table

type Table struct {
	Schema          string `json:",omitempty"`
	Name            string
	Temporary       bool
	Duration        string
	Comment         string
	Columns         []Column
	Keys            []Key
	ForeignKeys     []ForeignKey
	Checks          []Check
	PartitionBy     string // LIST, RANGE, HASH, etc.
	PartitionKey    string // column names
	Partitions      []Table
	PartitionBounds string // DEFAULT, FROM, TO, etc.
	Indexes         []Index
	Size            int
	Rows            int
	Ext             map[string]any `json:",omitempty"`
	Annotable
}

func RowToTable

func RowToTable(r *sql.Rows) (t Table, err error)

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 model

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

For a table, the path is of form `<schema>/Tables/<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) 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

Use average row size to estimate task priority. Biggers rows first. Note that Oracle allocates by segment, not by row. Thus tiny tables may have high priority.

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

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) Scan

func (t *Table) Scan(r *sql.Rows) error

func (Table) String

func (t Table) String() string

type Trigger added in v0.0.7

type Trigger struct {
	Schema      string
	Name        string
	Source      Source
	Event       string
	Timing      string
	TableSchema string
	TableName   string
	Annotable
}

func RowToTrigger added in v0.0.8

func RowToTrigger(r *sql.Rows) (t Trigger, err error)

func (Trigger) BuildPath added in v0.29.0

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

func (*Trigger) Scan added in v0.0.8

func (t *Trigger) Scan(r *sql.Rows) error

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
	Source string
	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
	Comment     string
	Query       Source
	Columns     []string
	Options     map[string]string
	CheckOption string // "LOCAL" ou "CASCADED"
	Annotable
}

func RowToView added in v0.0.4

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

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