add username data to updates table
This commit is contained in:
9
db/migrations/20240926022714_updates_user.sql
Normal file
9
db/migrations/20240926022714_updates_user.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE "Updates" ADD COLUMN UserName TEXT;
|
||||||
|
-- +goose StatementEnd
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
-- +goose StatementBegin
|
||||||
|
ALTER TABLE "Updates" DROP COLUMN UserName;
|
||||||
|
-- +goose StatementEnd
|
@@ -59,4 +59,5 @@ type Updates struct {
|
|||||||
EventKey sql.NullString
|
EventKey sql.NullString
|
||||||
EventId sql.NullString
|
EventId sql.NullString
|
||||||
NewProvisionedDisk sql.NullFloat64
|
NewProvisionedDisk sql.NullFloat64
|
||||||
|
UserName sql.NullString
|
||||||
}
|
}
|
||||||
|
@@ -29,9 +29,9 @@ WHERE "VmId" = sqlc.arg('vmId') AND "Datacenter" = sqlc.arg('datacenterName');
|
|||||||
|
|
||||||
-- name: CreateUpdate :one
|
-- name: CreateUpdate :one
|
||||||
INSERT INTO "Updates" (
|
INSERT INTO "Updates" (
|
||||||
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk"
|
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName"
|
||||||
) 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
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName
|
||||||
`
|
`
|
||||||
|
|
||||||
type CleanupUpdatesParams struct {
|
type CleanupUpdatesParams struct {
|
||||||
@@ -162,11 +162,11 @@ func (q *Queries) CreateInventory(ctx context.Context, arg CreateInventoryParams
|
|||||||
|
|
||||||
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"
|
"InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk", "UserName"
|
||||||
) VALUES(
|
) VALUES(
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||||
)
|
)
|
||||||
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateUpdateParams struct {
|
type CreateUpdateParams struct {
|
||||||
@@ -179,6 +179,7 @@ type CreateUpdateParams struct {
|
|||||||
NewRam sql.NullInt64
|
NewRam sql.NullInt64
|
||||||
NewResourcePool sql.NullString
|
NewResourcePool sql.NullString
|
||||||
NewProvisionedDisk sql.NullFloat64
|
NewProvisionedDisk sql.NullFloat64
|
||||||
|
UserName sql.NullString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
|
||||||
@@ -192,6 +193,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
|
|||||||
arg.NewRam,
|
arg.NewRam,
|
||||||
arg.NewResourcePool,
|
arg.NewResourcePool,
|
||||||
arg.NewProvisionedDisk,
|
arg.NewProvisionedDisk,
|
||||||
|
arg.UserName,
|
||||||
)
|
)
|
||||||
var i Updates
|
var i Updates
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
@@ -205,6 +207,7 @@ func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Upd
|
|||||||
&i.EventKey,
|
&i.EventKey,
|
||||||
&i.EventId,
|
&i.EventId,
|
||||||
&i.NewProvisionedDisk,
|
&i.NewProvisionedDisk,
|
||||||
|
&i.UserName,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
@@ -164,6 +164,7 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
|||||||
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}
|
||||||
|
params.UserName = sql.NullString{String: event.CloudEvent.Data.UserName, Valid: event.CloudEvent.Data.UserName != ""}
|
||||||
|
|
||||||
// Create the Update database record
|
// Create the Update database record
|
||||||
result, err := h.Database.Queries().CreateUpdate(context.Background(), params)
|
result, err := h.Database.Queries().CreateUpdate(context.Background(), params)
|
||||||
|
@@ -27,7 +27,7 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
|||||||
mux.HandleFunc("/api/event/vm/delete", h.VmDelete)
|
mux.HandleFunc("/api/event/vm/delete", h.VmDelete)
|
||||||
mux.HandleFunc("/api/import/vm", h.VmImport)
|
mux.HandleFunc("/api/import/vm", h.VmImport)
|
||||||
// temporary endpoint
|
// temporary endpoint
|
||||||
mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
|
//mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
|
||||||
|
|
||||||
return middleware.NewLoggingMiddleware(logger, mux)
|
return middleware.NewLoggingMiddleware(logger, mux)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user