...

Text file src/github.com/golang-migrate/migrate/v4/source/httpfs/README.md

Documentation: github.com/golang-migrate/migrate/v4/source/httpfs

     1# httpfs
     2
     3## Usage
     4
     5This package could be used to create new migration source drivers that uses
     6`http.FileSystem` to read migration files.
     7
     8Struct `httpfs.PartialDriver` partly implements the `source.Driver` interface. It has all
     9the methods except for `Open()`. Embedding this struct and adding `Open()` method
    10allows users of this package to create new migration sources. Example:
    11
    12```go
    13struct mydriver {
    14        httpfs.PartialDriver
    15}
    16
    17func (d *mydriver) Open(url string) (source.Driver, error) {
    18	var fs http.FileSystem
    19	var path string
    20	var ds mydriver
    21
    22	// acquire fs and path from url
    23	// set-up ds if necessary
    24
    25	if err := ds.Init(fs, path); err != nil {
    26		return nil, err
    27	}
    28	return &ds, nil
    29}
    30```
    31
    32This package also provides a simple `source.Driver` implementation that works
    33with `http.FileSystem` provided by the user of this package. It is created with
    34`httpfs.New()` call.
    35
    36Example of using `http.Dir()` to read migrations from `sql` directory:
    37
    38```go
    39	src, err := httpfs.New(http.Dir("sql"))
    40	if err != nil {
    41		// do something
    42	}
    43	m, err := migrate.NewWithSourceInstance("httpfs", src, "database://url")
    44	if err != nil {
    45		// do something
    46	}
    47        err = m.Up()
    48	...
    49```

View as plain text