update dependencies (#6267)

Signed-off-by: hongming <coder.scala@gmail.com>
This commit is contained in:
hongming
2024-11-06 10:27:06 +08:00
committed by GitHub
parent faf255a084
commit cfebd96a1f
4263 changed files with 341374 additions and 132036 deletions

View File

@@ -9,9 +9,18 @@ linters-settings:
disable:
- fieldalignment
depguard:
list-type: blacklist
include-go-root: true
include-go-std-lib: true
rules:
main:
allow:
- $gostd
- github.com/denisenkom/go-mssqldb
- github.com/go-sql-driver/mysql
- github.com/go-gorp/gorp/v3
- github.com/lib/pq
- github.com/mattn/go-sqlite3
- github.com/mitchellh/cli
- github.com/olekukonko/tablewriter
- github.com/rubenv/sql-migrate
exhaustive:
default-signifies-exhaustive: true
nolintlint:

View File

@@ -219,6 +219,7 @@ migrations := &migrate.FileMigrationSource{
}
// OR: Use migrations from a packr box
// Note: Packr is no longer supported, your best option these days is [embed](https://pkg.go.dev/embed)
migrations := &migrate.PackrMigrationSource{
Box: packr.New("migrations", "./migrations"),
}
@@ -316,62 +317,31 @@ CREATE UNIQUE INDEX CONCURRENTLY people_unique_id_idx ON people (id);
DROP INDEX people_unique_id_idx;
```
## Embedding migrations with [packr](https://github.com/gobuffalo/packr)
## Embedding migrations with [embed](https://pkg.go.dev/embed)
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.
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.
Just write your migration files as usual, as a set of SQL files in a folder.
Import the packr package into your application:
Import the embed package into your application and point it to your migrations:
```go
import "github.com/gobuffalo/packr/v2"
import "embed"
//go:embed migrations/*
var dbMigrations embed.FS
```
Use the `PackrMigrationSource` in your application to find the migrations:
Use the `EmbedFileSystemMigrationSource` in your application to find the migrations:
```go
migrations := &migrate.PackrMigrationSource{
Box: packr.New("migrations", "./migrations"),
migrations := migrate.EmbedFileSystemMigrationSource{
FileSystem: dbMigrations,
Root: "migrations",
}
```
If you already have a box and would like to use a subdirectory:
```go
migrations := &migrate.PackrMigrationSource{
Box: myBox,
Dir: "./migrations",
}
```
## Embedding migrations with [bindata](https://github.com/shuLhan/go-bindata)
As an alternative, but slightly less maintained, you can use [bindata](https://github.com/shuLhan/go-bindata) to embed the migration files.
Just write your migration files as usual, as a set of SQL files in a folder.
Then use bindata to generate a `.go` file with the migrations embedded:
```bash
go-bindata -pkg myapp -o bindata.go db/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).
Use the `AssetMigrationSource` in your application to find the migrations:
```go
migrations := &migrate.AssetMigrationSource{
Asset: Asset,
AssetDir: AssetDir,
Dir: "db/migrations",
}
```
Both `Asset` and `AssetDir` are functions provided by bindata.
Then proceed as usual.
Other options such as [packr](https://github.com/gobuffalo/packr) or [go-bindata](https://github.com/shuLhan/go-bindata) are no longer recommended.
## Embedding migrations with libraries that implement `http.FileSystem`

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"database/sql"
"embed"
"errors"
"fmt"
"io"
@@ -343,6 +344,19 @@ func (a AssetMigrationSource) FindMigrations() ([]*Migration, error) {
return migrations, nil
}
// A set of migrations loaded from an go1.16 embed.FS
type EmbedFileSystemMigrationSource struct {
FileSystem embed.FS
Root string
}
var _ MigrationSource = (*EmbedFileSystemMigrationSource)(nil)
func (f EmbedFileSystemMigrationSource) FindMigrations() ([]*Migration, error) {
return findMigrations(http.FS(f.FileSystem), f.Root)
}
// Avoids pulling in the packr library for everyone, mimicks the bits of
// packr.Box that we need.
type PackrBox interface {

View File

@@ -1,23 +0,0 @@
//go:build go1.16
// +build go1.16
package migrate
import (
"embed"
"net/http"
)
// A set of migrations loaded from an go1.16 embed.FS
type EmbedFileSystemMigrationSource struct {
FileSystem embed.FS
Root string
}
var _ MigrationSource = (*EmbedFileSystemMigrationSource)(nil)
func (f EmbedFileSystemMigrationSource) FindMigrations() ([]*Migration, error) {
return findMigrations(http.FS(f.FileSystem), f.Root)
}

View File

@@ -1,8 +0,0 @@
-- +migrate Up
-- SQL in section 'Up' is executed when this migration is applied
CREATE TABLE people (id int);
-- +migrate Down
-- SQL section 'Down' is executed when this migration is rolled back
DROP TABLE people;

View File

@@ -1,5 +0,0 @@
-- +migrate Up
INSERT INTO people (id) VALUES (1);
-- +migrate Down
DELETE FROM people WHERE id=1;