Documentation
¶
Index ¶
- Constants
- func Exclude(path string) bool
- func Find[T any](object any, path string) T
- func QuoteIdentifier(names ...any) string
- func RegisterExcludePatterns(patterns []string) error
- func Render(name string, o any) string
- func SetupSourceAnalyze(p parser, f analyzer)
- func TruncateTask(t Table, reqs []string) dispatch.Task
- func Version(ctx context.Context) (software, version string, err error)
- type Annotable
- type Association
- func RowToCheck(r *sql.Rows) (a Association, err error)
- func RowToColumn(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)
- type Check
- type Column
- type DataType
- type ForeignKey
- type Function
- type Index
- type IndexColumn
- type Key
- type Metadata
- type Model
- func (mdl Model) AlterTablesDefaults(p dispatch.TaskAdder)
- func (mdl Model) CreateIndexes(p dispatch.TaskAdder)
- func (mdl Model) CreateRoles(p dispatch.TaskAdder)
- func (mdl Model) CreateSchemas(p dispatch.TaskAdder)
- func (mdl Model) CreateSequences(p dispatch.TaskAdder)
- func (mdl Model) CreateTables(p dispatch.TaskAdder)
- type Parameter
- type Procedure
- type Role
- type Routine
- type Schema
- type Sequence
- 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) Is(o Table) bool
- func (t Table) IsZero() bool
- func (t Table) Priority() int
- func (t Table) ReplaceColumn(n Column)
- func (t *Table) SaveStats(s Stats)
- func (t *Table) Scan(r *sql.Rows) error
- 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 ¶
This section is empty.
Functions ¶
func Exclude ¶ added in v0.26.0
Exclude returns wether 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 `<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 RegisterExcludePatterns ¶ added in v0.27.0
func SetupSourceAnalyze ¶ added in v0.15.0
func SetupSourceAnalyze(p parser, f analyzer)
func TruncateTask ¶ added in v0.20.0
TruncateTask instanciates TRUNCATE operation on a table
Types ¶
type Annotable ¶ added in v0.0.4
type Association ¶ added in v0.30.0
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 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 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
}
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
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) BuildSignature ¶ added in v0.29.0
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
}
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 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 (Model) CreateIndexes ¶ added in v0.29.0
func (Model) CreateRoles ¶ added in v0.26.0
func (Model) CreateSchemas ¶ added in v0.25.0
CreateSchemas generates CREATE SCHEMA tasks
func (Model) CreateSequences ¶ added in v0.25.0
CreateSequences generates CREATE SEQUENCE tasks
func (Model) CreateTables ¶ added in v0.25.0
CreateTables generates CREATE TABLE tasks
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) 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
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
func (Routine) MakeTrigger ¶ added in v0.0.7
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 (Sequence) BuildPath ¶ added in v0.29.0
BuildPath build canonical object path in model
Use catalog.Find() to fetch by path the object in a model struct.
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
}
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 (Table) AlterDefaults ¶ added in v0.30.0
func (Table) BuildPath ¶ added in v0.29.0
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) CreateIndex ¶ added in v0.29.0
Create generates DDL for index
func (Table) Priority ¶ added in v0.28.0
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.