migration

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 6 Imported by: 1

README

migration

GoDoc Test Go Report Card codecov Gitter chat

Database Migration utility for Golang.

Example

package main

import (
    "context"

    "github.com/go-rel/doc/examples/db/migrations"
    "github.com/go-rel/mysql"
    "github.com/go-rel/rel"
    "github.com/go-rel/rel/migrator"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    var (
        ctx  = context.TODO()
        repo = rel.New(mysql.MustOpen("root@(source:3306)/rel_test?charset=utf8&parseTime=True&loc=Local"))
        m    = migrator.New(repo)
    )

    // Register migrations
    m.Register(20202806225100, migrations.MigrateCreateTodos, migrations.RollbackCreateTodos)

    // Run migrations
    m.Migrate(ctx)
    // OR:
    // m.Rollback(ctx)
}

More Info: https://go-rel.github.io/migration

License

Released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	// contains filtered or unexported fields
}

Migration utility that handles migration logic.

func New

func New(repo rel.Repository) Migration

New migration manager.

func (*Migration) Instrumentation

func (m *Migration) Instrumentation(instrumenter rel.Instrumenter)

Instrumentation function.

func (*Migration) Migrate

func (m *Migration) Migrate(ctx context.Context)

Migrate to the latest schema version.

func (*Migration) Register

func (m *Migration) Register(v int, up func(schema *rel.Schema), down func(schema *rel.Schema))

Register a migration.

func (*Migration) Rollback

func (m *Migration) Rollback(ctx context.Context)

Rollback migration 1 step.

Jump to

Keyboard shortcuts

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