Skip to content

Commit

Permalink
Delete favorites for deleted resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 8, 2025
1 parent a1c4b0d commit 5dcbb9d
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/schema/v1/cron_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CronJob struct {
Annotations []Annotation `db:"-"`
CronJobAnnotations []CronJobAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type CronJobLabel struct {
Expand Down Expand Up @@ -129,5 +130,6 @@ func (c *CronJob) Relations() []database.Relation {
database.HasMany(c.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(c.Annotations, database.WithoutCascadeDelete()),
database.HasMany(c.CronJobAnnotations, fk),
database.HasMany(c.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DaemonSet struct {
Annotations []Annotation `db:"-"`
DaemonSetAnnotations []DaemonSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type DaemonSetCondition struct {
Expand Down Expand Up @@ -216,5 +217,6 @@ func (d *DaemonSet) Relations() []database.Relation {
database.HasMany(d.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(d.Annotations, database.WithoutCascadeDelete()),
database.HasMany(d.DaemonSetAnnotations, fk),
database.HasMany(d.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Deployment struct {
Annotations []Annotation `db:"-"`
DeploymentAnnotations []DeploymentAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type DeploymentCondition struct {
Expand Down Expand Up @@ -235,5 +236,6 @@ func (d *Deployment) Relations() []database.Relation {
database.HasMany(d.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(d.Annotations, database.WithoutCascadeDelete()),
database.HasMany(d.DeploymentAnnotations, fk),
database.HasMany(d.Favorites, database.WithForeignKey("resource_uuid")),
}
}
8 changes: 8 additions & 0 deletions pkg/schema/v1/favorite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package v1

import "github.com/icinga/icinga-go-library/types"

type Favorite struct {
ResourceUuid types.UUID
Username string
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Ingress struct {
Annotations []Annotation `db:"-"`
IngressAnnotations []IngressAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type IngressTls struct {
Expand Down Expand Up @@ -228,5 +229,6 @@ func (i *Ingress) Relations() []database.Relation {
database.HasMany(i.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(i.Annotations, database.WithoutCascadeDelete()),
database.HasMany(i.IngressAnnotations, fk),
database.HasMany(i.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Job struct {
JobAnnotations []JobAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Owners []JobOwner `db:"-"`
Favorites []Favorite `db:"-"`
}

type JobCondition struct {
Expand Down Expand Up @@ -287,5 +288,6 @@ func (j *Job) Relations() []database.Relation {
database.HasMany(j.Annotations, database.WithoutCascadeDelete()),
database.HasMany(j.JobAnnotations, fk),
database.HasMany(j.Owners, fk),
database.HasMany(j.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Namespace struct {
Annotations []Annotation `db:"-"`
NamespaceAnnotations []NamespaceAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type NamespaceCondition struct {
Expand Down Expand Up @@ -117,5 +118,6 @@ func (n *Namespace) Relations() []database.Relation {
database.HasMany(n.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(n.Annotations, database.WithoutCascadeDelete()),
database.HasMany(n.NamespaceAnnotations, fk),
database.HasMany(n.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Node struct {
Annotations []Annotation `db:"-"`
NodeAnnotations []NodeAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type NodeCondition struct {
Expand Down Expand Up @@ -267,6 +268,7 @@ func (n *Node) Relations() []database.Relation {
database.HasMany(n.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(n.Annotations, database.WithoutCascadeDelete()),
database.HasMany(n.NodeAnnotations, fk),
database.HasMany(n.Favorites, database.WithForeignKey("resource_uuid")),
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/v1/persistent_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type PersistentVolume struct {
Annotations []Annotation `db:"-"`
PersistentVolumeAnnotations []PersistentVolumeAnnotation `db:"-"`
ResourceAnnotations []PersistentVolumeAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type PersistentVolumeClaimRef struct {
Expand Down Expand Up @@ -147,5 +148,6 @@ func (p *PersistentVolume) Relations() []database.Relation {
database.HasMany(p.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(p.Annotations, database.WithoutCascadeDelete()),
database.HasMany(p.PersistentVolumeAnnotations, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Pod struct {
ResourceAnnotations []ResourceAnnotation `db:"-"`
Pvcs []PodPvc `db:"-"`
Volumes []PodVolume `db:"-"`
Favorites []Favorite `db:"-"`
factory *PodFactory
}

Expand Down Expand Up @@ -459,6 +460,7 @@ func (p *Pod) Relations() []database.Relation {
database.HasMany(p.PodAnnotations, fk),
database.HasMany(p.Pvcs, fk),
database.HasMany(p.Volumes, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/v1/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Pvc struct {
Annotations []Annotation `db:"-"`
PvcAnnotations []PvcAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type PvcCondition struct {
Expand Down Expand Up @@ -172,5 +173,6 @@ func (p *Pvc) Relations() []database.Relation {
database.HasMany(p.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(p.Annotations, database.WithoutCascadeDelete()),
database.HasMany(p.PvcAnnotations, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ReplicaSet struct {
Annotations []Annotation `db:"-"`
ReplicaSetAnnotations []ReplicaSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type ReplicaSetCondition struct {
Expand Down Expand Up @@ -217,5 +218,6 @@ func (r *ReplicaSet) Relations() []database.Relation {
database.HasMany(r.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(r.Annotations, database.WithoutCascadeDelete()),
database.HasMany(r.ReplicaSetAnnotations, fk),
database.HasMany(r.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Service struct {
ServiceAnnotations []ServiceAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
ServicePods []ServicePod `db:"-"`
Favorites []Favorite `db:"-"`
factory *ServiceFactory
}

Expand Down Expand Up @@ -257,5 +258,6 @@ func (s *Service) Relations() []database.Relation {
database.HasMany(s.ServiceAnnotations, fk),
database.HasMany(s.ResourceAnnotations, fk),
database.HasMany(s.ServicePods, fk),
database.HasMany(s.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/stateful_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type StatefulSet struct {
Annotations []Annotation `db:"-"`
StatefulSetAnnotations []StatefulSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type StatefulSetCondition struct {
Expand Down Expand Up @@ -234,5 +235,6 @@ func (s *StatefulSet) Relations() []database.Relation {
database.HasMany(s.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(s.Annotations, database.WithoutCascadeDelete()),
database.HasMany(s.StatefulSetAnnotations, fk),
database.HasMany(s.Favorites, database.WithForeignKey("resource_uuid")),
}
}

0 comments on commit 5dcbb9d

Please sign in to comment.