Documentation ¶
Overview ¶
Package sqlcheck provides interfaces for analyzing the contents of SQL files to generate insights on the safety of many kinds of changes to database schemas. With this package developers may define an Analyzer that can be used to diagnose the impact of SQL statements on the target database. For instance, The `destructive` package exposes an Analyzer that detects destructive changes to the database schema, such as the dropping of tables or columns.
Index ¶
- func Code(code string) string
- func Register(name string, f func(*schemahcl.Resource) ([]Analyzer, error))
- type Analyzer
- type AnalyzerFunc
- type Analyzers
- type Change
- type Diagnostic
- type File
- type NamedAnalyzer
- type Options
- type Pass
- type Report
- type ReportWriter
- type ReportWriterFunc
- type ResourceSpan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analyzer ¶
type Analyzer interface { // Analyze executes the analysis function. Analyze(context.Context, *Pass) error }
An Analyzer describes a migration file analyzer.
type AnalyzerFunc ¶ added in v0.5.0
AnalyzerFunc allows using ordinary functions as analyzers.
type Change ¶
type Change struct { schema.Changes // The actual changes. Stmt *migrate.Stmt // The SQL statement generated this change. }
A Change in a migration file.
type Diagnostic ¶
type Diagnostic struct { Pos int // Diagnostic position. Text string // Diagnostic text. Code string // Code describes the check. For example, DS101 }
A Diagnostic is a text associated with a specific position of a statement in a file.
type File ¶
type File struct { migrate.File // Changes represents the list of changes this file represents. Changes []*Change // Sum represents a summary of changes this file represents. For example, // in case of a file that contains exactly two statements, and the first // statement is reverted by the one after it, the Sum is nil. Sum schema.Changes // A Parser that may be used for parsing this file. It sets to any as the contract // between checks and their parsers can vary. For example, in case of running checks // from CLI, the injected parser can be found in cmd/atlas/internal/sqlparse.Parser. Parser any // contains filtered or unexported fields }
File represents a parsed version of a migration file.
func (*File) ColumnSpan ¶ added in v0.4.3
ColumnSpan returns the span information for the column.
func (*File) SchemaSpan ¶ added in v0.4.3
func (f *File) SchemaSpan(s *schema.Schema) ResourceSpan
SchemaSpan returns the span information for the schema.
type NamedAnalyzer ¶ added in v0.6.5
type NamedAnalyzer interface { Analyzer // Name of the analyzer. Identifies the analyzer // in configuration and linting passes. Name() string }
A NamedAnalyzer describes an Analyzer that has a name.
type Options ¶ added in v0.6.2
type Options struct { // Error indicates if an analyzer should // error in case a Diagnostic was found. Error *bool `spec:"error"` // Allow drivers to extend the configuration. schemahcl.DefaultExtension }
Options defines a generic configuration options for analyzers.
type Pass ¶
type Pass struct { // A migration file and the changes it describes. File *File // Dev is a driver-specific environment used to execute analysis work. Dev *sqlclient.Client // Report reports analysis reports. Reporter ReportWriter }
A Pass provides information to the Run function that applies a specific analyzer to an SQL file.
type Report ¶ added in v0.4.3
type Report struct { Text string // Report text. Diagnostics []Diagnostic // Report diagnostics. }
A Report describes an analysis report with an optional specific diagnostic.
type ReportWriter ¶ added in v0.4.3
type ReportWriter interface {
WriteReport(Report)
}
ReportWriter represents a writer for analysis reports.
type ReportWriterFunc ¶ added in v0.4.3
type ReportWriterFunc func(Report)
ReportWriterFunc is a function that implements Reporter.
func (ReportWriterFunc) WriteReport ¶ added in v0.4.3
func (f ReportWriterFunc) WriteReport(r Report)
WriteReport calls f(r).
type ResourceSpan ¶ added in v0.4.3
type ResourceSpan uint
ResourceSpan describes the lifespan of a resource in perspective to the migration file.
const ( // SpanUnknown describes unknown lifespan. // e.g. resource may exist before this file. SpanUnknown ResourceSpan = iota // SpanAdded describes that a span of // a resource was started in this file. SpanAdded // SpanDropped describes that a span of // a resource was ended in this file. SpanDropped // SpanTemporary indicates that a resource lifetime // was started and ended in this file (CREATE and DROP). SpanTemporary = SpanAdded | SpanDropped )