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

Function TestMigrateIndexesWithDynamicTableName

tests/migrate_test.go:838–867  ·  view source on GitHub ↗

To test auto migrate crate indexes for dynamic table name https://github.com/go-gorm/gorm/issues/4752

(t *testing.T)

Source from the content-addressed store, hash-verified

836// To test auto migrate crate indexes for dynamic table name
837// https://github.com/go-gorm/gorm/issues/4752
838func TestMigrateIndexesWithDynamicTableName(t *testing.T) {
839 // Create primary table
840 if err := DB.AutoMigrate(&DynamicUser{}); err != nil {
841 t.Fatalf("AutoMigrate create table error: %#v", err)
842 }
843
844 // Create sub tables
845 for _, v := range []string{"01", "02", "03"} {
846 tableName := "dynamic_users_" + v
847 m := DB.Scopes(func(db *gorm.DB) *gorm.DB {
848 return db.Table(tableName)
849 }).Migrator()
850
851 if err := m.AutoMigrate(&DynamicUser{}); err != nil {
852 t.Fatalf("AutoMigrate create table error: %#v", err)
853 }
854
855 if !m.HasTable(tableName) {
856 t.Fatalf("AutoMigrate expected %#v exist, but not.", tableName)
857 }
858
859 if !m.HasIndex(&DynamicUser{}, "CompanyID") {
860 t.Fatalf("Should have index on %s", "CompanyI.")
861 }
862
863 if !m.HasIndex(&DynamicUser{}, "DeletedAt") {
864 t.Fatalf("Should have index on deleted_at.")
865 }
866 }
867}
868
869// check column order after migration, flaky test
870// https://github.com/go-gorm/gorm/issues/4351

Callers

nothing calls this directly

Calls 6

AutoMigrateMethod · 0.65
MigratorMethod · 0.65
ScopesMethod · 0.65
TableMethod · 0.65
HasTableMethod · 0.65
HasIndexMethod · 0.65

Tested by

no test coverage detected