migrate

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: MIT Imports: 4 Imported by: 1

README

migrate

Golang Database Migration Library

Quickstart

textHandler := slog.NewTextHandler(os.Stdout)
logger := slog.New(textHandler)
driver := sqlite3driver.NewSqlite3Driver(db, logger)
err = migrate.Migrate(driver, migrationsFS, logger)

How it works

The Migrate function queries the driver for a list of all applied migrations. It then loads all the SQL files found on the supplied file system. It will sort these files by filename and then ask the driver to apply each migration that was not included in the original list of applied migrations.

Why not use golang-migrate/migrate?

I needed a simple library to perform Sqlite3 migrations. When you install golang-migrate/migrate it pulls in the dependencies for all the drivers it supports. This was leading to long build times.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(driver Driver, migrationsFS fs.FS, logger *slog.Logger) error

Types

type Driver

type Driver interface {
	Setup() error
	Applied() ([]string, error)
	Apply(migration Migration) error
}

type Migration

type Migration struct {
	Name string
	SQL  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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