Documentation
¶
Overview ¶
A very simple library that provides a way to perform SQL migrations using pgxDB.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( MalformedMigrationFileErr = errors.New("Malformed migration file") MigrationSequenceErr = errors.New("Malformed migration sequence") MissingSqlMigrationErr = errors.New( "A postOp did not have an associated sql migration file", ) UnknownMigrationErr = errors.New( "A migration requested from the database was not found", ) )
Functions ¶
func Load ¶
Loads a set of migration files from the supplied directory of the supplied embedded file system. All sql migration files are expected to have an integer for the file name and end with a sql file extension. Migration files are expected to be strictly increasing with no missing numbers.
postOps define code that will be run after the corresponding sql migration has been run, as defined by the sql file number. Post ops are not required.
An embedded file system is used to encourage all migrations to be baked into the executable so that deploying any application will not also require deploying a dir containing all the migration files.
func Run ¶
Runs all migrations that need to be run. This will run all migrations that have a status of false in the database and will run any additional migrations that have been added. All migrations will be run in the increasing order and if an error is encountered all further migrations will not be run.
All migrations will be run inside a transaction. If any migration fails the entire transaction will be rolled back, there will be no changes to the database, and any migrations that ran successfully before the failed migration will need to be re-run.
Types ¶
type Migrations ¶
type Migrations struct {
// contains filtered or unexported fields
}
func (*Migrations) Load ¶
func (m *Migrations) Load( sqlFiles embed.FS, dir string, postOps map[Migration]PostMigrationOp, ) error
Loads a set of migration files from the supplied directory of the supplied embedded file system. All sql migration files are expected to have an integer for the file name and end with a sql file extension. Migration files are expected to be strictly increasing with no missing numbers.
postOps define code that will be run after the corresponding sql migration has been run, as defined by the sql file number. Post ops are not required.
An embedded file system is used to encourage all migrations to be baked into the executable so that deploying any application will not also require deploying a dir containing all the migration files.
func (*Migrations) Run ¶
Runs all migrations that need to be run. This will run all migrations that have a status of false in the database and will run any additional migrations that have been added. All migrations will be run in the increasing order and if an error is encountered all further migrations will not be run.
All migrations will be run inside a transaction. If any migration fails the entire transaction will be rolled back, there will be no changes to the database, and any migrations that ran successfully before the failed migration will need to be re-run.
func (*Migrations) Status ¶
func (m *Migrations) Status( ctxt context.Context, p *pgxpool.Pool, ) ([]queries.SmoothbrainSqlmigrateVersioning, error)
Returns the current status of all migrations. This result will include the status of all operations that are not yet listed in the database.
type PostMigrationOp ¶
The function signature for any golang operations that should be performed after the sql migration has been executed.