migrations

package
v0.0.0-...-e4abd6c Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: OSL-3.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMigrationVersion

func GetMigrationVersion(ctx context.Context, pool *pgxpool.Pool, migrationsPath string) (version uint, dirty bool, err error)

GetMigrationVersion returns the current migration version. ctx bounds the advisory-lock wait and the version query like RunMigrations: when it ends the migrator's connections are canceled server-side and the error matches errors.Is(err, ctx.Err()).

func MigrateToVersion

func MigrateToVersion(ctx context.Context, pool *pgxpool.Pool, migrationsPath string, version uint) error

MigrateToVersion migrates the schema up or down to exactly the given version. Unlike RunMigrations it applies no post-migration Go logic (admin seeding etc.), and unlike RollbackMigrations it targets a version rather than a step count. Migration tests use it to pin the database at the version just below the migration under test; fixed step counts from head silently drift every time a newer migration lands.

func RollbackMigrations

func RollbackMigrations(ctx context.Context, pool *pgxpool.Pool, migrationsPath string, steps int) error

RollbackMigrations rolls back N migrations.

func RunMigrations

func RunMigrations(ctx context.Context, pool *pgxpool.Pool, migrationsPath, adminEmail, adminPassword string) error

RunMigrations runs database migrations using golang-migrate adminEmail is optional - if provided, admin user will be created after migrations complete adminPassword is optional - if provided, admin is created with hashed password and active=true.

ctx bounds the schema work itself: connection setup, advisory-lock wait and the running migration SQL. When ctx ends, the migrator's connections are canceled server-side and RunMigrations returns an error matching errors.Is(err, ctx.Err()). An interrupted migration file rolls back as a whole (PostgreSQL runs each file as one implicit transaction; see TestMigrationsAreTransactional) but leaves schema_migrations dirty, which the next run reports through maybeRefuseDirty without clearing it.

func ValidateMigrationsPath

func ValidateMigrationsPath(path string) error

ValidateMigrationsPath checks if migrations directory exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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