package godoc_vfs

import "github.com/golang-migrate/migrate/v4/source/godoc_vfs"

Package godoc_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)

Code:

{
	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")
	}
	err = m.Up()
	if err != nil {
		panic("up failed")
	}
}

Index

Examples

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 {
	httpfs.PartialDriver
	// contains filtered or unexported fields
}

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

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.

Source Files

vfs.go

Version
v4.12.2
Published
Aug 4, 2020
Platform
windows/amd64
Imports
4 packages
Last checked
4 minutes ago

Tools for package owners.