diff --git a/core/models/models/v2/base_v2.go b/core/models/models/v2/base_v2.go index 13a33abe3..c5b191b03 100644 --- a/core/models/models/v2/base_v2.go +++ b/core/models/models/v2/base_v2.go @@ -1,8 +1,10 @@ package models import ( - "go.mongodb.org/mongo-driver/bson/primitive" + "reflect" "time" + + "go.mongodb.org/mongo-driver/bson/primitive" ) type BaseModelV2[T any] struct { @@ -62,3 +64,66 @@ func (m *BaseModelV2[T]) SetUpdated(id primitive.ObjectID) { m.SetUpdatedAt(time.Now()) m.SetUpdatedBy(id) } + +func GetModelInstances() []any { + return []any{ + *new(TestModelV2), + *new(DataCollectionV2), + *new(DatabaseV2), + *new(DatabaseMetricV2), + *new(DependencyV2), + *new(DependencyLogV2), + *new(DependencySettingV2), + *new(DependencyTaskV2), + *new(EnvironmentV2), + *new(GitV2), + *new(MetricV2), + *new(NodeV2), + *new(NotificationChannelV2), + *new(NotificationRequestV2), + *new(NotificationSettingV2), + *new(PermissionV2), + *new(ProjectV2), + *new(RolePermissionV2), + *new(RoleV2), + *new(ScheduleV2), + *new(SettingV2), + *new(SpiderV2), + *new(SpiderStatV2), + *new(TaskQueueItemV2), + *new(TaskStatV2), + *new(TaskV2), + *new(TokenV2), + *new(UserRoleV2), + *new(UserV2), + } +} + +func GetSystemModelColNames() []string { + colNames := make([]string, 0) + for _, instance := range GetModelInstances() { + colName := GetCollectionNameByInstance(instance) + if colName != "" { + colNames = append(colNames, colName) + } + } + return colNames +} + +func GetCollectionNameByInstance(v any) string { + t := reflect.TypeOf(v) + field := t.Field(0) + return field.Tag.Get("collection") +} + +// Add this new function +func GetSystemModelColNamesMap() map[string]bool { + colNamesMap := make(map[string]bool) + for _, instance := range GetModelInstances() { + colName := GetCollectionNameByInstance(instance) + if colName != "" { + colNamesMap[colName] = true + } + } + return colNamesMap +}