🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

src.userspace.com.au/migrate

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

src.userspace.com.au/migrate

Go Modules
Version
v0.2.0
Version published
Created
Source

Go migrations

A very simple migration library for your Go projects.

Features

  • Any database/sql compatible drivers should work. See https://github.com/golang/go/wiki/SQLDrivers

  • Each migration is run in a transaction so there should be no 'dirty' state.

  • Only migrates "up". I have never used a "down" migration.

  • Enables a callback function to suit whatever logging implementation you choose.

  • Supports Go1.16's io/fs interface for embedded migrations.

Example usage

import "src.userspace.com.au/migrate"
// or import "github.com/felix/migrate"

db, err := sql.Open("pgx", uri)
//db, err := sql.Open("sqlite3", uri)
if err != nil {
    return err
}
defer db.Close()

// Relative path to migration files
migrator, err := migrate.NewFileMigrator(db, "file://migrations/")
if err != nil {
    return fmt.Errorf("failed to create migrator: %s", err)
}

// Migrate all the way
err = migrator.Migrate()
if err != nil {
    return fmt.Errorf("failed to migrate: %s", err)
}

v, err := migrator.Version()
fmt.Printf("database at version %d\n", v)

FAQs

Package last updated on 05 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts