Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 574 Bytes

README.md

File metadata and controls

32 lines (25 loc) · 574 Bytes

migs

Simple library for go migrations. Supports plain text SQL statements and also functions.

Usage

package migs

import (
	"database/sql"
	"log"
)

func runMigrations(tx *sql.Tx) {
	migs := New(
		"CREATE TABLE users (id SERIAL NOT NULL PRIMARY KEY, email VARCHAR)",
		migrationFunc, // allow executing functions as well
	)
	err := migs.ExecuteTx(tx)
	if err != nil {
		log.Fatal(err)
	}
}

func migrationFunc(tx Con) error {
	_, err := tx.Exec("INSERT INTO users (email) VALUES ($1)", "[email protected]")
	return err
}