Skip to content

Lightweight database migragtion library for Golang

License

Notifications You must be signed in to change notification settings

h44z/lightmigrate

Repository files navigation

LightMigrate - a lightweight database migration library

codecov License: MIT GoDoc GitHub last commit Go Report Card GitHub go.mod Go version GitHub code size in bytes GitHub Release

This library is heavily inspired by golang-migrate.

It currently lacks support for many database drivers and the CLI feature, this is still WIP.

But it is completely restructured to minimize the dependency footprint.

Currently Supported databases

Usage example:

fsys := os.DirFS("/app/data") // Migration File Source Root (/app/data/migration-files)

source, err := NewFsSource(fsys, "migration-files")
if err != nil {
    t.Fatalf("unable to setup source: %v", err)
}
defer source.Close()

driver, err := test.NewMockDriver() // Database Driver (for example mongodb.NewDriver() or mysql.NewDriver())
if err != nil {
    t.Fatalf("unable to setup driver: %v", err)
}
defer driver.Close()

migrator, err := NewMigrator(source, driver, WithVerboseLogging(true)) // The migrator instance
if err != nil {
    t.Fatalf("unable to setup migrator: %v", err)
}

err = migrator.Migrate(3) // Migrate to schema version 3
if err != nil {
    t.Fatalf("migration error: %v", err)
}