Documentation
¶
Overview ¶
Package sqlserver is the database half of the SQL Server dialect of the schema engine: it reads capabilities, schemas and the live dependents of columns, and runs a unit on one connection. Diffing, lowering and preconditions are the pure planner it embeds.
Index ¶
- func ExportHCL(ctx context.Context, q engine.Querier, opts ExportOptions) ([]planner.HCLFile, error)
- type Dialect
- func (d Dialect) Capabilities(ctx context.Context, q engine.Querier) (engine.Capabilities, error)
- func (d Dialect) Dependents(ctx context.Context, q engine.Querier, current migrate.Schema, ...) ([]engine.Dependent, error)
- func (Dialect) Exec(ctx context.Context, q engine.Querier, s engine.Statement) error
- func (Dialect) Inspect(ctx context.Context, q engine.Querier, scope engine.Scope) (engine.Inspection, error)
- func (Dialect) Open(ctx context.Context, conn *sql.Conn, opts engine.SessionOptions) (engine.UnitSession, error)
- func (Dialect) Reconcile(_ context.Context, _ engine.Querier, current, desired migrate.Schema) (migrate.Schema, error)
- func (Dialect) SameDependent(before, after engine.Dependent) (bool, error)
- type ExportOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExportHCL ¶
func ExportHCL(ctx context.Context, q engine.Querier, opts ExportOptions) ([]planner.HCLFile, error)
ExportHCL reads the tables of one schema and writes them as SQL Server HCL that the bundle evaluator reads back to the same tables (see planner.ExportHCL). Whatever the inspector could not read of a selected table (a refused table or member) fails the export, unless HCL.OmitUnsupported turns it into a comment line at the top of the output.
Types ¶
type Dialect ¶
Dialect is registered as "sqlserver".
func (Dialect) Capabilities ¶
Capabilities probes the database. Feature keys are the BackendCapability values, so the planner's FeatureTryConvert is the key of the same name. With q == nil it answers the planner's static, offline capabilities.
func (Dialect) Dependents ¶
func (d Dialect) Dependents(ctx context.Context, q engine.Querier, current migrate.Schema, columns []engine.ColumnRef) ([]engine.Dependent, error)
Dependents lists what depends on columns. Without a database it derives the answer from current, as the pure planner does. With one it reads the catalog: everything SQL Server refuses to alter a column under, with the definition that re-creates it exactly, or a Refusal for what it cannot reproduce.
func (Dialect) Inspect ¶
func (Dialect) Inspect(ctx context.Context, q engine.Querier, scope engine.Scope) (engine.Inspection, error)
Inspect reads the schema. Complete mode reads every object of scope.Schemas. Declared mode reads exactly the scope's objects that exist, with the catalog narrowed to their names. What the native model cannot hold comes back as a refusal instead of failing the inspection, so an object nobody touches never blocks a plan.
func (Dialect) Open ¶
func (Dialect) Open(ctx context.Context, conn *sql.Conn, opts engine.SessionOptions) (engine.UnitSession, error)
Open starts one unit on its connection: the transaction when the unit has one, the application lock, SET LOCK_TIMEOUT and SET XACT_ABORT ON. A zero lock timeout means no waiting, for the application lock and for blocked statements. Finish ends the transaction, releases the lock and puts the connection's settings back, so the pooled connection is clean.
func (Dialect) Reconcile ¶
func (Dialect) Reconcile(_ context.Context, _ engine.Querier, current, desired migrate.Schema) (migrate.Schema, error)
Reconcile rewrites desired so that what it leaves unset inherits the live value and what the server compares as equal is spelled like the live value. It touches nothing else: a real difference stays one. The rules:
- a column of a character type with no collation takes the live column's collation, and a collation that differs only in case takes the live spelling.
type ExportOptions ¶
type ExportOptions struct {
Schema string
// Tables are the tables to export; empty exports every table of the schema.
Tables []string
// HCL configures the writer. DatabaseCollation is read from the database.
HCL planner.HCLOptions
}
ExportOptions select what ExportHCL reads and how it writes it.