You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Note: Packr is no longer supported, your best option these days is [embed](https://pkg.go.dev/embed)
222
223
migrations:= &migrate.PackrMigrationSource{
223
224
Box: packr.New("migrations", "./migrations"),
224
225
}
@@ -316,62 +317,31 @@ CREATE UNIQUE INDEX CONCURRENTLY people_unique_id_idx ON people (id);
316
317
DROPINDEX people_unique_id_idx;
317
318
```
318
319
319
-
## Embedding migrations with [packr](https://github.com/gobuffalo/packr)
320
+
## Embedding migrations with [embed](https://pkg.go.dev/embed)
320
321
321
-
If you like your Go applications self-contained (that is: a single binary): use [packr](https://github.com/gobuffalo/packr) to embed the migration files.
322
+
If you like your Go applications self-contained (that is: a single binary): use [embed](https://pkg.go.dev/embed) to embed the migration files.
322
323
323
324
Just write your migration files as usual, as a set of SQL files in a folder.
324
325
325
-
Import the packr package into your application:
326
+
Import the embed package into your application and point it to your migrations:
326
327
327
328
```go
328
-
import"github.com/gobuffalo/packr/v2"
329
-
```
330
-
331
-
Use the `PackrMigrationSource` in your application to find the migrations:
329
+
import"embed"
332
330
333
-
```go
334
-
migrations:= &migrate.PackrMigrationSource{
335
-
Box: packr.New("migrations", "./migrations"),
336
-
}
331
+
//go:embed migrations/*
332
+
vardbMigrations embed.FS
337
333
```
338
334
339
-
If you already have a box and would like to use a subdirectory:
335
+
Use the `EmbedFileSystemMigrationSource` in your application to find the migrations:
The resulting `bindata.go` file will contain your migrations. Remember to regenerate your `bindata.go` file whenever you add/modify a migration (`go generate` will help here, once it arrives).
361
-
362
-
Use the `AssetMigrationSource` in your application to find the migrations:
363
-
364
-
```go
365
-
migrations:= &migrate.AssetMigrationSource{
366
-
Asset: Asset,
367
-
AssetDir: AssetDir,
368
-
Dir: "db/migrations",
369
-
}
370
-
```
371
-
372
-
Both `Asset` and `AssetDir` are functions provided by bindata.
373
-
374
-
Then proceed as usual.
344
+
Other options such as [packr](https://github.com/gobuffalo/packr) or [go-bindata](https://github.com/shuLhan/go-bindata) are no longer recommended.
375
345
376
346
## Embedding migrations with libraries that implement `http.FileSystem`
0 commit comments