mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-09 11:17:28 -06:00
[chore] update go dependencies (#4304)
- github.com/KimMachineGun/automemlimit v0.7.2 => v0.7.3
- github.com/gin-contrib/cors v1.7.5 => v1.7.6
- github.com/minio/minio-go/v7 v7.0.92 => v7.0.94
- github.com/spf13/cast v1.8.0 => v1.9.2
- github.com/uptrace/bun{,/*} v1.2.11 => v1.2.14
- golang.org/x/image v0.27.0 => v0.28.0
- golang.org/x/net v0.40.0 => v0.41.0
- code.superseriousbusiness.org/go-swagger v0.31.0-gts-go1.23-fix => v0.32.3-gts-go1.23-fix
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4304
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
7712885038
commit
8b0ea56027
294 changed files with 139999 additions and 21873 deletions
49
vendor/github.com/uptrace/bun/migrate/migration.go
generated
vendored
49
vendor/github.com/uptrace/bun/migrate/migration.go
generated
vendored
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io/fs"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
|
|
@ -23,8 +24,8 @@ type Migration struct {
|
|||
GroupID int64
|
||||
MigratedAt time.Time `bun:",notnull,nullzero,default:current_timestamp"`
|
||||
|
||||
Up MigrationFunc `bun:"-"`
|
||||
Down MigrationFunc `bun:"-"`
|
||||
Up internalMigrationFunc `bun:"-"`
|
||||
Down internalMigrationFunc `bun:"-"`
|
||||
}
|
||||
|
||||
func (m Migration) String() string {
|
||||
|
|
@ -35,23 +36,57 @@ func (m Migration) IsApplied() bool {
|
|||
return m.ID > 0
|
||||
}
|
||||
|
||||
type internalMigrationFunc func(ctx context.Context, db *bun.DB, templateData any) error
|
||||
|
||||
type MigrationFunc func(ctx context.Context, db *bun.DB) error
|
||||
|
||||
func NewSQLMigrationFunc(fsys fs.FS, name string) MigrationFunc {
|
||||
return func(ctx context.Context, db *bun.DB) error {
|
||||
func NewSQLMigrationFunc(fsys fs.FS, name string) internalMigrationFunc {
|
||||
return func(ctx context.Context, db *bun.DB, templateData any) error {
|
||||
f, err := fsys.Open(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isTx := strings.HasSuffix(name, ".tx.up.sql") || strings.HasSuffix(name, ".tx.down.sql")
|
||||
return Exec(ctx, db, f, isTx)
|
||||
return Exec(ctx, db, f, templateData, isTx)
|
||||
}
|
||||
}
|
||||
|
||||
func wrapMigrationFunc(fn MigrationFunc) internalMigrationFunc {
|
||||
return func(ctx context.Context, db *bun.DB, templateData any) error {
|
||||
return fn(ctx, db)
|
||||
}
|
||||
}
|
||||
|
||||
func renderTemplate(contents []byte, templateData any) (*bytes.Buffer, error) {
|
||||
tmpl, err := template.New("migration").Parse(string(contents))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse template: %w", err)
|
||||
}
|
||||
|
||||
var rendered bytes.Buffer
|
||||
if err := tmpl.Execute(&rendered, templateData); err != nil {
|
||||
return nil, fmt.Errorf("failed to execute template: %w", err)
|
||||
}
|
||||
|
||||
return &rendered, nil
|
||||
}
|
||||
|
||||
// Exec reads and executes the SQL migration in the f.
|
||||
func Exec(ctx context.Context, db *bun.DB, f io.Reader, isTx bool) error {
|
||||
scanner := bufio.NewScanner(f)
|
||||
func Exec(ctx context.Context, db *bun.DB, f io.Reader, templateData any, isTx bool) error {
|
||||
contents, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var reader io.Reader = bytes.NewReader(contents)
|
||||
if templateData != nil {
|
||||
buf, err := renderTemplate(contents, templateData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reader = buf
|
||||
}
|
||||
scanner := bufio.NewScanner(reader)
|
||||
var queries []string
|
||||
|
||||
var query []byte
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue