Documentation ¶
Overview ¶
Package mig is a simple SQL migration library. You use it to embed snippets of SQL into your application which will be run on startup (or whenever you tell them to). Mig is primarily used for migrating schemas between versions of applications.
Mig is small and deliberately simple. There are no rollbacks in Mig, and it's expected that the application running Mig will have schema altering permissions on the target database.
If you want to restrict your application's rights to a database, it's best you run Mig from a different process or under a different user.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Quiet = false
Quiet will supress status output on STDOUT if true
Functions ¶
func Define ¶
func Define(script string)
Define will define and register a migration for running the next time Mig is run. A version is automatically chosen based on the sequence of previous calls to Define (aka version=len(migrations)+1).
mig.Define(` create table foo ( id integer ); `)
func DefineVersion ¶
DefineVersion will define and register a migration for running the next time Mig is run with a specific version number.
mig.DefineVersion(2, ` alter table foo add column bar varchar(10); `)
func Migrate ¶
Migrate will execute the defined migrations against the sql.DB. For each migration Mig will look in a db_version table to see if it has already been run. If there's a row in db_version for a migration it wont be run again, otherwise the migration will be run and a row stored in db_version.
If this is the first time Mig has been run, Migrate will first create a db_version table and store a zero row.
Types ¶
type MigrationError ¶
MigrationError is returned when an error occurs running one of the migrations. If the version is 0, the initial db_version table creation failed.
func (MigrationError) Error ¶
func (e MigrationError) Error() string