migration

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package migration provides functionality for creating, managing, and executing database migrations. It handles the lifecycle of migrations including creation, dependency resolution, and execution in both up and down directions.

The package supports:

  • Creating new migration files with proper structure
  • Managing migration dependencies through parent-child relationships
  • Executing migrations in dependency order
  • Rolling back migrations safely
  • Tracking applied migrations in the database

Index

Constants

View Source
const FilePerm = 0644

FilePerm is the standard permission for migration files (readable by all, writable by owner)

Variables

View Source
var ErrMigrationsDirNotExist = errors.New("migrations directory does not exist")

ErrMigrationsDirNotExist is returned when the migrations directory doesn't exist

Functions

func Add

func Add(c *cli.Context, name string) error

Add creates a new directory with stub migration files in the given schema and returns the names of the newly created files. If there was an error, the filesystem is rolled-back.

func ComputeDefinitions added in v0.0.5

func ComputeDefinitions(f fs.FS) (*graph.Graph, error)

ComputeDefinitions builds a directed acyclic graph (DAG) from migration definitions. It scans the provided filesystem for migration directories, creates vertices for each migration, and establishes parent-child relationships between them. The resulting graph enables proper migration ordering and dependency resolution.

The function expects directories to be timestamp-prefixed following Kat's convention. It returns the constructed graph and any errors encountered during graph construction.

func Down

func Down(c *cli.Context, cfg types.Config, dryRun bool) error

func Execute added in v0.0.6

func Execute(ctx context.Context, db database.DB, logger loggr.Logger, definitions *graph.Graph, cfg types.Config, count int, op types.MigrationOperationType, dryRun bool) error

func ExportGraph added in v0.0.6

func ExportGraph(w io.Writer, cfg types.Config) error

func GenerateConfigFile

func GenerateConfigFile(tableName, directory, databaseURL, dbUser, dbPassword, dbName, dbPort, dbHost, dbSSLMode string) ([]byte, error)

GenerateConfigFile creates a configuration file from the init.tmpl template using the provided parameters

func Init

func Init(c *cli.Context) (err error)

Init initializes a project for use with kat.

func Up

func Up(c *cli.Context, cfg types.Config, dryRun bool) error

Up is the command that runs the up migration operation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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