(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func 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 | |
| 124 | func TestAutoMigrateSelfReferential(t *testing.T) { |
| 125 | type MigratePerson struct { |
nothing calls this directly
no test coverage detected