summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/migrate/sqlschema
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace/bun/migrate/sqlschema')
-rw-r--r--vendor/github.com/uptrace/bun/migrate/sqlschema/database.go8
-rw-r--r--vendor/github.com/uptrace/bun/migrate/sqlschema/inspector.go23
-rw-r--r--vendor/github.com/uptrace/bun/migrate/sqlschema/table.go8
3 files changed, 20 insertions, 19 deletions
diff --git a/vendor/github.com/uptrace/bun/migrate/sqlschema/database.go b/vendor/github.com/uptrace/bun/migrate/sqlschema/database.go
index cdc5b2d50..eb7476c54 100644
--- a/vendor/github.com/uptrace/bun/migrate/sqlschema/database.go
+++ b/vendor/github.com/uptrace/bun/migrate/sqlschema/database.go
@@ -4,12 +4,12 @@ import (
"slices"
"strings"
+ "github.com/uptrace/bun/internal/ordered"
"github.com/uptrace/bun/schema"
- orderedmap "github.com/wk8/go-ordered-map/v2"
)
type Database interface {
- GetTables() *orderedmap.OrderedMap[string, Table]
+ GetTables() *ordered.Map[string, Table]
GetForeignKeys() map[ForeignKey]string
}
@@ -20,11 +20,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 *orderedmap.OrderedMap[string, Table]
+ Tables *ordered.Map[string, Table]
ForeignKeys map[ForeignKey]string
}
-func (ds BaseDatabase) GetTables() *orderedmap.OrderedMap[string, Table] {
+func (ds BaseDatabase) GetTables() *ordered.Map[string, Table] {
return ds.Tables
}
diff --git a/vendor/github.com/uptrace/bun/migrate/sqlschema/inspector.go b/vendor/github.com/uptrace/bun/migrate/sqlschema/inspector.go
index fc9af06fc..19d1dc469 100644
--- a/vendor/github.com/uptrace/bun/migrate/sqlschema/inspector.go
+++ b/vendor/github.com/uptrace/bun/migrate/sqlschema/inspector.go
@@ -7,8 +7,8 @@ import (
"strings"
"github.com/uptrace/bun"
+ "github.com/uptrace/bun/internal/ordered"
"github.com/uptrace/bun/schema"
- orderedmap "github.com/wk8/go-ordered-map/v2"
)
type InspectorDialect interface {
@@ -102,25 +102,25 @@ func (bmi *BunModelInspector) Inspect(ctx context.Context) (Database, error) {
BaseDatabase: BaseDatabase{
ForeignKeys: make(map[ForeignKey]string),
},
- Tables: orderedmap.New[string, Table](),
+ Tables: ordered.NewMap[string, Table](),
}
for _, t := range bmi.tables.All() {
if t.Schema != bmi.SchemaName {
continue
}
- columns := orderedmap.New[string, Column]()
+ columns := ordered.NewMap[string, 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.Set(f.Name, &BaseColumn{
+ columns.Store(f.Name, &BaseColumn{
Name: f.Name,
SQLType: strings.ToLower(sqlType), // TODO(dyma): maybe this is not necessary after Column.Eq()
VarcharLen: length,
- DefaultValue: exprToLower(f.SQLDefault),
+ DefaultValue: exprOrLiteral(f.SQLDefault),
IsNullable: !f.NotNull,
IsAutoIncrement: f.AutoIncrement,
IsIdentity: f.Identity,
@@ -162,7 +162,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.Set(tableName, &BunTable{
+ state.Tables.Store(tableName, &BunTable{
BaseTable: BaseTable{
Schema: t.Schema,
Name: tableName,
@@ -211,12 +211,13 @@ func parseLen(typ string) (string, int, error) {
return typ[:paren], length, nil
}
-// exprToLower converts string to lowercase, if it does not contain a string literal 'lit'.
+// exprOrLiteral converts string to lowercase, if it does not contain a string literal 'lit'
+// 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 exprToLower(s string) string {
+func exprOrLiteral(s string) string {
if strings.HasPrefix(s, "'") && strings.HasSuffix(s, "'") {
- return s
+ return strings.Trim(s, "'")
}
return strings.ToLower(s)
}
@@ -225,10 +226,10 @@ func exprToLower(s string) string {
type BunModelSchema struct {
BaseDatabase
- Tables *orderedmap.OrderedMap[string, Table]
+ Tables *ordered.Map[string, Table]
}
-func (ms BunModelSchema) GetTables() *orderedmap.OrderedMap[string, Table] {
+func (ms BunModelSchema) GetTables() *ordered.Map[string, Table] {
return ms.Tables
}
diff --git a/vendor/github.com/uptrace/bun/migrate/sqlschema/table.go b/vendor/github.com/uptrace/bun/migrate/sqlschema/table.go
index a805ba780..ec9b77f69 100644
--- a/vendor/github.com/uptrace/bun/migrate/sqlschema/table.go
+++ b/vendor/github.com/uptrace/bun/migrate/sqlschema/table.go
@@ -1,13 +1,13 @@
package sqlschema
import (
- orderedmap "github.com/wk8/go-ordered-map/v2"
+ "github.com/uptrace/bun/internal/ordered"
)
type Table interface {
GetSchema() string
GetName() string
- GetColumns() *orderedmap.OrderedMap[string, Column]
+ GetColumns() *ordered.Map[string, Column]
GetPrimaryKey() *PrimaryKey
GetUniqueConstraints() []Unique
}
@@ -23,7 +23,7 @@ type BaseTable struct {
Name string
// ColumnDefinitions map each column name to the column definition.
- Columns *orderedmap.OrderedMap[string, Column]
+ Columns *ordered.Map[string, Column]
// PrimaryKey holds the primary key definition.
// A nil value means that no primary key is defined for the table.
@@ -47,7 +47,7 @@ func (td *BaseTable) GetName() string {
return td.Name
}
-func (td *BaseTable) GetColumns() *orderedmap.OrderedMap[string, Column] {
+func (td *BaseTable) GetColumns() *ordered.Map[string, Column] {
return td.Columns
}