snapshot

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 2 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

Complete migration snapshots

snapshot.Inspect(ctx, db, snapshot.Options{Schemas: []string{"dbo"}}) reads full SQL Server migration definitions without the row or definition limits used by the interactive explorer. Schemas are explicit. The connection must have database VIEW DEFINITION permission so hidden metadata cannot look like absent objects.

Inspection reuses the shared SQL Server catalogue reader for tables, columns, indexes, keys, checks and routines. It also reads column collations, view and trigger definitions, trigger state and module dependencies. The result uses sqlglot's native migration model; this package does not generate or execute migrations.

The current contract targets SQL Server 2016 or newer, including databases at compatibility level 100. Unsupported computed or user-defined columns, storage settings, indexed views, disabled or untrusted constraints, unsupported module session settings, and external or unresolved dependencies cause explicit errors. This prevents a partial catalogue from becoming a destructive desired state.

Default, check or column expressions that depend on other database objects are also blocked: the native table model does not yet carry those dependencies for ordering and selection validation.

Options.Objects narrows an inspection to named tables, views, routines, triggers, sequences and table types, with the name filter pushed into each catalogue query. Options.CollectRefusals turns what the model cannot hold into Result.Refusals instead of an error: a whole-object refusal (an unsupported table, module or object type) leaves the object out of the schema, and a member refusal (a disabled index, an untrusted key or check) leaves it in and names the member. In that mode the result is checked by diffing the schema against itself, so a foreign key may reference a table that was not read.

Trigger schemas come from sys.objects, while parent and disabled state come from sys.triggers.

go test ./inspect/sql/snapshot -count=1

The tests separate pure catalogue projection from database-driver boundary checks. Live SQL Server execution remains a separate integration gate.

Documentation

Overview

Package snapshot inspects SQL Server schemas for migration planning, whole or narrowed to named objects. Query bounds used by the interactive explorer never apply to these snapshots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Schemas []string
	// Task, when set, reports each catalog read as progress.
	Task *task.Task
	// Objects narrows the inspection to these tables, views, routines,
	// triggers, sequences and table types, read with name filters; each must be
	// in a schema of Schemas. An object that does not exist is not in the
	// result. Empty reads every object of Schemas.
	Objects []migrate.Name
	// CollectRefusals reports what the native model cannot hold in
	// Result.Refusals instead of failing the inspection: a whole-object refusal
	// leaves the object out of Schema, a member refusal leaves it in.
	CollectRefusals bool
}

type Querier

type Querier interface {
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}

Querier is implemented by a database, pinned connection or transaction.

type Refusal added in v1.3.8

type Refusal struct {
	Object migrate.Name
	Member string
	Reason string
}

Refusal names an object, or one member of it, that the snapshot cannot model faithfully. An empty Member refuses the whole object, which the snapshot then leaves out; a member refusal leaves the object in and says which part of it a plan must not touch.

type Result

type Result struct {
	Schema  migrate.Schema
	Schemas []string
	// Warnings names each definition whose body is not understood. The snapshot
	// still holds it, as written.
	Warnings []string
	// Refusals is set only with Options.CollectRefusals.
	Refusals []Refusal
}

func Inspect

func Inspect(ctx context.Context, db Querier, options Options) (Result, error)

Jump to

Keyboard shortcuts

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