gooseparser

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gooseparser parses Goose-format SQL migration files into forward and backward SQL strings for use in RunSQL migration operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractDescription

func ExtractDescription(filename string) string

ExtractDescription strips the leading numeric prefix and file extension from a Goose migration filename, returning just the description part. For example, "20240101120000_initial.sql" returns "initial".

func ExtractVersionID

func ExtractVersionID(filename string) (int64, error)

ExtractVersionID parses the numeric prefix from a Goose migration filename as an int64. This matches the version_id stored in goose_db_version. For example, "00001_initial.sql" returns 1.

Types

type Migration

type Migration struct {
	// ForwardSQL is the SQL from the -- +goose Up section.
	ForwardSQL string
	// BackwardSQL is the SQL from the -- +goose Down section.
	// Empty if no Down section is present.
	BackwardSQL string
}

Migration holds the parsed content of a Goose SQL migration file.

func ParseFile

func ParseFile(path string) (Migration, error)

ParseFile reads a Goose-format .sql file and returns the parsed Migration. Goose markers (-- +goose Up, -- +goose Down, -- +goose StatementBegin, -- +goose StatementEnd) are stripped; all other content is preserved.

Jump to

Keyboard shortcuts

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