Skip to content

Commit

Permalink
fix: create index by clusterId in clusterpolicy reports
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry committed May 29, 2024
1 parent 6f01c37 commit 7270616
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/storage/db/cpolr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ type cpolrdb struct {
}

func NewClusterPolicyReportStore(db *sql.DB, clusterId string) (api.ClusterPolicyReportsInterface, error) {
_, err := db.Exec("CREATE TABLE IF NOT EXISTS clusterpolicyreports (name VARCHAR NOT NULL, clusterId VARCHAR NOT NULL, report JSONB NOT NULL, PRIMARY KEY(name))")
_, err := db.Exec("CREATE TABLE IF NOT EXISTS clusterpolicyreports (name VARCHAR NOT NULL, clusterId VARCHAR NOT NULL, report JSONB NOT NULL, PRIMARY KEY(name, clusterId))")
if err != nil {
klog.ErrorS(err, "failed to create table")
return nil, err
}

_, err = db.Exec("CREATE INDEX IF NOT EXISTS clusterpolicyreportcluster ON clusterpolicyreports(clusterId)")
if err != nil {
klog.ErrorS(err, "failed to create index")
return nil, err
}

return &cpolrdb{db: db, clusterId: clusterId}, nil
}

Expand Down

0 comments on commit 7270616

Please sign in to comment.