sqlserver

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const Dialect = "tsql"

Dialect is the sqlglot dialect the driver parses T-SQL with.

Variables

View Source
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.

View Source
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

func CollationChanged(from, to *schema.Column) bool

CollationChanged reports an explicit collation change between two columns.

func CreateOrAlter

func CreateOrAlter(definition string) (string, error)

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

func DefaultSQL(c *schema.Column) (string, error)

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

func FormatType(t schema.Type) (string, error)

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

func IndexDefinitionChanged(from, to []schema.Attr) bool

IndexDefinitionChanged reports index attribute changes other than fill factor, which a rebuild applies in place.

func ParseType

func ParseType(s string) (schema.Type, error)

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

func QualifyDefinition(definition, schema string) (string, error)

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

func RowGUIDChanged(from, to *schema.Column) bool

RowGUIDChanged reports a ROWGUIDCOL property change between two columns.

Types

type CatalogColumn

type CatalogColumn struct {
	Name      string
	DataType  string
	MaxLength *int
	Precision *int
	Scale     *int
}

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 Clustered

type Clustered struct {
	schema.Attr
}

Clustered marks a clustered index or primary key. Its absence means nonclustered.

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

type Definition struct {
	schema.Attr
	Text string
}

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 Disabled

type Disabled struct {
	schema.Attr
}

type FillFactor added in v1.1.0

type FillFactor struct {
	schema.Attr
	Percent int
}

FillFactor is an index's FILLFACTOR percentage, 1-99. Its absence is the server default (0, equivalent to 100).

type Identity

type Identity struct {
	schema.Attr
	Seed, Increment int64
}

Identity is an IDENTITY(seed, increment) column.

type IndexInclude

type IndexInclude struct {
	schema.Attr
	Columns []string
}

IndexInclude lists the non-key columns an index INCLUDEs.

type IndexPredicate

type IndexPredicate struct {
	schema.Attr
	P string
	// contains filtered or unexported fields
}

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

type QuotedIdentifierOff struct {
	schema.Attr
}

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

func ParseRoutine(definition string) (*Routine, error)

ParseRoutine parses a single CREATE [OR ALTER] PROCEDURE|FUNCTION batch. A batch holding anything else, or more than one statement, is an error.

func (*Routine) AddTo

func (r *Routine) AddTo(s *schema.Schema) error

AddTo adds the routine to s as a schema.Proc or schema.Func carrying its Definition. A routine qualified with another schema is an error.

type RowGUID added in v1.1.0

type RowGUID struct {
	schema.Attr
}

RowGUID marks the table's ROWGUIDCOL column.

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

type SpecialType struct {
	schema.Type
	T string
}

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.

func FindTableType added in v1.1.0

func FindTableType(s *schema.Schema, qualified string) *TableType

FindTableType resolves a [schema.]name parameter type to a table type declared in s, matching names case-insensitively as the catalog does.

type TableTypePrimaryKey added in v1.1.0

type TableTypePrimaryKey struct {
	schema.Attr
}

TableTypePrimaryKey marks the key of a table type that is its PRIMARY KEY; the others are UNIQUE.

type TableTypeRef added in v1.1.0

type TableTypeRef struct {
	schema.Type
	T *TableType
}

TableTypeRef is a routine parameter typed by a user-defined table type.

type UniqueConstraint

type UniqueConstraint struct {
	schema.Attr
}

UniqueConstraint marks a live unique index that backs a UNIQUE constraint, which is dropped with ALTER TABLE ... DROP CONSTRAINT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL