add raw string to database
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-02 13:37:59 +10:00
parent f94339446d
commit f9b8e25c2f
6 changed files with 24 additions and 9 deletions

View File

@@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE "Updates" ADD COLUMN RawChangeString BLOB;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE "Updates" DROP COLUMN RawChangeString;
-- +goose StatementEnd

View File

@@ -74,4 +74,5 @@ type Updates struct {
UserName sql.NullString UserName sql.NullString
PlaceholderChange sql.NullString PlaceholderChange sql.NullString
Name sql.NullString Name sql.NullString
RawChangeString []byte
} }

View File

@@ -60,9 +60,9 @@ RETURNING *;
-- name: CreateUpdate :one -- name: CreateUpdate :one
INSERT INTO "Updates" ( INSERT INTO "Updates" (
"InventoryId", "Name", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange" "InventoryId", "Name", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange", "RawChangeString"
) VALUES( ) VALUES(
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
) )
RETURNING *; RETURNING *;

View File

@@ -13,7 +13,7 @@ import (
const cleanupUpdates = `-- name: CleanupUpdates :exec const cleanupUpdates = `-- name: CleanupUpdates :exec
DELETE FROM "Updates" DELETE FROM "Updates"
WHERE "UpdateType" = ?1 AND "UpdateTime" <= ?2 WHERE "UpdateType" = ?1 AND "UpdateTime" <= ?2
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString
` `
type CleanupUpdatesParams struct { type CleanupUpdatesParams struct {
@@ -29,7 +29,7 @@ func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams)
const cleanupUpdatesNullVm = `-- name: CleanupUpdatesNullVm :exec const cleanupUpdatesNullVm = `-- name: CleanupUpdatesNullVm :exec
DELETE FROM "Updates" DELETE FROM "Updates"
WHERE "InventoryId" IS NULL WHERE "InventoryId" IS NULL
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString
` `
func (q *Queries) CleanupUpdatesNullVm(ctx context.Context) error { func (q *Queries) CleanupUpdatesNullVm(ctx context.Context) error {
@@ -221,11 +221,11 @@ func (q *Queries) CreateInventoryHistory(ctx context.Context, arg CreateInventor
const createUpdate = `-- name: CreateUpdate :one const createUpdate = `-- name: CreateUpdate :one
INSERT INTO "Updates" ( INSERT INTO "Updates" (
"InventoryId", "Name", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange" "InventoryId", "Name", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange", "RawChangeString"
) VALUES( ) VALUES(
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
) )
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString
` `
type CreateUpdateParams struct { type CreateUpdateParams struct {
@@ -241,6 +241,7 @@ type CreateUpdateParams struct {
NewProvisionedDisk sql.NullFloat64 NewProvisionedDisk sql.NullFloat64
UserName sql.NullString UserName sql.NullString
PlaceholderChange sql.NullString PlaceholderChange sql.NullString
RawChangeString []byte
} }
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) { func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
@@ -257,6 +258,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
arg.NewProvisionedDisk, arg.NewProvisionedDisk,
arg.UserName, arg.UserName,
arg.PlaceholderChange, arg.PlaceholderChange,
arg.RawChangeString,
) )
var i Updates var i Updates
err := row.Scan( err := row.Scan(
@@ -273,6 +275,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
&i.UserName, &i.UserName,
&i.PlaceholderChange, &i.PlaceholderChange,
&i.Name, &i.Name,
&i.RawChangeString,
) )
return i, err return i, err
} }
@@ -583,7 +586,7 @@ func (q *Queries) GetReportInventory(ctx context.Context) ([]Inventory, error) {
} }
const getReportUpdates = `-- name: GetReportUpdates :many const getReportUpdates = `-- name: GetReportUpdates :many
SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name FROM "Updates" SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name, RawChangeString FROM "Updates"
ORDER BY "UpdateTime" ORDER BY "UpdateTime"
` `
@@ -610,6 +613,7 @@ func (q *Queries) GetReportUpdates(ctx context.Context) ([]Updates, error) {
&i.UserName, &i.UserName,
&i.PlaceholderChange, &i.PlaceholderChange,
&i.Name, &i.Name,
&i.RawChangeString,
); err != nil { ); err != nil {
return nil, err return nil, err
} }

View File

@@ -197,6 +197,7 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
// populate other parameters for the Update database record // populate other parameters for the Update database record
params.Name = sql.NullString{String: event.CloudEvent.Data.VM.Name, Valid: event.CloudEvent.Data.VM.Name != ""} params.Name = sql.NullString{String: event.CloudEvent.Data.VM.Name, Valid: event.CloudEvent.Data.VM.Name != ""}
params.RawChangeString = []byte(event.CloudEvent.Data.ConfigChanges.Modified)
params.EventId = sql.NullString{String: event.CloudEvent.ID, Valid: event.CloudEvent.ID != ""} params.EventId = sql.NullString{String: event.CloudEvent.ID, Valid: event.CloudEvent.ID != ""}
params.EventKey = sql.NullString{String: strconv.Itoa(event.CloudEvent.Data.Key), Valid: event.CloudEvent.Data.Key > 0} params.EventKey = sql.NullString{String: strconv.Itoa(event.CloudEvent.Data.Key), Valid: event.CloudEvent.Data.Key > 0}
params.UpdateTime = sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0} params.UpdateTime = sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0}

View File

@@ -41,7 +41,7 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
//mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails) //mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails)
// temporary endpoint // temporary endpoint
mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup) //mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
//mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup) //mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup)
mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload) mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)