README
¶
httpfs
Usage
This package could be used to create new migration source drivers that uses
http.FileSystem
to read migration files.
Struct httpfs.PartialDriver
partly implements the source.Driver
interface. It has all
the methods except for Open()
. Embedding this struct and adding Open()
method
allows users of this package to create new migration sources. Example:
struct mydriver {
httpfs.PartialDriver
}
func (d *mydriver) Open(url string) (source.Driver, error) {
var fs http.FileSystem
var path string
var ds mydriver
// acquire fs and path from url
// set-up ds if necessary
if err := ds.Init(fs, path); err != nil {
return nil, err
}
return &ds, nil
}
This package also provides a simple source.Driver
implementation that works
with http.FileSystem
provided by the user of this package. It is created with
httpfs.New()
call.
Example of using http.Dir()
to read migrations from sql
directory:
src, err := httpfs.New(http.Dir("sql"))
if err != nil {
// do something
}
m, err := migrate.NewWithSourceInstance("httpfs", src, "database://url")
if err != nil {
// do something
}
err = m.Up()
...
Documentation
¶
Index ¶
- func New(fs http.FileSystem, path string) (source.Driver, error)
- type PartialDriver
- func (p *PartialDriver) Close() error
- func (p *PartialDriver) First() (version uint, err error)
- func (p *PartialDriver) Init(fs http.FileSystem, path string) error
- func (d *PartialDriver) MarkSkipMigrations(version uint, dir source.Direction)
- func (p *PartialDriver) Next(version uint) (nextVersion uint, err error)
- func (p *PartialDriver) Prev(version uint) (prevVersion uint, err error)
- func (d *PartialDriver) PrintSummary(dir source.Direction)
- func (p *PartialDriver) ReadDown(version uint) (r io.ReadCloser, identifier string, location string, fn source.MigrationFunc, ...)
- func (p *PartialDriver) ReadUp(version uint) (r io.ReadCloser, identifier string, location string, fn source.MigrationFunc, ...)
- func (d *PartialDriver) UpdateStatus(version uint, status source.Status, errstr string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PartialDriver ¶
type PartialDriver struct {
// contains filtered or unexported fields
}
PartialDriver is a helper service for creating new source drivers working with http.FileSystem instances. It implements all source.Driver interface methods except for Open(). New driver could embed this struct and add missing Open() method.
To prepare PartialDriver for use Init() function.
func (*PartialDriver) Close ¶
func (p *PartialDriver) Close() error
Close is part of source.Driver interface implementation. This is a no-op.
func (*PartialDriver) First ¶
func (p *PartialDriver) First() (version uint, err error)
First is part of source.Driver interface implementation.
func (*PartialDriver) Init ¶
func (p *PartialDriver) Init(fs http.FileSystem, path string) error
Init prepares not initialized PartialDriver instance to read migrations from a http.FileSystem instance and a relative path.
func (*PartialDriver) MarkSkipMigrations ¶
func (d *PartialDriver) MarkSkipMigrations(version uint, dir source.Direction)
func (*PartialDriver) Next ¶
func (p *PartialDriver) Next(version uint) (nextVersion uint, err error)
Next is part of source.Driver interface implementation.
func (*PartialDriver) Prev ¶
func (p *PartialDriver) Prev(version uint) (prevVersion uint, err error)
Prev is part of source.Driver interface implementation.
func (*PartialDriver) PrintSummary ¶
func (d *PartialDriver) PrintSummary(dir source.Direction)
func (*PartialDriver) ReadDown ¶
func (p *PartialDriver) ReadDown(version uint) (r io.ReadCloser, identifier string, location string, fn source.MigrationFunc, err error)
ReadDown is part of source.Driver interface implementation.
func (*PartialDriver) ReadUp ¶
func (p *PartialDriver) ReadUp(version uint) (r io.ReadCloser, identifier string, location string, fn source.MigrationFunc, err error)
ReadUp is part of source.Driver interface implementation.
func (*PartialDriver) UpdateStatus ¶
func (d *PartialDriver) UpdateStatus(version uint, status source.Status, errstr string)