pkger

package
v4.14.5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 7 Imported by: 0

README

pkger

package main

import (
	"errors"
	"log"

	"github.com/golang-migrate/migrate/v4"
	"github.com/markbates/pkger"

	_ "github.com/golang-migrate/migrate/v4/database/postgres"
	_ "github.com/golang-migrate/migrate/v4/source/pkger"
	_ "github.com/lib/pq"
)

func main() {
	pkger.Include("/module/path/to/migrations")
	m, err := migrate.New("pkger:///module/path/to/migrations", "postgres://postgres@localhost/postgres?sslmode=disable")
	if err != nil {
		log.Fatalln(err)
	}
	if err := m.Up(); errors.Is(err, migrate.ErrNoChange) {
		log.Println(err)
	} else if err != nil {
		log.Fatalln(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInstance

func WithInstance(instance pkging.Pkger, path string) (source.Driver, error)

WithInstance returns a source.Driver that is backed by an instance of pkging.Pkger. The relative location of migrations is indicated by path. The path must exist on the pkging.Pkger instance for the driver to initialize successfully.

Types

type Pkger

type Pkger struct {
	httpfs.PartialDriver
}

Pkger is a source.Driver that reads migrations from instances of pkging.Pkger.

func (*Pkger) Open

func (p *Pkger) Open(url string) (source.Driver, error)

Open implements source.Driver. The path component of url will be used as the relative location of migrations. The returned driver will use the package scoped pkger.Open to access migrations. The relative root and any migrations must be added to the global pkger.Pkger instance by calling pkger.Apply. Refer to Pkger documentation for more information.

Jump to

Keyboard shortcuts

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