minor adjustments
This commit is contained in:
9
db/migrations/20241001222729_add_placeholder.sql
Normal file
9
db/migrations/20241001222729_add_placeholder.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE "Updates" ADD COLUMN PlaceholderChange TEXT;
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE "Updates" DROP COLUMN PlaceholderChange;
|
||||||
|
-- +goose StatementEnd
|
@@ -72,4 +72,5 @@ type Updates struct {
|
|||||||
EventId sql.NullString
|
EventId sql.NullString
|
||||||
NewProvisionedDisk sql.NullFloat64
|
NewProvisionedDisk sql.NullFloat64
|
||||||
UserName sql.NullString
|
UserName sql.NullString
|
||||||
|
PlaceholderChange sql.NullString
|
||||||
}
|
}
|
||||||
|
@@ -60,9 +60,9 @@ RETURNING *;
|
|||||||
|
|
||||||
-- name: CreateUpdate :one
|
-- name: CreateUpdate :one
|
||||||
INSERT INTO "Updates" (
|
INSERT INTO "Updates" (
|
||||||
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName"
|
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange"
|
||||||
) VALUES(
|
) VALUES(
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||||
)
|
)
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
|
@@ -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
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange
|
||||||
`
|
`
|
||||||
|
|
||||||
type CleanupUpdatesParams struct {
|
type CleanupUpdatesParams struct {
|
||||||
@@ -210,11 +210,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", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName"
|
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName", "PlaceholderChange"
|
||||||
) VALUES(
|
) VALUES(
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||||
)
|
)
|
||||||
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateUpdateParams struct {
|
type CreateUpdateParams struct {
|
||||||
@@ -228,6 +228,7 @@ type CreateUpdateParams struct {
|
|||||||
NewResourcePool sql.NullString
|
NewResourcePool sql.NullString
|
||||||
NewProvisionedDisk sql.NullFloat64
|
NewProvisionedDisk sql.NullFloat64
|
||||||
UserName sql.NullString
|
UserName sql.NullString
|
||||||
|
PlaceholderChange sql.NullString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
||||||
@@ -242,6 +243,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
|
|||||||
arg.NewResourcePool,
|
arg.NewResourcePool,
|
||||||
arg.NewProvisionedDisk,
|
arg.NewProvisionedDisk,
|
||||||
arg.UserName,
|
arg.UserName,
|
||||||
|
arg.PlaceholderChange,
|
||||||
)
|
)
|
||||||
var i Updates
|
var i Updates
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
@@ -256,6 +258,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
|
|||||||
&i.EventId,
|
&i.EventId,
|
||||||
&i.NewProvisionedDisk,
|
&i.NewProvisionedDisk,
|
||||||
&i.UserName,
|
&i.UserName,
|
||||||
|
&i.PlaceholderChange,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -566,7 +569,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 FROM "Updates"
|
SELECT Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange FROM "Updates"
|
||||||
ORDER BY "UpdateTime"
|
ORDER BY "UpdateTime"
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -591,6 +594,7 @@ func (q *Queries) GetReportUpdates(ctx context.Context) ([]Updates, error) {
|
|||||||
&i.EventId,
|
&i.EventId,
|
||||||
&i.NewProvisionedDisk,
|
&i.NewProvisionedDisk,
|
||||||
&i.UserName,
|
&i.UserName,
|
||||||
|
&i.PlaceholderChange,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -113,10 +113,12 @@ func CreateInventoryReport(logger *slog.Logger, Database db.Database, ctx contex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set column autowidth
|
// Set column autowidth
|
||||||
|
/*
|
||||||
err = SetColAutoWidth(xlsx, sheetName)
|
err = SetColAutoWidth(xlsx, sheetName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error setting auto width : '%s'\n", err)
|
fmt.Printf("Error setting auto width : '%s'\n", err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Save the Excel file into a byte buffer
|
// Save the Excel file into a byte buffer
|
||||||
if err := xlsx.Write(&buffer); err != nil {
|
if err := xlsx.Write(&buffer); err != nil {
|
||||||
@@ -224,10 +226,12 @@ func CreateUpdatesReport(logger *slog.Logger, Database db.Database, ctx context.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set column autowidth
|
// Set column autowidth
|
||||||
|
/*
|
||||||
err = SetColAutoWidth(xlsx, sheetName)
|
err = SetColAutoWidth(xlsx, sheetName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error setting auto width : '%s'\n", err)
|
fmt.Printf("Error setting auto width : '%s'\n", err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Save the Excel file into a byte buffer
|
// Save the Excel file into a byte buffer
|
||||||
if err := xlsx.Write(&buffer); err != nil {
|
if err := xlsx.Write(&buffer); err != nil {
|
||||||
|
@@ -164,7 +164,14 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Logger.Error("unable to find existing inventory record for this VM", "error", err)
|
h.Logger.Error("unable to find existing inventory record for this VM", "error", err)
|
||||||
// TODO - how to handle?
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
|
"status": "ERROR",
|
||||||
|
"message": fmt.Sprintf("Valid request but could not locate vm id '%s' and datacenter name '%s' within inventory table : %s",
|
||||||
|
event.CloudEvent.Data.VM.VM.Value, event.CloudEvent.Data.Datacenter.Name, err),
|
||||||
|
})
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
params.InventoryId = sql.NullInt64{Int64: invResult.Iid, Valid: invResult.Iid > 0}
|
params.InventoryId = sql.NullInt64{Int64: invResult.Iid, Valid: invResult.Iid > 0}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user