From d0d7b93f35c64af885e135f33227d15e4b9eb5ef Mon Sep 17 00:00:00 2001 From: Benjamin Kane Date: Sat, 18 Jan 2020 23:32:22 -0800 Subject: [PATCH] Update README.md with http.FileSystem docs --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36488556..c87ee09a 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ Import sql-migrate into your application: import "github.com/rubenv/sql-migrate" ``` -Set up a source of migrations, this can be from memory, from a set of files or from bindata (more on that later): +Set up a source of migrations, this can be from memory, from a set of files, from bindata (more on that later), or from any library that implements [`http.FileSystem`](https://godoc.org/net/http#FileSystem): ```go // Hardcoded strings in memory: @@ -168,6 +168,11 @@ migrations := &migrate.AssetMigrationSource{ AssetDir: AssetDir, Dir: "migrations", } + +// OR: Read migrations from a `http.FileSystem` +migrationSource := &migrate.HttpFileSystemMigrationSource{ + FileSystem: httpFS, +} ``` Then use the `Exec` function to upgrade your database: @@ -301,6 +306,16 @@ Both `Asset` and `AssetDir` are functions provided by bindata. Then proceed as usual. +## Embedding migrations with libraries that implement `http.FileSystem` + +You can also embed migrations with any library that implements `http.FileSystem`, like [`vfsgen`](https://github.com/shurcooL/vfsgen), [`parcello`](https://github.com/phogolabs/parcello), or [`go-resources`](https://github.com/omeid/go-resources). + +```go +migrationSource := &migrate.HttpFileSystemMigrationSource{ + FileSystem: httpFS, +} +``` + ## Extending Adding a new migration source means implementing `MigrationSource`.