From 0cae48bbdeebf8ac29a96890901e8b6fea0139f3 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 26 Jun 2025 12:02:53 +0545 Subject: [PATCH] feat: config_properties table --- models/config_properties.go | 42 ++++++++++++++++ rbac/objects.go | 1 + schema/config_properties.hcl | 94 ++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 models/config_properties.go create mode 100644 schema/config_properties.hcl diff --git a/models/config_properties.go b/models/config_properties.go new file mode 100644 index 000000000..4b82487f1 --- /dev/null +++ b/models/config_properties.go @@ -0,0 +1,42 @@ +package models + +import ( + "time" + + "github.com/google/uuid" + "gorm.io/gorm/clause" +) + +// ConfigProperty represents properties associated with config items +type ConfigProperty struct { + ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"` + ConfigID uuid.UUID `json:"config_id"` + ScraperID uuid.UUID `json:"scraper_id"` + Label string `json:"label,omitempty"` + Text string `json:"text,omitempty" gorm:"default:NULL"` + Value *float64 `json:"value,omitempty" gorm:"default:NULL"` + Unit string `json:"unit,omitempty" gorm:"default:NULL"` + Max *int64 `json:"max,omitempty" gorm:"default:NULL"` + Min *int64 `json:"min,omitempty" gorm:"default:NULL"` + CreatedAt time.Time `json:"created_at" gorm:"<-:create"` + UpdatedAt time.Time `json:"updated_at"` + + // Visual properties + Tooltip string `json:"tooltip,omitempty" gorm:"default:NULL"` + Icon string `json:"icon,omitempty" gorm:"default:NULL"` + Type string `json:"type,omitempty" gorm:"default:NULL"` + Color string `json:"color,omitempty" gorm:"default:NULL"` + Order int `json:"order,omitempty" gorm:"default:NULL"` +} + +func (ConfigProperty) TableName() string { + return "config_properties" +} + +func (p ConfigProperty) PK() string { + return p.ID.String() +} + +func (p ConfigProperty) PKCols() []clause.Column { + return []clause.Column{{Name: "id"}} +} diff --git a/rbac/objects.go b/rbac/objects.go index 20a3d3070..2b2157ef1 100644 --- a/rbac/objects.go +++ b/rbac/objects.go @@ -68,6 +68,7 @@ var dbResourceObjMap = map[string]string{ "config_labels": policy.ObjectDatabasePublic, "config_names": policy.ObjectDatabasePublic, "config_relationships": policy.ObjectCatalog, + "config_properties": policy.ObjectCatalog, "config_scrapers_with_status": policy.ObjectMonitor, "config_scrapers": policy.ObjectDatabaseSettings, "config_statuses": policy.ObjectDatabasePublic, diff --git a/schema/config_properties.hcl b/schema/config_properties.hcl new file mode 100644 index 000000000..22410ba7b --- /dev/null +++ b/schema/config_properties.hcl @@ -0,0 +1,94 @@ +table "config_properties" { + schema = schema.public + column "id" { + null = false + type = uuid + default = sql("generate_ulid()") + } + column "config_id" { + null = false + type = uuid + } + column "scraper_id" { + null = false + type = uuid + } + column "label" { + null = false + type = text + } + column "tooltip" { + null = true + type = text + } + column "icon" { + null = true + type = text + } + column "type" { + null = true + type = text + } + column "color" { + null = true + type = text + } + column "order" { + null = true + type = int + } + column "text" { + null = true + type = text + } + column "value" { + null = true + type = numeric(16, 4) + } + column "unit" { + null = true + type = text + } + column "max" { + null = true + type = bigint + } + column "min" { + null = true + type = bigint + } + column "created_at" { + null = false + type = timestamptz + default = sql("now()") + } + column "updated_at" { + null = false + type = timestamptz + default = sql("now()") + } + primary_key { + columns = [column.id] + } + foreign_key "config_properties_config_id_fkey" { + columns = [column.config_id] + ref_columns = [table.config_items.column.id] + on_update = CASCADE + on_delete = CASCADE + } + foreign_key "config_properties_scraper_id_fkey" { + columns = [column.scraper_id] + ref_columns = [table.config_scrapers.column.id] + on_update = CASCADE + on_delete = CASCADE + } + index "config_properties_config_id_idx" { + columns = [column.config_id] + } + index "config_properties_scraper_id_idx" { + columns = [column.scraper_id] + } + check "config_property_text_or_value" { + expr = "(text IS NOT NULL AND value IS NULL) OR (text IS NULL AND value IS NOT NULL)" + } +} \ No newline at end of file