Documentation
¶
Index ¶
- func GetMigrationVersion(ctx context.Context, pool *pgxpool.Pool, migrationsPath string) (uint, bool, error)
- func MigrateToVersion(ctx context.Context, pool *pgxpool.Pool, migrationsPath string, version uint) error
- func RollbackMigrations(ctx context.Context, pool *pgxpool.Pool, migrationsPath string, steps int) error
- func RunMigrations(ctx context.Context, pool *pgxpool.Pool, ...) error
- func ValidateMigrationsPath(path string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMigrationVersion ¶
func GetMigrationVersion(ctx context.Context, pool *pgxpool.Pool, migrationsPath string) (uint, bool, error)
GetMigrationVersion returns the current migration version.
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 rolls back (every migration is transactional) but leaves schema_migrations dirty, which the next run reports through maybeAutoHealDirty.
func ValidateMigrationsPath ¶
ValidateMigrationsPath checks if migrations directory exists.
Types ¶
This section is empty.