mirror of https://github.com/go-gorm/gorm.git
test: test for postgrs serial column (#5234)
* test: test for postgrs sercial column * test: only for postgres * chore: spelling mistake * test: for drop sequence
This commit is contained in:
parent
3643f856a3
commit
a0cc631272
|
@ -574,3 +574,65 @@ func TestMigrateColumnOrder(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/go-gorm/gorm/issues/5047
|
||||
func TestMigrateSerialColumn(t *testing.T) {
|
||||
if DB.Dialector.Name() != "postgres" {
|
||||
return
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
UID uint32
|
||||
}
|
||||
|
||||
type Event1 struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
UID uint32 `gorm:"not null;autoIncrement"`
|
||||
}
|
||||
|
||||
type Event2 struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
UID uint16 `gorm:"not null;autoIncrement"`
|
||||
}
|
||||
|
||||
var err error
|
||||
err = DB.Migrator().DropTable(&Event{})
|
||||
if err != nil {
|
||||
t.Errorf("DropTable err:%v", err)
|
||||
}
|
||||
|
||||
// create sequence
|
||||
err = DB.Table("events").AutoMigrate(&Event1{})
|
||||
if err != nil {
|
||||
t.Errorf("AutoMigrate err:%v", err)
|
||||
}
|
||||
|
||||
// delete sequence
|
||||
err = DB.Table("events").AutoMigrate(&Event{})
|
||||
if err != nil {
|
||||
t.Errorf("AutoMigrate err:%v", err)
|
||||
}
|
||||
|
||||
// update sequence
|
||||
err = DB.Table("events").AutoMigrate(&Event1{})
|
||||
if err != nil {
|
||||
t.Errorf("AutoMigrate err:%v", err)
|
||||
}
|
||||
err = DB.Table("events").AutoMigrate(&Event2{})
|
||||
if err != nil {
|
||||
t.Errorf("AutoMigrate err:%v", err)
|
||||
}
|
||||
|
||||
DB.Table("events").Save(&Event2{})
|
||||
DB.Table("events").Save(&Event2{})
|
||||
DB.Table("events").Save(&Event2{})
|
||||
|
||||
events := make([]*Event, 0)
|
||||
DB.Table("events").Find(&events)
|
||||
|
||||
AssertEqual(t, 3, len(events))
|
||||
for _, v := range events {
|
||||
AssertEqual(t, v.ID, v.UID)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue