lint

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lint analyzes SQL migrations for destructive or risky changes.

It parses each migration's up SQL with internal/parse and walks the resulting statement nodes, emitting Findings for patterns that can lose data, take heavy locks, or otherwise fail on a populated production database. The linter is database-free: it operates purely on the parse tree and never connects to or executes against a server.

Index

Constants

View Source
const (
	RuleParseError       = "parse-error"
	RuleDestructiveDrop  = "destructive-drop"
	RuleDestructiveTrunc = "destructive-truncate"
	RuleColumnTypeChange = "column-type-change"
	RuleNotNullNoDefault = "not-null-no-default"
	RuleIndexNotConcurr  = "index-not-concurrent"
	RuleMissingDown      = "missing-down"
)

Rule identifiers. These are stable strings suitable for allow-listing.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finding

type Finding struct {
	Version  string // migration version ("" for cross-file findings)
	Rule     string // stable rule id, e.g. "destructive-drop"
	Severity Severity
	Message  string
}

Finding is a single lint result tied to a migration version.

func Lint

func Lint(migs []migrate.Migration) []Finding

Lint analyzes migrations (parsing each UpSQL) and returns findings in migration order. It never panics: a parse failure yields a parse-error finding and statements it does not recognize are ignored.

type Severity

type Severity string

Severity is the seriousness of a Finding.

const (
	// SeverityError marks a change that loses data or is otherwise unsafe; it
	// should block a migration unless explicitly overridden.
	SeverityError Severity = "error"
	// SeverityWarning marks a change that is risky (e.g. takes a lock) but not
	// inherently destructive.
	SeverityWarning Severity = "warning"
)

Jump to

Keyboard shortcuts

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