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
- Variables
- func Add(c *cli.Context, name string) error
- func ComputeDefinitions(f fs.FS) (*graph.Graph, error)
- func Down(c *cli.Context, cfg types.Config, dryRun bool) error
- func Execute(ctx context.Context, db database.DB, logger loggr.Logger, ...) error
- func ExportGraph(w io.Writer, cfg types.Config) error
- func GenerateConfigFile(...) ([]byte, error)
- func Init(c *cli.Context) (err error)
- func Up(c *cli.Context, cfg types.Config, dryRun bool) error
Constants ¶
const FilePerm = 0644
FilePerm is the standard permission for migration files (readable by all, writable by owner)
Variables ¶
var ErrMigrationsDirNotExist = errors.New("migrations directory does not exist")
ErrMigrationsDirNotExist is returned when the migrations directory doesn't exist
Functions ¶
func Add ¶
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
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 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
Types ¶
This section is empty.