Documentation
¶
Index ¶
- Constants
- Variables
- func CatalogType(c CatalogColumn) (schema.Type, error)
- func CollationChanged(from, to *schema.Column) bool
- func CreateOrAlter(definition string) (string, error)
- func DefaultSQL(c *schema.Column) (string, error)
- func FormatType(t schema.Type) (string, error)
- func IndexDefinitionChanged(from, to []schema.Attr) bool
- func ParseType(s string) (schema.Type, error)
- func QualifyDefinition(definition, schema string) (string, error)
- func RowGUIDChanged(from, to *schema.Column) bool
- type CatalogColumn
- type Clustered
- type DefaultConstraint
- type Definition
- type Disabled
- type FillFactor
- type Identity
- type IndexInclude
- type IndexPredicate
- type Planner
- type QuotedIdentifierOff
- type Routine
- type RowGUID
- type Sequence
- type SpecialType
- type TableType
- type TableTypePrimaryKey
- type TableTypeRef
- type UniqueConstraint
Constants ¶
const Dialect = "tsql"
Dialect is the sqlglot dialect the driver parses T-SQL with.
Variables ¶
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{}}
DefaultDiff provides basic diffing capabilities for SQL Server. A Driver opened on a connection exposes the same Differ.
var DefaultPlan = Planner{}
DefaultPlan generates SQL Server migration statements without a database connection.
Functions ¶
func CatalogType ¶
func CatalogType(c CatalogColumn) (schema.Type, error)
func CollationChanged ¶ added in v1.1.0
CollationChanged reports an explicit collation change between two columns.
func CreateOrAlter ¶
CreateOrAlter rewrites a CREATE PROCEDURE|FUNCTION definition to CREATE OR ALTER, splicing the two words in after the CREATE keyword so every other byte of the definition -- comments, layout, literals -- is kept.
func DefaultSQL ¶ added in v1.0.5
DefaultSQL is the SQL text of a column default. An HCL string literal arrives unquoted and is quoted for the column's type, N'...' for the Unicode types; numbers and raw sql() expressions are written as they are.
func FormatType ¶
FormatType writes a schema.Type in its canonical T-SQL spelling, so two spellings of one type format the same.
func IndexDefinitionChanged ¶ added in v1.1.0
IndexDefinitionChanged reports index attribute changes other than fill factor, which a rebuild applies in place.
func ParseType ¶
ParseType reads a declared T-SQL data type (`nvarchar(max)`, `decimal(18,2)`) through sqlglot into its schema.Type.
func QualifyDefinition ¶ added in v1.1.0
QualifyDefinition prefixes an unqualified module name -- and a trigger's unqualified ON target -- with schema. SQL Server creates an unqualified module in the executing login's default schema, so a replayed definition must name the schema the catalog placed it in. Every other byte is kept.
func RowGUIDChanged ¶ added in v1.1.0
RowGUIDChanged reports a ROWGUIDCOL property change between two columns.
Types ¶
type CatalogColumn ¶
CatalogType maps a catalog column to its schema.Type from the raw sys.columns widths: bytes for string and binary types (halved for the n-types), -1 for (max), precision and scale for decimals and floats, and the fractional-second digits as the scale of time types.
type DefaultConstraint ¶
type DefaultConstraint struct {
schema.Attr
Name string
// SystemNamed marks a name SQL Server generated; it is not compared,
// and a new default for it is created unnamed.
SystemNamed bool
}
DefaultConstraint names the constraint holding a column default. The inspector sets it from the catalog; the planner names new defaults DF_<table>_<column>.
type Definition ¶
Definition is the T-SQL text a routine is created from: the declared .sql batch for a desired routine, sys.sql_modules.definition for a live one. The differ compares definitions by their sqlglot canonical form, and the planner executes a declared definition as written.
type FillFactor ¶ added in v1.1.0
FillFactor is an index's FILLFACTOR percentage, 1-99. Its absence is the server default (0, equivalent to 100).
type IndexInclude ¶
IndexInclude lists the non-key columns an index INCLUDEs.
type IndexPredicate ¶
IndexPredicate is a filtered index's WHERE clause.
type Planner ¶
type Planner struct{}
Planner generates SQL for schema changes without a database connection.
func (Planner) PlanChanges ¶
func (Planner) PlanChanges(_ context.Context, name string, changes []schema.Change, opts ...migrate.PlanOption) (*migrate.Plan, error)
PlanChanges returns a migration plan for the given schema changes. Each statement is its own change, so a routine definition runs as its own batch. The statements stay valid at compatibility level 100.
type QuotedIdentifierOff ¶ added in v1.1.0
QuotedIdentifierOff marks a module created under SET QUOTED_IDENTIFIER OFF.
type Routine ¶
type Routine struct {
// Kind is PROCEDURE or FUNCTION.
Kind string
// Schema is the schema the definition names, empty when unqualified.
Schema string
Name string
// Text is the definition as written.
Text string
// contains filtered or unexported fields
}
Routine is one CREATE PROCEDURE or CREATE FUNCTION read from its definition.
func ParseRoutine ¶
ParseRoutine parses a single CREATE [OR ALTER] PROCEDURE|FUNCTION batch. A batch holding anything else, or more than one statement, is an error.
type Sequence ¶ added in v1.1.0
type Sequence struct {
schema.Object
Schema *schema.Schema
Name, Type, Start, Increment, Minimum string
Maximum string
Cycle, NoCache bool
CacheSize int64
}
Sequence is a CREATE SEQUENCE schema object. Bounds are exact decimal strings; CacheSize 0 with NoCache false is the server default cache.
type SpecialType ¶
SpecialType is a SQL Server type with no generic Atlas counterpart: money, smallmoney, xml, sql_variant and rowversion.
type TableType ¶ added in v1.1.0
type TableType struct {
schema.Object
Schema *schema.Schema
Name string
Columns []*schema.Column
Keys []*schema.Index
Checks []string
}
TableType is a CREATE TYPE ... AS TABLE schema object. Its defaults, keys and checks are unnamed: SQL Server names a table type's constraints itself.
type TableTypePrimaryKey ¶ added in v1.1.0
TableTypePrimaryKey marks the key of a table type that is its PRIMARY KEY; the others are UNIQUE.
type TableTypeRef ¶ added in v1.1.0
TableTypeRef is a routine parameter typed by a user-defined table type.
type UniqueConstraint ¶
UniqueConstraint marks a live unique index that backs a UNIQUE constraint, which is dropped with ALTER TABLE ... DROP CONSTRAINT.