From d3b75a3c9c144790c19a276eba6b7dd78c3fc2ca Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Fri, 29 Nov 2024 15:18:14 +0545 Subject: [PATCH] feat: scrape plugins --- models/scrape_plugin.go | 20 +++++++++++++ schema/config.hcl | 65 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 models/scrape_plugin.go diff --git a/models/scrape_plugin.go b/models/scrape_plugin.go new file mode 100644 index 00000000..c13f8fde --- /dev/null +++ b/models/scrape_plugin.go @@ -0,0 +1,20 @@ +package models + +import ( + "time" + + "github.com/flanksource/duty/types" + "github.com/google/uuid" +) + +type ScrapePlugin struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + Namespace string `json:"namespace"` + Spec types.JSON `json:"spec,omitempty"` + Source string `json:"source,omitempty"` + CreatedBy *uuid.UUID `json:"created_by,omitempty"` + CreatedAt time.Time `json:"created_at" gorm:"<-:create"` + UpdatedAt *time.Time `json:"updated_at" gorm:"autoUpdateTime:false"` + DeletedAt *time.Time `json:"deleted_at,omitempty"` +} diff --git a/schema/config.hcl b/schema/config.hcl index cc4767f3..2606d6f3 100644 --- a/schema/config.hcl +++ b/schema/config.hcl @@ -38,8 +38,8 @@ table "config_analysis" { type = text } column "status" { - null = true - type = text + null = true + type = text default = "open" } column "message" { @@ -182,8 +182,8 @@ table "config_changes" { comment = "is_pushed when set to true indicates that the config changes has been pushed to upstream." } column "inserted_at" { - null = false - type = timestamptz + null = false + type = timestamptz default = sql("now()") } @@ -352,8 +352,8 @@ table "config_items" { type = text } column "inserted_at" { - null = false - type = timestamptz + null = false + type = timestamptz default = sql("now()") } primary_key { @@ -405,7 +405,7 @@ table "config_items" { } index "idx_config_items_scraper_id_deleted_at_null" { columns = [column.scraper_id] - where = "deleted_at IS NULL" + where = "deleted_at IS NULL" } index "idx_config_items_path" { columns = [column.path] @@ -616,3 +616,54 @@ table "config_scrapers" { where = "is_pushed IS FALSE" } } + +table "scrape_plugins" { + schema = schema.public + column "id" { + null = false + type = uuid + default = sql("generate_ulid()") + } + column "name" { + type = text + } + column "namespace" { + null = true + type = text + } + column "spec" { + null = false + type = jsonb + } + column "source" { + null = false + type = enum.source + } + column "created_by" { + null = true + type = uuid + } + column "created_at" { + null = false + type = timestamptz + default = sql("now()") + } + column "updated_at" { + null = true + type = timestamptz + default = sql("now()") + } + column "deleted_at" { + null = true + type = timestamptz + } + primary_key { + columns = [column.id] + } + foreign_key "config_scraper_plugins_created_by_fkey" { + columns = [column.created_by] + ref_columns = [table.people.column.id] + on_update = NO_ACTION + on_delete = NO_ACTION + } +}