Documentation
¶
Overview ¶
Package migrations provides database migration utilities built on top of golang-migrate.
Index ¶
- type Migration
- func (a *Migration) CreatePopMigration(up, down []byte, migrationName, migrationType string) error
- func (adele *Migration) MigrateDownAll(dsn string) error
- func (adele *Migration) MigrateForce(dsn string) error
- func (adele *Migration) MigrateUp(dsn string) error
- func (a *Migration) PopConnect() (*pop.Connection, error)
- func (a *Migration) PopMigrateDown(tx *pop.Connection, steps ...int) error
- func (a *Migration) PopMigrateReset(tx *pop.Connection) error
- func (a *Migration) RunPopMigrations(tx *pop.Connection) error
- func (adele *Migration) Steps(n int, dsn string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Migration ¶
func (*Migration) CreatePopMigration ¶
CreatePopMigration generates new migration files using the Pop library. It creates both up and down migration files in the RootPath/migrations directory. Parameters:
- up: the SQL or Go code to run when migrating up
- down: the SQL or Go code to run when migrating down (rollback)
- migrationName: the name for the migration (used in filename)
- migrationType: the type of migration (e.g., "sql" or "fizz")
Returns an error if the migration files cannot be created.
func (*Migration) MigrateDownAll ¶
MigrateDownAll reverts all applied migrations, rolling the database schema back to its initial state. This is useful for testing or completely resetting the database. Returns an error if the migration instance cannot be created or if any rollback fails.
func (*Migration) MigrateForce ¶
MigrateForce resets the migration version to -1 (no version) without running any migrations. This is useful for recovering from a dirty migration state where a migration failed partway through and left the database in an inconsistent state. Use with caution as it does not modify the actual database schema. Returns an error if the migration instance cannot be created or if the force operation fails.
func (*Migration) MigrateUp ¶
MigrateUp applies all available migrations to bring the database schema up to date. It reads migration files from the configured RootPath/migrations directory and connects to the database using the provided DSN (Data Source Name). Returns an error if the migration instance cannot be created or if any migration fails.
func (*Migration) PopConnect ¶
func (a *Migration) PopConnect() (*pop.Connection, error)
PopConnect establishes a database connection using the Pop library. Currently defaults to the "development" environment configuration. Returns a Pop connection instance or an error if the connection fails. TODO: Do we want to default to development? Seems to me that a env pivot is helpful.
func (*Migration) PopMigrateDown ¶
func (a *Migration) PopMigrateDown(tx *pop.Connection, steps ...int) error
PopMigrateDown reverts a specified number of migrations using the Pop library. The steps parameter is variadic; if not provided, it defaults to reverting 1 migration. If steps is provided, the first value determines how many migrations to roll back. Returns an error if the migrator cannot be created or if the rollback fails.
func (*Migration) PopMigrateReset ¶
func (a *Migration) PopMigrateReset(tx *pop.Connection) error
PopMigrateReset rolls back all migrations and then re-applies them. This effectively rebuilds the entire database schema from scratch. Useful for development and testing environments to ensure a clean state. Returns an error if the migrator cannot be created or if the reset fails.
func (*Migration) RunPopMigrations ¶
func (a *Migration) RunPopMigrations(tx *pop.Connection) error
RunPopMigrations applies all pending migrations using the Pop library. It reads migration files from RootPath/migrations and executes them in order. Requires an active Pop database connection. Returns an error if the migrator cannot be created or if any migration fails.
func (*Migration) Steps ¶
Steps applies or reverts a specific number of migrations based on the value of n. If n is positive, it applies n migrations forward. If n is negative, it reverts n migrations backward. This provides fine-grained control over migration state changes. Returns an error if the migration instance cannot be created or if any step fails.