gormgrate

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2020 License: MIT Imports: 2 Imported by: 0

README

gormgrate

Managed manual migrations for GORM

Usage

gormgrate provides a MigrationFile interface. Each of your migrations must satisfy this interface.

type MigrationFile interface {
	Up(*gorm.DB) error
	Down(*gorm.DB) error
	Name() string
}

You can find an example migration in this repo at examples/migration_example.go.

Once you've created a migration, you use gormgate in your project like so (it's assumed you already have db initialized):

files := map[string]gormgrate.MigrationFile{
    "example": NewExampleMigration(),
}
migrator, err := gormgrate.NewMigrator(db, true, files)
if err != nil {
    log.Fatal(err)
}

err = migrator.RunMigrations()
if err != nil {
	log.Fatal(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	gorm.Model

	Name       string `gorm:"type:varchar(100);unique_index"`
	Successful bool
}

Migration a migration

type MigrationFile

type MigrationFile interface {
	Up(*gorm.DB) error
	Down(*gorm.DB) error
	Name() string
}

MigrationFile a migration file

type Migrator

type Migrator struct {
	DB         *gorm.DB
	Migrations []Migration
	MigrateUp  bool
	Files      []MigrationFile
}

Migrator migrates

func NewMigrator

func NewMigrator(db *gorm.DB, up bool, files []MigrationFile) (*Migrator, error)

NewMigrator returns a new Migrator

func (*Migrator) RunMigrations

func (mig *Migrator) RunMigrations() error

RunMigrations runs all our migrations (if they haven't been run successfully)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL