[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:
kim 2025-06-30 15:19:09 +02:00 committed by kim
commit 8b0ea56027
294 changed files with 139999 additions and 21873 deletions

View file

@ -4,12 +4,11 @@ import (
"slices"
"strings"
"github.com/uptrace/bun/internal/ordered"
"github.com/uptrace/bun/schema"
)
type Database interface {
GetTables() *ordered.Map[string, Table]
GetTables() []Table
GetForeignKeys() map[ForeignKey]string
}
@ -20,11 +19,11 @@ var _ Database = (*BaseDatabase)(nil)
// Dialects and only dialects can use it to implement the Database interface.
// Other packages must use the Database interface.
type BaseDatabase struct {
Tables *ordered.Map[string, Table]
Tables []Table
ForeignKeys map[ForeignKey]string
}
func (ds BaseDatabase) GetTables() *ordered.Map[string, Table] {
func (ds BaseDatabase) GetTables() []Table {
return ds.Tables
}

View file

@ -7,7 +7,6 @@ import (
"strings"
"github.com/uptrace/bun"
"github.com/uptrace/bun/internal/ordered"
"github.com/uptrace/bun/schema"
)
@ -30,12 +29,23 @@ type InspectorDialect interface {
// InspectorConfig controls the scope of migration by limiting the objects Inspector should return.
// Inspectors SHOULD use the configuration directly instead of copying it, or MAY choose to embed it,
// to make sure options are always applied correctly.
//
// ExcludeTables and ExcludeForeignKeys are intended for database inspectors,
// to compensate for the fact that model structs may not wholly reflect the
// state of the database schema.
// Database inspectors MUST respect these exclusions to prevent relations
// from being dropped unintentionally.
type InspectorConfig struct {
// SchemaName limits inspection to tables in a particular schema.
SchemaName string
// ExcludeTables from inspection.
// ExcludeTables from inspection. Patterns MAY make use of wildcards
// like % and _ and dialects MUST acknowledge that by using them
// with the SQL LIKE operator.
ExcludeTables []string
// ExcludeForeignKeys from inspection.
ExcludeForeignKeys map[ForeignKey]string
}
// Inspector reads schema state.
@ -49,13 +59,26 @@ func WithSchemaName(schemaName string) InspectorOption {
}
}
// WithExcludeTables works in append-only mode, i.e. tables cannot be re-included.
// WithExcludeTables forces inspector to exclude tables from the reported schema state.
// It works in append-only mode, i.e. tables cannot be re-included.
//
// Patterns MAY make use of % and _ wildcards, as if writing a LIKE clause in SQL.
func WithExcludeTables(tables ...string) InspectorOption {
return func(cfg *InspectorConfig) {
cfg.ExcludeTables = append(cfg.ExcludeTables, tables...)
}
}
// WithExcludeForeignKeys forces inspector to exclude foreign keys
// from the reported schema state.
func WithExcludeForeignKeys(fks ...ForeignKey) InspectorOption {
return func(cfg *InspectorConfig) {
for _, fk := range fks {
cfg.ExcludeForeignKeys[fk] = ""
}
}
}
// NewInspector creates a new database inspector, if the dialect supports it.
func NewInspector(db *bun.DB, options ...InspectorOption) (Inspector, error) {
dialect, ok := (db.Dialect()).(InspectorDialect)
@ -78,6 +101,9 @@ func NewBunModelInspector(tables *schema.Tables, options ...InspectorOption) *Bu
type InspectorOption func(*InspectorConfig)
func ApplyInspectorOptions(cfg *InspectorConfig, options ...InspectorOption) {
if cfg.ExcludeForeignKeys == nil {
cfg.ExcludeForeignKeys = make(map[ForeignKey]string)
}
for _, opt := range options {
opt(cfg)
}
@ -90,6 +116,10 @@ type inspector struct {
// BunModelInspector creates the current project state from the passed bun.Models.
// Do not recycle BunModelInspector for different sets of models, as older models will not be de-registerred before the next run.
//
// BunModelInspector does not know which the database's dialect, so it does not
// assume any default schema name. Always specify the target schema name via
// WithSchemaName option to receive meaningful results.
type BunModelInspector struct {
InspectorConfig
tables *schema.Tables
@ -102,21 +132,21 @@ func (bmi *BunModelInspector) Inspect(ctx context.Context) (Database, error) {
BaseDatabase: BaseDatabase{
ForeignKeys: make(map[ForeignKey]string),
},
Tables: ordered.NewMap[string, Table](),
}
for _, t := range bmi.tables.All() {
if t.Schema != bmi.SchemaName {
continue
}
columns := ordered.NewMap[string, Column]()
var columns []Column
for _, f := range t.Fields {
sqlType, length, err := parseLen(f.CreateTableSQLType)
if err != nil {
return nil, fmt.Errorf("parse length in %q: %w", f.CreateTableSQLType, err)
}
columns.Store(f.Name, &BaseColumn{
columns = append(columns, &BaseColumn{
Name: f.Name,
SQLType: strings.ToLower(sqlType), // TODO(dyma): maybe this is not necessary after Column.Eq()
VarcharLen: length,
@ -162,7 +192,7 @@ func (bmi *BunModelInspector) Inspect(ctx context.Context) (Database, error) {
// produces
// schema.Table{ Schema: "favourite", Name: "favourite.books" }
tableName := strings.TrimPrefix(t.Name, t.Schema+".")
state.Tables.Store(tableName, &BunTable{
state.Tables = append(state.Tables, &BunTable{
BaseTable: BaseTable{
Schema: t.Schema,
Name: tableName,
@ -212,7 +242,7 @@ func parseLen(typ string) (string, int, error) {
}
// exprOrLiteral converts string to lowercase, if it does not contain a string literal 'lit'
// and trims the surrounding '' otherwise.
// and trims the surrounding otherwise.
// Use it to ensure that user-defined default values in the models are always comparable
// to those returned by the database inspector, regardless of the case convention in individual drivers.
func exprOrLiteral(s string) string {
@ -226,10 +256,10 @@ func exprOrLiteral(s string) string {
type BunModelSchema struct {
BaseDatabase
Tables *ordered.Map[string, Table]
Tables []Table
}
func (ms BunModelSchema) GetTables() *ordered.Map[string, Table] {
func (ms BunModelSchema) GetTables() []Table {
return ms.Tables
}

View file

@ -1,13 +1,9 @@
package sqlschema
import (
"github.com/uptrace/bun/internal/ordered"
)
type Table interface {
GetSchema() string
GetName() string
GetColumns() *ordered.Map[string, Column]
GetColumns() []Column
GetPrimaryKey() *PrimaryKey
GetUniqueConstraints() []Unique
}
@ -23,7 +19,7 @@ type BaseTable struct {
Name string
// ColumnDefinitions map each column name to the column definition.
Columns *ordered.Map[string, Column]
Columns []Column
// PrimaryKey holds the primary key definition.
// A nil value means that no primary key is defined for the table.
@ -47,7 +43,7 @@ func (td *BaseTable) GetName() string {
return td.Name
}
func (td *BaseTable) GetColumns() *ordered.Map[string, Column] {
func (td *BaseTable) GetColumns() []Column {
return td.Columns
}