iofs

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package iofs contains functions that allows to work with migration using io/fs package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectMigrations

func CollectMigrations(fsys fs.FS, dirpath string, current, target int64) (goose.Migrations, error)

CollectMigrations returns all the valid looking migration scripts in the migrations folder and key them by version.

func Down

func Down(db *sql.DB, fsys fs.FS, dir string) error

Down rolls back a single migration from the current version.

func DownTo

func DownTo(db *sql.DB, fsys fs.FS, dir string, version int64) error

DownTo rolls back migrations to a specific version.

func Redo

func Redo(db *sql.DB, fsys fs.FS, dir string) error

Redo rolls back the most recently applied migration, then runs it again.

func Reset

func Reset(db *sql.DB, fsys fs.FS, dir string) error

Reset rolls back all migrations.

func Status

func Status(db *sql.DB, fsys fs.FS, dir string) error

Status prints the status of all migrations.

func Up

func Up(db *sql.DB, fsys fs.FS, dir string) error

Up applies all available migrations.

Example
package main

import (
	"database/sql"
	"embed"
	"log"

	"github.com/vearutop/gooselite/iofs"
)

//go:embed testdata
var migrations embed.FS

func main() {
	db, err := sql.Open("sqlite3", "sql.db")
	if err != nil {
		log.Fatalf("Failed to open test database: %v", err)
	}

	if err := iofs.Up(db, migrations, "testdata/migrations"); err != nil {
		log.Fatalf("Failed to run up migrations: %v", err)
	}
}
Output:

func UpByOne

func UpByOne(db *sql.DB, fsys fs.FS, dir string) error

UpByOne migrates up by a single version.

func UpTo

func UpTo(db *sql.DB, fsys fs.FS, dir string, version int64) error

UpTo migrates up to a specific version.

Types

This section is empty.

Jump to

Keyboard shortcuts

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