migrate

package module
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 10 Imported by: 0

README

Golang migrate

Install
go get -u github.com/LineoIT/go-migrate
How to use
package main

import (
	"github.com/LineoIT/go-migrate"
	"log"
	_ "github.com/lib/pq"
)

func main() {
	m, err := migrate.New("postgres",
		"postgres://postgres:postgres@localhost/demo?sslmode=disable",
		"./migrations",
	)
	if err != nil {
		log.Fatal(err)
	}
	if err := m.Migrate(); err != nil {
		panic(err)
	}
}

Note: Do not forget import db driver github.com/lib/pq for postgres

Documentation

Index

Constants

View Source
const (
	TIME_LAYOUT = "20060102150405"
)

Variables

View Source
var ErrDirty = errors.New("migration is dirty")
View Source
var ErrNoChange = errors.New("no change")

Functions

func Create

func Create(dir, name string)

Types

type Config

type Config struct {
	Table string
}

type Migration

type Migration struct {
	*sql.DB
	Config *Config
	// contains filtered or unexported fields
}

func New

func New(driver, dsn, baseDir string) (*Migration, error)

New creates new migration

func (*Migration) Clean

func (m *Migration) Clean() error

Clean delete all migrations versions

func (*Migration) GetLastVersion

func (m *Migration) GetLastVersion() (Version, error)

GetLastVersion get last migration version

func (*Migration) GetVersions

func (m *Migration) GetVersions() ([]Version, error)

GetVersions get all migrations version

func (*Migration) Migrate

func (m *Migration) Migrate() error

* Run migrations

func (*Migration) Rollback

func (m *Migration) Rollback() error

! Rollback all migrations from database

type Version

type Version struct {
	Version int64
	IsDirty *bool
	Date    *time.Time
}

func (*Version) Create

func (v *Version) Create(m *Migration) error

func (*Version) Save

func (v *Version) Save(m *Migration) error

Jump to

Keyboard shortcuts

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