MCPcopy
hub / github.com/go-gorm/gorm / TestAutoMigrateInt8PGAndGaussDB

Function TestAutoMigrateInt8PGAndGaussDB

tests/migrate_test.go:86–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestAutoMigrateInt8PGAndGaussDB(t *testing.T) {
87 if DB.Dialector.Name() != "postgres" && DB.Dialector.Name() != "gaussdb" {
88 return
89 }
90
91 type Smallint int8
92
93 type MigrateInt struct {
94 Int8 Smallint
95 }
96
97 tracer := Tracer{
98 Logger: DB.Config.Logger,
99 Test: func(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
100 sql, _ := fc()
101 if strings.HasPrefix(sql, "ALTER TABLE \"migrate_ints\" ALTER COLUMN \"int8\" TYPE smallint") {
102 t.Fatalf("shouldn't execute ALTER COLUMN TYPE if such type is already existed in DB schema: sql: %s",
103 sql)
104 }
105 },
106 }
107
108 DB.Migrator().DropTable(&MigrateInt{})
109
110 // The first AutoMigrate to make table with field with correct type
111 if err := DB.AutoMigrate(&MigrateInt{}); err != nil {
112 t.Fatalf("Failed to auto migrate: error: %v", err)
113 }
114
115 // make new session to set custom logger tracer
116 session := DB.Session(&gorm.Session{Logger: tracer})
117
118 // The second AutoMigrate to catch an error
119 if err := session.AutoMigrate(&MigrateInt{}); err != nil {
120 t.Fatalf("Failed to auto migrate: error: %v", err)
121 }
122}
123
124func TestAutoMigrateSelfReferential(t *testing.T) {
125 type MigratePerson struct {

Callers

nothing calls this directly

Calls 5

SessionMethod · 0.80
NameMethod · 0.65
DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65

Tested by

no test coverage detected