Documentation
¶
Overview ¶
Package migration provides an interface for migrating a database backwards and forwards.
You must store the path to the env.json file in the environment variable: JAYCONFIG
Examples:
jay migrate:mysql make "test" # Create new migration jay migrate:mysql all # Advance all migrations jay migrate:mysql reset # Rollback all migrations jay migrate:mysql refresh # Rollback all migrations then advance all migrations jay migrate:mysql status # See last 'up' migration jay migrate:mysql up # Apply only the next 'up' migration jay migrate:mysql down # Apply only the current 'down' migration jay migrate make "Create user table" Creates two new files in the database/migration folder using this format: * YYYYMMDD_HHMMSS.nnnnnn_create_user_table.up.sql * YYYYMMDD_HHMMSS.nnnnnn_create_user_table.down.sql
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNone is when there are no migrations in the database ErrNone = errors.New("No migrations yet.") // ErrCurrent is when the database is up-to-date ErrCurrent = errors.New("Database current. No changes made.") // ErrMissing is when the migration file cannot be found ErrMissing = errors.New("Migration not found.") // ErrTableNotCreated is when the migration cannot be created ErrTableNotCreated = errors.New("Could not create the migration table.") )
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { // Db is the database information Db Interface //DateFormat is the date and time format for the migration files DateFormat string // Folder is the migrations folder Folder string // List if the life of Up migrations List []string // Folder is the migrations table Table string // TemplateUp is the stub used for Up migration files when they are created TemplateUp string // TemplateDown is the stub used for Down migration files when they are created TemplateDown string // contains filtered or unexported fields }
Info holds the information for the migration.
func New ¶
New returns an instance of a migration after creating the migration table (if one doesn't exist), retrieving a list of the available migrations, and reading the last migration. You must connect to the database prior to calling this function.
func (*Info) Create ¶
Create writes two new migration files to the folder with timestamps and descriptions.
type Interface ¶
type Interface interface { // Extension should return an extension without a period or a blank string Extension() string // TableExist should return an error if the table does not exist TableExist() error // CreateTable should return an error if the table could not be created CreateTable() error // Status should return the name of the last migration or return an error // or a model.ErrNoResult error if there are no results Status() (string, error) // Migrate will run the migration and return an error if not successful Migrate(query string) error // RecordUp should record the name of the file in the database RecordUp(name string) error // RecordDown should record the name of the file in the database and make // any changes to the database like updating the AUTO_INCREMENT value RecordDown(name string) error }
Interface defines all the functions required for a migration.
Click to show internal directories.
Click to hide internal directories.