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

Function TestAutoMigrateSelfReferential

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

Source from the content-addressed store, hash-verified

122}
123
124func TestAutoMigrateSelfReferential(t *testing.T) {
125 type MigratePerson struct {
126 ID uint
127 Name string
128 ManagerID *uint
129 Manager *MigratePerson
130 }
131
132 DB.Migrator().DropTable(&MigratePerson{})
133
134 if err := DB.AutoMigrate(&MigratePerson{}); err != nil {
135 t.Fatalf("Failed to auto migrate, but got error %v", err)
136 }
137
138 if !DB.Migrator().HasConstraint("migrate_people", "fk_migrate_people_manager") {
139 t.Fatalf("Failed to find has one constraint between people and managers")
140 }
141}
142
143func TestAutoMigrateNullable(t *testing.T) {
144 type MigrateNullableColumn struct {

Callers

nothing calls this directly

Calls 4

DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65
HasConstraintMethod · 0.65

Tested by

no test coverage detected