Skip to content

Commit

Permalink
chore: remove agent_id from relationship tables
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed May 15, 2023
1 parent fb25486 commit 9afc236
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 68 deletions.
19 changes: 9 additions & 10 deletions models/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ func (u Uptime) String() string {
}

type CheckStatus struct {
CheckID uuid.UUID `json:"check_id"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
Status bool `json:"status"`
Invalid bool `json:"invalid,omitempty"`
Time string `json:"time"`
Duration int `json:"duration"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Detail any `json:"-" gorm:"-"`
CreatedAt time.Time `json:"created_at,omitempty"`
CheckID uuid.UUID `json:"check_id"`
Status bool `json:"status"`
Invalid bool `json:"invalid,omitempty"`
Time string `json:"time"`
Duration int `json:"duration"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Detail any `json:"-" gorm:"-"`
CreatedAt time.Time `json:"created_at,omitempty"`
}

func (s CheckStatus) GetTime() (time.Time, error) {
Expand Down
2 changes: 0 additions & 2 deletions models/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ type ComponentRelationship struct {
RelationshipID uuid.UUID `gorm:"column:relationship_id" json:"relationship_id,omitempty"`
SelectorID string `gorm:"column:selector_id" json:"selector_id,omitempty"`
RelationshipPath string `gorm:"column:relationship_path" json:"relationship_path,omitempty"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at,omitempty"`
DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at,omitempty"`
Expand All @@ -424,7 +423,6 @@ type ConfigComponentRelationship struct {
ComponentID uuid.UUID `gorm:"column:component_id" json:"component_id,omitempty"`
ConfigID uuid.UUID `gorm:"column:config_id" json:"config_id,omitempty"`
SelectorID string `gorm:"column:selector_id" json:"selector_id,omitempty"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at,omitempty"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at,omitempty"`
DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (c ConfigItem) GetSelectorID() string {
type ConfigScraper struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
Description string `json:"description,omitempty"`
Spec string `json:"spec,omitempty"`
CreatedBy *uuid.UUID `json:"created_by,omitempty"`
Expand All @@ -106,7 +105,6 @@ func (cs *ConfigScraper) BeforeCreate(tx *gorm.DB) error {
}

type ConfigRelationship struct {
AgentID *uuid.UUID `json:"agent_id,omitempty"`
ConfigID string `gorm:"column:config_id" json:"config_id"`
RelatedID string `gorm:"column:related_id" json:"related_id"`
Relation string `gorm:"column:relation" json:"relation"`
Expand All @@ -126,7 +124,6 @@ type ConfigChange struct {
ConfigType string `gorm:"-"`
ExternalChangeId string `gorm:"column:external_change_id" json:"external_change_id"`
ID string `gorm:"primaryKey;unique_index;not null;column:id" json:"id"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
ConfigID string `gorm:"column:config_id;default:''" json:"config_id"`
ChangeType string `gorm:"column:change_type" json:"change_type" faker:"oneof: RunInstances, diff" `
Severity string `gorm:"column:severity" json:"severity" faker:"oneof: critical, high, medium, low, info"`
Expand Down Expand Up @@ -166,7 +163,6 @@ func (c *ConfigChange) BeforeCreate(tx *gorm.DB) error {

type ConfigAnalysis struct {
ID uuid.UUID `gorm:"primaryKey;unique_index;not null;column:id" json:"id"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
ExternalID string `gorm:"-"`
ConfigType string `gorm:"-"`
ConfigID uuid.UUID `gorm:"column:config_id;default:''" json:"config_id"`
Expand Down
4 changes: 2 additions & 2 deletions schema/agents.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ table "agents" {
columns = [column.id]
}

index "agents_name_hostname_key" {
index "agents_name_key" {
unique = true
columns = [column.name, column.hostname]
columns = [column.name]
}

foreign_key "agents_created_by_fkey" {
Expand Down
10 changes: 0 additions & 10 deletions schema/checks.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ table "check_statuses" {
null = false
type = uuid
}
column "agent_id" {
null = true
type = uuid
}
column "details" {
null = true
type = jsonb
Expand Down Expand Up @@ -119,12 +115,6 @@ table "check_statuses" {
on_update = NO_ACTION
on_delete = CASCADE
}
foreign_key "check_statuses_agent_id_fkey" {
columns = [column.agent_id]
ref_columns = [table.agents.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
index "check_statuses_time_brin_idx" {
type = BRIN
columns = [column.time]
Expand Down
21 changes: 1 addition & 20 deletions schema/components.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ table "component_relationships" {
null = true
type = text
}
column "agent_id" {
null = true
type = uuid
}

foreign_key "component_relationships_component_id_fkey" {
columns = [column.component_id]
Expand All @@ -108,18 +104,13 @@ table "component_relationships" {
on_update = NO_ACTION
on_delete = NO_ACTION
}
foreign_key "component_relationships_agent_id_fkey" {
columns = [column.agent_id]
ref_columns = [table.agents.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}

index "component_relationships_component_id_relationship_id_select_key" {
unique = true
columns = [column.component_id, column.relationship_id, column.selector_id]
}
}

table "components" {
schema = schema.public
column "id" {
Expand Down Expand Up @@ -376,10 +367,6 @@ table "config_component_relationships" {
null = false
type = uuid
}
column "agent_id" {
null = true
type = uuid
}
column "created_at" {
null = false
type = timestamptz
Expand Down Expand Up @@ -410,12 +397,6 @@ table "config_component_relationships" {
on_update = NO_ACTION
on_delete = NO_ACTION
}
foreign_key "config_component_relationships_agent_id_fkey" {
columns = [column.agent_id]
ref_columns = [table.agents.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
index "config_component_relationships_component_id_config_id_key" {
unique = true
columns = [column.component_id, column.config_id]
Expand Down
20 changes: 0 additions & 20 deletions schema/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ table "config_analysis" {
null = false
type = uuid
}
column "agent_id" {
null = true
type = uuid
}
column "created_by" {
null = true
type = uuid
Expand Down Expand Up @@ -73,12 +69,6 @@ table "config_analysis" {
on_update = NO_ACTION
on_delete = NO_ACTION
}
foreign_key "config_analysis_agent_id_fkey" {
columns = [column.agent_id]
ref_columns = [table.agents.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
}

table "config_changes" {
Expand All @@ -92,10 +82,6 @@ table "config_changes" {
null = false
type = uuid
}
column "agent_id" {
null = true
type = uuid
}
column "external_change_id" {
null = true
type = text
Expand Down Expand Up @@ -150,12 +136,6 @@ table "config_changes" {
on_update = NO_ACTION
on_delete = NO_ACTION
}
foreign_key "config_changes_agent_id_fkey" {
columns = [column.agent_id]
ref_columns = [table.agents.column.id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
index "config_changes_config_id_external_change_id_key" {
unique = true
columns = [column.config_id, column.external_change_id]
Expand Down

0 comments on commit 9afc236

Please sign in to comment.