migration

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package migration provides helpers for detecting and preprocessing SQL migration files produced by common migration tools (goose, dbmate, golang-migrate). The output is always plain up-only DDL that the schema parser can consume without modification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preprocess

func Preprocess(path string, contents []byte, format Format) []byte

Preprocess returns the up-only DDL for the file. For FormatPlain or FormatGolangMigrate (up files), the contents are returned unchanged. For FormatAuto, Detect is run first. The returned slice is always a fresh allocation so callers may modify it freely.

func SkipFile

func SkipFile(path string, format Format) bool

SkipFile reports whether the file should be skipped entirely (i.e. not even parsed) for the given format. When format is FormatAuto, detection is performed on the path alone (contents not needed for this check).

Types

type Format

type Format string

Format identifies the migration file format.

const (
	// FormatPlain means the file contains raw DDL with no migration markers.
	// Preprocess returns the contents unchanged.
	FormatPlain Format = "plain"
	// FormatGoose means the file uses goose-style markers
	// (-- +goose Up / -- +goose Down / -- +goose StatementBegin/End).
	FormatGoose Format = "goose"
	// FormatDBMate means the file uses dbmate-style markers
	// (-- migrate:up / -- migrate:down).
	FormatDBMate Format = "dbmate"
	// FormatGolangMigrate means the file is part of a golang-migrate pair:
	// *.up.sql holds the up DDL; *.down.sql should be skipped entirely.
	FormatGolangMigrate Format = "golang-migrate"
	// FormatAuto instructs Detect to infer the format from file path and
	// contents. It is the default when no format is configured.
	FormatAuto Format = "auto"
)

func Detect

func Detect(path string, contents []byte) Format

Detect inspects the file path and contents and returns the detected format. It is used when Format is FormatAuto (or empty string treated as auto).

Jump to

Keyboard shortcuts

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