godoc_vfs

package
v3.5.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package vfs contains a driver that reads migrations from a virtual file system.

Implementations of the filesystem interface that read from zip files and maps, as well as the definition of the filesystem interface can be found in the golang.org/x/tools/godoc/vfs package.

Example (Mapfs)
package main

import (
	"github.com/golang-migrate/migrate"
	"github.com/golang-migrate/migrate/source/godoc_vfs"
	"golang.org/x/tools/godoc/vfs/mapfs"
)

func main() {
	fs := mapfs.New(map[string]string{
		"1_foobar.up.sql":   "1 up",
		"1_foobar.down.sql": "1 down",
		"3_foobar.up.sql":   "3 up",
		"4_foobar.up.sql":   "4 up",
		"4_foobar.down.sql": "4 down",
		"5_foobar.down.sql": "5 down",
		"7_foobar.up.sql":   "7 up",
		"7_foobar.down.sql": "7 down",
	})

	d, err := godoc_vfs.WithInstance(fs, "")
	if err != nil {
		panic("bad migrations found!")
	}
	m, err := migrate.NewWithSourceInstance("godoc-vfs", d, "database://foobar")
	if err != nil {
		panic("error creating the migrations")
	}
	m.Up()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithInstance

func WithInstance(fs vfs.FileSystem, searchPath string) (source.Driver, error)

WithInstance creates a new driver from a virtual file system. If a tree named searchPath exists in the virtual filesystem, WithInstance searches for migration files there. It defaults to "/".

Types

type VFS

type VFS struct {
	// contains filtered or unexported fields
}

VFS is an implementation of driver that returns migrations from a virtual file system.

func (*VFS) Close

func (b *VFS) Close() error

Close implements the source.Driver interface for VFS. It is a no-op and should not be used.

func (*VFS) First

func (b *VFS) First() (version uint, err error)

First returns the first migration verion found in the file system. If no version is available os.ErrNotExist is returned.

func (*VFS) Next

func (b *VFS) Next(version uint) (nextVersion uint, err error)

Prev returns the next version available to the driver. If no previous version is available os.ErrNotExist is returned.

func (*VFS) Open

func (b *VFS) Open(url string) (source.Driver, error)

Open implements the source.Driver interface for VFS.

Calling this function panics, instead use the WithInstance function. See the package level documentation for an example.

func (*VFS) Prev

func (b *VFS) Prev(version uint) (prevVersion uint, err error)

Prev returns the previous version available to the driver. If no previous version is available os.ErrNotExist is returned.

func (*VFS) ReadDown

func (b *VFS) ReadDown(version uint) (r io.ReadCloser, identifier string, err error)

ReadDown returns the down migration body and an identifier that helps with finding this migration in the source.

func (*VFS) ReadUp

func (b *VFS) ReadUp(version uint) (r io.ReadCloser, identifier string, err error)

ReadUp returns the up migration body and an identifier that helps with finding this migration in the source. If there is no up migration available for this version it returns os.ErrNotExist.

Jump to

Keyboard shortcuts

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