migrationlint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package migrationlint enforces the SQL conventions every migration source must follow, so the OSS set and any downstream set are held to the same contract. Two rule families:

  • Schema-agnostic: no schema-qualified identifiers, no CREATE SCHEMA, no SET search_path. The runtime schema is set via the migrator's SchemaName/search_path, so migration SQL must stay unqualified.
  • Single-transaction atomicity: no CONCURRENTLY, no explicit transaction control, no other statement Postgres refuses to run inside a transaction block. The migrator applies each file as one implicit transaction; the orchestrator's failure-restore relies on a failed file rolling back its DDL rather than half-applying.

Each migration set runs Check against its own embedded FS from a test:

func TestMigrationsLint(t *testing.T) {
    violations, err := migrationlint.Check(myMigrations, "migrations")
    if err != nil {
        t.Fatal(err)
    }
    for _, v := range violations {
        t.Errorf("%s", v)
    }
}

The rules mirror the contract documented in the OSS migrations README.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Violation

type Violation struct {
	// File is the path within the linted FS.
	File string
	// Line is the 1-based line number of the match.
	Line int
	// Match is the substring that tripped the rule.
	Match string
	// Message explains why the pattern is rejected.
	Message string
}

Violation is a single rejected line in a migration file.

func Check

func Check(files fs.FS, dir string) ([]Violation, error)

Check walks every `*.sql` file under dir in files and returns one Violation per rejected line. A nil/empty slice means the set is clean. The returned error is non-nil only on an FS walk/read failure, not on lint violations.

func (Violation) String

func (v Violation) String() string

String renders a violation as `file:line — message (matched: x)` so a test failure points the author straight at the offending line.

Jump to

Keyboard shortcuts

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