Documentation
¶
Index ¶
- Constants
- Variables
- func CatalogType(c CatalogColumn) (schema.Type, error)
- func CreateOrAlter(definition string) (string, error)
- func DefaultSQL(c *schema.Column) (string, error)
- func FormatType(t schema.Type) (string, error)
- func ParseType(s string) (schema.Type, error)
- type CatalogColumn
- type Clustered
- type DefaultConstraint
- type Definition
- type Disabled
- type Identity
- type IndexInclude
- type IndexPredicate
- type Planner
- type Routine
- type SpecialType
- 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 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.6
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.
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 ¶
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 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 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 SpecialType ¶
SpecialType is a SQL Server type with no generic Atlas counterpart: money, smallmoney, xml, sql_variant and rowversion.
type UniqueConstraint ¶
UniqueConstraint marks a live unique index that backs a UNIQUE constraint, which is dropped with ALTER TABLE ... DROP CONSTRAINT.