add test: update: TestAutoMigrateInt8PG

This commit is contained in:
viatoriche / Maxim Panfilov 2022-10-14 11:15:29 +03:00
parent c5e6119e94
commit 0f51c59f13

View File

@ -77,21 +77,23 @@ func TestMigrate(t *testing.T) {
}
type Smallint int8
func TestAutoMigrateInt8PG(t *testing.T) {
if DB.Dialector.Name() != "postgres" {
return
}
type MigrateInt struct {
Int8 int8
Int8 Smallint
}
tracer := Tracer{
Logger: DB.Config.Logger,
Test: func(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
sql, _ := fc()
if sql == "ALTER TABLE \"migrate_ints\" ALTER COLUMN \"int8\" TYPE smallint" {
t.Fatalf("shouldn't execute ALTER COLUMN TYPE if such type is already existed in DB schema")
if strings.HasPrefix(sql, `ALTER TABLE "migrate_ints" ALTER COLUMN "int8" TYPE smallint`) {
t.Fatalf("shouldn't execute ALTER COLUMN TYPE if such type is already existed in DB schema: sql: %s", sql)
}
},
}