dbolve

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 7 Imported by: 0

README

CircleCI codecov GoDoc Go Report Card

dbolve

Very simple code only migration library for go

Features

  • Very simple and readable code (< 200 lines of code)
  • Easy to use interface
  • Transaction safety for each migration
  • Verifies that already applied transactions haven't changed

Usage

go get -u github.com/cinemast/dbolve
Quickstart

examples/main.go

Motivation

Heavily inspired by lopezator/migrator.

I was missing two features:

  • Allow to list already applied and pending migrations
  • Verification that already applied migrations match the current migration code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migration

type Migration struct {
	Name      string
	Code      func(t Transaction) error
	Timestamp string
	// contains filtered or unexported fields
}

Migration struct

type Migrator

type Migrator struct {
	Migrations []Migration
	Log        *log.Logger
	// contains filtered or unexported fields
}

Migrator type

func NewMigrator

func NewMigrator(db *sql.DB, migrations []Migration) (*Migrator, error)

NewMigrator creates a new instance of Migrator

func (*Migrator) Applied

func (m *Migrator) Applied() []Migration

Applied returns a slice of already applied migrations

func (*Migrator) CountApplied

func (m *Migrator) CountApplied() int

CountApplied returns the number of already applied migrations

func (*Migrator) DryRun

func (m *Migrator) DryRun() error

DryRun tries to run the migrations but rollbacks each transaction

func (*Migrator) Migrate

func (m *Migrator) Migrate() error

Migrate run's all missing migrations

func (*Migrator) Pending

func (m *Migrator) Pending() []Migration

Pending returns a slice of not yet applied migrations

type Transaction

type Transaction interface {
	Exec(sql string) error
}

Transaction exposes allowed database operations for migrations

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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