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

Function TestMigrateDontOverrideAlterColumnByDefaultValue

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

Source from the content-addressed store, hash-verified

1603}
1604
1605func TestMigrateDontOverrideAlterColumnByDefaultValue(t *testing.T) {
1606 if DB.Dialector.Name() != "sqlite" {
1607 t.Skip()
1608 }
1609
1610 type BytesDefaultModel struct {
1611 ID int `gorm:"primaryKey"`
1612 Data []byte `gorm:"type:bytes;default:hello"`
1613 }
1614
1615 tableName := "bytes_default_models"
1616 DB.Migrator().DropTable(tableName)
1617 if err := DB.Exec("CREATE TABLE bytes_default_models (id integer primary key, data TEXT DEFAULT 'hello')").Error; err != nil {
1618 t.Fatalf("failed to create table, got error: %v", err)
1619 }
1620
1621 columnType, err := findColumnType(tableName, "data")
1622 if err != nil {
1623 t.Fatalf("failed to get column type, got error: %v", err)
1624 }
1625 AssertEqual(t, strings.ToLower(columnType.DatabaseTypeName()), "text")
1626
1627 if err := DB.AutoMigrate(&BytesDefaultModel{}); err != nil {
1628 t.Fatalf("failed to migrate, got error: %v", err)
1629 }
1630
1631 columnType, err = findColumnType(tableName, "data")
1632 if err != nil {
1633 t.Fatalf("failed to get column type, got error: %v", err)
1634 }
1635 if !strings.Contains(strings.ToUpper(columnType.DatabaseTypeName()), "BLOB") {
1636 t.Fatalf("expected data column to be migrated to BLOB, got: %s", columnType.DatabaseTypeName())
1637 }
1638}
1639
1640func TestMigrateMySQLWithCustomizedTypes(t *testing.T) {
1641 if DB.Dialector.Name() != "mysql" {

Callers

nothing calls this directly

Calls 9

findColumnTypeFunction · 0.85
ContainsMethod · 0.80
NameMethod · 0.65
DropTableMethod · 0.65
MigratorMethod · 0.65
ExecMethod · 0.65
DatabaseTypeNameMethod · 0.65
AutoMigrateMethod · 0.65
AssertEqualFunction · 0.50

Tested by

no test coverage detected