Documentation
¶
Index ¶
- Constants
- Variables
- func Exclude(ss ...string) bool
- func Find[T any](object any, path ...string) T
- func Include(ss ...string) bool
- func InsertSorted[T stringer](s []T, v T) []T
- func RegisterPatterns(inputs []string) error
- func RegisterStats(path string, s Stats)
- func Render(name string, o any) string
- func SetupSourceAnalyze(f analyzer)
- func TruncateTask(t Table, reqs []string) dispatch.Task
- func Version(ctx context.Context) (software, version string, err error)
- type Association
- func RowToCheck(r *sql.Rows) (a Association, err error)
- func RowToColumn(r *sql.Rows) (a Association, err error)
- func RowToColumnExtended(r *sql.Rows, extra ...any) (a Association, err error)
- func RowToComponentStats(r *sql.Rows) (a Association, err error)
- func RowToForeignKey(r *sql.Rows) (a Association, err error)
- func RowToIdentity(r *sql.Rows) (a Association, err error)
- func RowToIndex(r *sql.Rows) (a Association, err error)
- func RowToIndexColumn(r *sql.Rows) (a Association, err error)
- func RowToKey(r *sql.Rows) (a Association, err error)
- func RowToParameter(rows *sql.Rows) (a Association, err error)
- func RowToStats(r *sql.Rows) (a Association, err error)
- func RowToSubComponentStats(r *sql.Rows) (a Association, err error)
- func RowToTrigger(r *sql.Rows) (a Association, err error)
- type Catalog
- type Check
- type Column
- type DataType
- type ForeignKey
- type Function
- type Identity
- type Index
- type IndexColumn
- type Job
- type Key
- type Metadata
- type Namespace
- type Parameter
- type Procedure
- type Role
- type Routine
- type Schema
- func (s Schema) Associate(a Association) (Schema, bool)
- func (s Schema) BuildPath(tail ...string) string
- func (s Schema) Create() string
- func (s Schema) Drop() string
- func (s Schema) Format(f fmt.State, _ rune)
- func (s Schema) IsZero() bool
- func (s *Schema) Scan(r *sql.Rows) error
- func (s Schema) String() string
- type Sequence
- type Server
- type Source
- type Stats
- type Table
- func (t Table) AlterDefaults() string
- func (t Table) Associate(a Association) (Table, bool)
- func (t Table) BuildPath(tail ...string) string
- func (t Table) Column(name string) Column
- func (t Table) Create() string
- func (t Table) CreateIndex(idx Index) string
- func (t Table) Drop() string
- func (t Table) ExpressionColumns(objectpath string, expr string) []string
- func (t Table) HasIdentity() bool
- func (t Table) Is(o Table) bool
- func (t Table) IsZero() bool
- func (t Table) Priority() int
- func (t Table) Reference(n string, ctg any) (fc Column)
- func (t Table) ReplaceColumn(n Column)
- func (t *Table) SaveStats(s Stats)
- func (t Table) String() string
- type Trigger
- type Type
- type View
Constants ¶
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 ¶
var RenderData = make(map[string]any)
RenderData stores global data root for all templates.
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.
StatsRegistry stores stats per source object.
Functions ¶
func Exclude ¶ added in v0.26.0
Exclude returns whether the path must be excluded from the migration.
func Find ¶ added in v0.20.0
Find object by path
Uses reflection to browse deep object. Path is in format `<field>/<schema>.<name>(<signature>)/...`
Returns zero if not found.
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 RegisterStats ¶ added in v1.0.0
func SetupSourceAnalyze ¶ added in v0.15.0
func SetupSourceAnalyze(f analyzer)
func TruncateTask ¶ added in v0.20.0
TruncateTask instanciates TRUNCATE operation on a table
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 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
}
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
}
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 (DataType) Convert ¶ added in v0.27.0
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) Match ¶ added in v0.27.0
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
Precedence of a data type.
Higher precedence means the rule is more specific.
func (DataType) Precision ¶ added in v0.23.0
Precision returns the precision of the data type or NONE.
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) BuildSignature ¶ added in v0.29.0
type Identity ¶ added in v0.25.0
Identity holds serial number generator metadata
Used by identity column and sequence.
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
}
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 Key ¶
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
Namespace holds an identifier namespace
e.g. for relation name (pg_class.relname), constraints on a table, etc.
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) BuildSignature ¶ added in v0.29.0
type Role ¶ added in v0.26.0
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 (Routine) Associate ¶ added in v0.19.0
func (r Routine) Associate(a Association) (Routine, bool)
func (Routine) MakeFunction ¶ added in v0.0.7
func (Routine) MakeProcedure ¶ added in v0.0.7
type Schema ¶
type Sequence ¶ added in v0.0.7
Sequence holds a named number generator.
type Server ¶ added in v1.0.0
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
}
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 (Table) BuildPath ¶ added in v0.29.0
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) CreateIndex ¶ added in v0.29.0
Create generates DDL for index
func (Table) ExpressionColumns ¶ added in v1.0.0
func (Table) HasIdentity ¶ added in v1.0.0
func (Table) Priority ¶ added in v0.28.0
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
Reference return foreign column from local column
Returns zero value if not found.