sqlserver

package
v0.1.102 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Execute a reviewed SQL Server artifact

This package applies and renders a sqlglot-go engine.Artifact (version 2) planned for the sqlserver dialect. Importing it registers that dialect with the engine. Request, Result, Outcome and Apply are the engine's own ApplyRequest, Result, Outcome and Apply.

Plan with engine.PlanLive (or database/migrate.PlanSchema for a bundle) in sqlglot-go, review the artifact, then apply it:

result, err := sqlserver.Apply(ctx, db, sqlserver.Request{
    Artifact: artifact,
    Hash: reviewedHash,
    Acknowledgements: engine.Acknowledgements(artifact),
    LockTimeout: 30 * time.Second,
})

Hash must match the artifact reviewed by the caller, and Acknowledgements must contain each destructive change ID exactly once; a missing, unknown or duplicate ID fails before any connection is opened. LockTimeout is bounded to SQL Server's nonnegative millisecond range; zero makes one attempt without waiting. A forced rebuild is never acknowledged on its own: its cause is.

The artifact is split into units, each a connected set of changes. Every unit runs on its own connection under the migration application lock, in one transaction, and the engine inspects the unit's objects again before it commits, so a unit that did not reach its desired state is rolled back. A unit that already matches its desired state is skipped, which makes applying the same artifact again resume after the first failure. Earlier units stay committed and are reported. Result.Units lists each unit's Outcome and the statements it ran. The result distinguishes applied, already-applied, failed and commit-unknown; a commit error must be reconciled by inspecting the target (engine.Check reports each unit applied or pending, and fails a unit that matches neither state with DriftError) before another decision.

The fixed application-lock resource commons-db/migrate/schema serializes artifacts across different hashes and scopes within a database. Every cooperating migration runner must use this resource. Out-of-band schema writers must be quiesced during deployment. The application owns target identity, permissions, artifact storage and immutable attempt records.

Post-deployment scripts

RenderScript(artifact, ScriptOptions{Acknowledgements: ids}) renders the same reviewed artifact as one self-contained, re-runnable T-SQL batch for tools that run scripts rather than call Apply (for example a PostDeployment_* script). It validates the artifact exactly as Apply does and requires each destructive change acknowledged once, then emits one transaction per unit under the same commons-db/migrate/schema application lock, so a direct run and a script run serialise. Each unit gets a state guard evaluated before any step runs, and the script contains no GO line. See the sqlglot-go migrate/ARTIFACTS.md for the guard table.

An artifact of an earlier format (version 1, with a request and a plan) is refused: plan again.

Run the artifact seam spec with gavel test ./compatibility/database; it plans a table offline and renders it without a database. The engine's own execution suites live in sqlglot-go (migrate/engine, database/migrate/dialect/sqlserver) and run against a disposable SQL Server there.

Documentation

Overview

Package sqlserver executes reviewed SQL Server migration artifacts through the sqlglot-go engine. It registers the SQL Server dialect, so an engine.Artifact planned for "sqlserver" can be applied or rendered.

Index

Constants

View Source
const AlreadyApplied = engine.AlreadyApplied
View Source
const Applied = engine.Applied
View Source
const CommitUnknown = engine.CommitUnknown
View Source
const Failed = engine.Failed

Variables

View Source
var Apply = engine.Apply
View Source
var RenderScript = planner.RenderScript

Functions

This section is empty.

Types

type Outcome

type Outcome = engine.Outcome

type Request

type Request = engine.ApplyRequest

type Result

type Result = engine.Result

type ScriptOptions added in v0.1.74

type ScriptOptions = planner.ScriptOptions

Jump to

Keyboard shortcuts

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