Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions models/config_properties.go
Original file line number Diff line number Diff line change
@@ -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"`
Comment thread
adityathebe marked this conversation as resolved.
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"}}
}
1 change: 1 addition & 0 deletions rbac/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
94 changes: 94 additions & 0 deletions schema/config_properties.hcl
Original file line number Diff line number Diff line change
@@ -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)"
}
}
Loading