package model import ( "slices" "sync" "testing" "gorm.io/gorm/schema" ) func TestGORMModelsMatchMigrationColumns(t *testing.T) { tests := []struct { model any want []string }{ {User{}, []string{"id", "username", "email", "password_hash", "display_name", "status", "created_at", "updated_at"}}, {Provider{}, []string{"id", "slug", "name", "base_url", "auth_type", "api_key_enc", "enabled", "created_at", "updated_at"}}, {ProviderModel{}, []string{"id", "provider_id", "name", "model_id", "api_type", "kind", "extra_body", "timeout_ms", "weight", "enabled", "created_at", "updated_at"}}, {PromptTemplate{}, []string{"id", "template_key", "kind", "api_type", "capability", "name", "version", "template_text", "default_role_rule", "enabled", "created_at", "updated_at"}}, {Generation{}, []string{"id", "user_id", "provider_model_id", "route_pool_id", "route_pool_version", "prompt_template_id", "route_snapshot", "role_rule", "provider_attempt_count", "kind", "status", "idempotency_key", "user_prompt", "rendered_prompt", "attempts", "attempt_count", "error_code", "error_message", "lease_owner", "lease_token", "lease_until", "available_at", "started_at", "completed_at", "created_at", "updated_at"}}, {GenerationInput{}, []string{"id", "generation_id", "position", "role", "note", "original_name", "mime_type", "storage_key", "size_bytes", "width", "height", "created_at"}}, {GenerationOutput{}, []string{"id", "generation_id", "kind", "text_content", "storage_key", "thumbnail_storage_key", "mime_type", "size_bytes", "width", "height", "created_at"}}, {APIKey{}, []string{"id", "user_id", "name", "public_id", "key_prefix", "secret_hash", "expires_at", "last_used_at", "revoked_at", "created_at", "updated_at"}}, {APIAuditEvent{}, []string{"id", "user_id", "api_key_id", "generation_id", "action", "result", "request_id", "status_code", "error_code", "summary", "created_at"}}, } for _, test := range tests { parsed, err := schema.Parse(test.model, &sync.Map{}, schema.NamingStrategy{}) if err != nil { t.Fatalf("schema.Parse(%T) error = %v", test.model, err) } got := append([]string(nil), parsed.DBNames...) slices.Sort(got) want := append([]string(nil), test.want...) slices.Sort(want) if !slices.Equal(got, want) { t.Errorf("%T columns = %v, want %v", test.model, got, want) } } }