Documentation ¶
Overview ¶
Package migrations manages the state of the Catena database. SQL files should be added to this directory that implement DDL commands that update the schema of the database that Catena is connected to. The SQL files are then compiled into the binary using the catena makemigrations command along with go generate. The catena server and command can compare the state of the database with its expected state and run any migrations that are required.
Index ¶
- func Migrate(r int64, conn *sql.DB) (n int, err error)
- func New(name, dir string) (path string, err error)
- func Num() int
- func Refresh(conn *sql.DB) (err error)
- type ByRevision
- type Migration
- func (m *Migration) DBSync() bool
- func (m *Migration) Down(conn *sql.DB) (err error)
- func (m *Migration) DownSQL() string
- func (m *Migration) Filename() string
- func (m *Migration) Predecessors() (n int)
- func (m *Migration) String() string
- func (m *Migration) Successors() (n int)
- func (m *Migration) Up(conn *sql.DB) (err error)
- func (m *Migration) UpSQL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate the database to the specified revision, if the revision is negative, then apply all unapplied migrations to the database. If the revision is less than the current revision, then the database is rolled back to that state. This function cannot drop the migrations table, use the Delete() function to completely rollback all migrations and delete the migrations table. Returns the total number of migrations that were executed against the database.
Types ¶
type ByRevision ¶
type ByRevision []Migration
ByRevision implements sort.Interface for []Migration based on the Revision field.
func (ByRevision) Len ¶
func (a ByRevision) Len() int
func (ByRevision) Less ¶
func (a ByRevision) Less(i, j int) bool
func (ByRevision) Swap ¶
func (a ByRevision) Swap(i, j int)
type Migration ¶
type Migration struct { Revision int64 // the unique id of the migration, prefix from the migration file Name string // the human readable name of the migration, suffix of migration file Active bool // if the migration has been applied or not Applied time.Time // the timestamp the migration was applied Created time.Time // the timestamp the migration was created in the database // contains filtered or unexported fields }
Migration combines the information about the state of the database and how it has been migrated from the migrations table alongside the migration code stored in SQL files and compiled into the binary using go generate.
func Parse ¶
Parse a migration file into an unsynchronized migration struct. This function is only used by go generate and though it can help users diagnose migration parsing issues, is generally not useful outside of the package.
func (*Migration) Predecessors ¶
Predecessors returns the number of migrations before this migration.
func (*Migration) Successors ¶
Successors returns the number of migrations after this migration.