From 7b600b2359be7ce2478f3012d8fd93a3010a606e Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 14 Jan 2026 10:07:06 +1100 Subject: [PATCH] updates --- db/queries/models.go | 121 ++++++++++++++-------------- db/queries/query.sql.go | 134 ++++++++++++++++---------------- server/router/docs/docs.go | 57 ++++++++++++++ server/router/docs/swagger.json | 57 ++++++++++++++ server/router/docs/swagger.yaml | 39 ++++++++++ 5 files changed, 284 insertions(+), 124 deletions(-) diff --git a/db/queries/models.go b/db/queries/models.go index b39c939..382821d 100644 --- a/db/queries/models.go +++ b/db/queries/models.go @@ -9,70 +9,77 @@ import ( ) type Event struct { - Eid int64 - CloudId string - Source string - EventTime sql.NullInt64 - ChainId string - VmId sql.NullString - EventKey sql.NullString - DatacenterName sql.NullString - ComputeResourceName sql.NullString - UserName sql.NullString - Processed int64 - DatacenterId sql.NullString - ComputeResourceId sql.NullString - VmName sql.NullString - EventType sql.NullString + Eid int64 `db:"Eid" json:"Eid"` + CloudId string `db:"CloudId" json:"CloudId"` + Source string `db:"Source" json:"Source"` + EventTime sql.NullInt64 `db:"EventTime" json:"EventTime"` + ChainId string `db:"ChainId" json:"ChainId"` + VmId sql.NullString `db:"VmId" json:"VmId"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + DatacenterName sql.NullString `db:"DatacenterName" json:"DatacenterName"` + ComputeResourceName sql.NullString `db:"ComputeResourceName" json:"ComputeResourceName"` + UserName sql.NullString `db:"UserName" json:"UserName"` + Processed int64 `db:"Processed" json:"Processed"` + DatacenterId sql.NullString `db:"DatacenterId" json:"DatacenterId"` + ComputeResourceId sql.NullString `db:"ComputeResourceId" json:"ComputeResourceId"` + VmName sql.NullString `db:"VmName" json:"VmName"` + EventType sql.NullString `db:"EventType" json:"EventType"` } type Inventory struct { - Iid int64 - Name string - Vcenter string - VmId sql.NullString - EventKey sql.NullString - CloudId sql.NullString - CreationTime sql.NullInt64 - DeletionTime sql.NullInt64 - ResourcePool sql.NullString - VmType sql.NullString - Datacenter sql.NullString - Cluster sql.NullString - Folder sql.NullString - ProvisionedDisk sql.NullFloat64 - InitialVcpus sql.NullInt64 - InitialRam sql.NullInt64 - IsTemplate interface{} - PoweredOn interface{} - SrmPlaceholder interface{} - VmUuid sql.NullString + Iid int64 `db:"Iid" json:"Iid"` + Name string `db:"Name" json:"Name"` + Vcenter string `db:"Vcenter" json:"Vcenter"` + VmId sql.NullString `db:"VmId" json:"VmId"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + CloudId sql.NullString `db:"CloudId" json:"CloudId"` + CreationTime sql.NullInt64 `db:"CreationTime" json:"CreationTime"` + DeletionTime sql.NullInt64 `db:"DeletionTime" json:"DeletionTime"` + ResourcePool sql.NullString `db:"ResourcePool" json:"ResourcePool"` + VmType sql.NullString `db:"VmType" json:"VmType"` + Datacenter sql.NullString `db:"Datacenter" json:"Datacenter"` + Cluster sql.NullString `db:"Cluster" json:"Cluster"` + Folder sql.NullString `db:"Folder" json:"Folder"` + ProvisionedDisk sql.NullFloat64 `db:"ProvisionedDisk" json:"ProvisionedDisk"` + InitialVcpus sql.NullInt64 `db:"InitialVcpus" json:"InitialVcpus"` + InitialRam sql.NullInt64 `db:"InitialRam" json:"InitialRam"` + IsTemplate interface{} `db:"IsTemplate" json:"IsTemplate"` + PoweredOn interface{} `db:"PoweredOn" json:"PoweredOn"` + SrmPlaceholder interface{} `db:"SrmPlaceholder" json:"SrmPlaceholder"` + VmUuid sql.NullString `db:"VmUuid" json:"VmUuid"` } type InventoryHistory struct { - Hid int64 - InventoryId sql.NullInt64 - ReportDate sql.NullInt64 - UpdateTime sql.NullInt64 - PreviousVcpus sql.NullInt64 - PreviousRam sql.NullInt64 - PreviousResourcePool sql.NullString - PreviousProvisionedDisk sql.NullFloat64 + Hid int64 `db:"Hid" json:"Hid"` + InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"` + ReportDate sql.NullInt64 `db:"ReportDate" json:"ReportDate"` + UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"` + PreviousVcpus sql.NullInt64 `db:"PreviousVcpus" json:"PreviousVcpus"` + PreviousRam sql.NullInt64 `db:"PreviousRam" json:"PreviousRam"` + PreviousResourcePool sql.NullString `db:"PreviousResourcePool" json:"PreviousResourcePool"` + PreviousProvisionedDisk sql.NullFloat64 `db:"PreviousProvisionedDisk" json:"PreviousProvisionedDisk"` +} + +type SnapshotRegistry struct { + ID int64 `db:"id" json:"id"` + SnapshotType string `db:"snapshot_type" json:"snapshot_type"` + TableName string `db:"table_name" json:"table_name"` + SnapshotTime int64 `db:"snapshot_time" json:"snapshot_time"` } type Update struct { - Uid int64 - InventoryId sql.NullInt64 - UpdateTime sql.NullInt64 - UpdateType string - NewVcpus sql.NullInt64 - NewRam sql.NullInt64 - NewResourcePool sql.NullString - EventKey sql.NullString - EventId sql.NullString - NewProvisionedDisk sql.NullFloat64 - UserName sql.NullString - PlaceholderChange sql.NullString - Name sql.NullString - RawChangeString []byte + Uid int64 `db:"Uid" json:"Uid"` + InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"` + UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"` + UpdateType string `db:"UpdateType" json:"UpdateType"` + NewVcpus sql.NullInt64 `db:"NewVcpus" json:"NewVcpus"` + NewRam sql.NullInt64 `db:"NewRam" json:"NewRam"` + NewResourcePool sql.NullString `db:"NewResourcePool" json:"NewResourcePool"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + EventId sql.NullString `db:"EventId" json:"EventId"` + NewProvisionedDisk sql.NullFloat64 `db:"NewProvisionedDisk" json:"NewProvisionedDisk"` + UserName sql.NullString `db:"UserName" json:"UserName"` + PlaceholderChange sql.NullString `db:"PlaceholderChange" json:"PlaceholderChange"` + Name sql.NullString `db:"Name" json:"Name"` + RawChangeString []byte `db:"RawChangeString" json:"RawChangeString"` } diff --git a/db/queries/query.sql.go b/db/queries/query.sql.go index 6a0339b..61c01f0 100644 --- a/db/queries/query.sql.go +++ b/db/queries/query.sql.go @@ -17,8 +17,8 @@ RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourc ` type CleanupUpdatesParams struct { - UpdateType string - UpdateTime sql.NullInt64 + UpdateType string `db:"updateType" json:"updateType"` + UpdateTime sql.NullInt64 `db:"updateTime" json:"updateTime"` } func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams) error { @@ -47,19 +47,19 @@ RETURNING Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterNa ` type CreateEventParams struct { - CloudId string - Source string - EventTime sql.NullInt64 - ChainId string - VmId sql.NullString - VmName sql.NullString - EventType sql.NullString - EventKey sql.NullString - DatacenterId sql.NullString - DatacenterName sql.NullString - ComputeResourceId sql.NullString - ComputeResourceName sql.NullString - UserName sql.NullString + CloudId string `db:"CloudId" json:"CloudId"` + Source string `db:"Source" json:"Source"` + EventTime sql.NullInt64 `db:"EventTime" json:"EventTime"` + ChainId string `db:"ChainId" json:"ChainId"` + VmId sql.NullString `db:"VmId" json:"VmId"` + VmName sql.NullString `db:"VmName" json:"VmName"` + EventType sql.NullString `db:"EventType" json:"EventType"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + DatacenterId sql.NullString `db:"DatacenterId" json:"DatacenterId"` + DatacenterName sql.NullString `db:"DatacenterName" json:"DatacenterName"` + ComputeResourceId sql.NullString `db:"ComputeResourceId" json:"ComputeResourceId"` + ComputeResourceName sql.NullString `db:"ComputeResourceName" json:"ComputeResourceName"` + UserName sql.NullString `db:"UserName" json:"UserName"` } func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Event, error) { @@ -109,24 +109,24 @@ RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTim ` type CreateInventoryParams struct { - Name string - Vcenter string - VmId sql.NullString - VmUuid sql.NullString - EventKey sql.NullString - CloudId sql.NullString - CreationTime sql.NullInt64 - ResourcePool sql.NullString - VmType sql.NullString - IsTemplate interface{} - Datacenter sql.NullString - Cluster sql.NullString - Folder sql.NullString - ProvisionedDisk sql.NullFloat64 - InitialVcpus sql.NullInt64 - InitialRam sql.NullInt64 - SrmPlaceholder interface{} - PoweredOn interface{} + Name string `db:"Name" json:"Name"` + Vcenter string `db:"Vcenter" json:"Vcenter"` + VmId sql.NullString `db:"VmId" json:"VmId"` + VmUuid sql.NullString `db:"VmUuid" json:"VmUuid"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + CloudId sql.NullString `db:"CloudId" json:"CloudId"` + CreationTime sql.NullInt64 `db:"CreationTime" json:"CreationTime"` + ResourcePool sql.NullString `db:"ResourcePool" json:"ResourcePool"` + VmType sql.NullString `db:"VmType" json:"VmType"` + IsTemplate interface{} `db:"IsTemplate" json:"IsTemplate"` + Datacenter sql.NullString `db:"Datacenter" json:"Datacenter"` + Cluster sql.NullString `db:"Cluster" json:"Cluster"` + Folder sql.NullString `db:"Folder" json:"Folder"` + ProvisionedDisk sql.NullFloat64 `db:"ProvisionedDisk" json:"ProvisionedDisk"` + InitialVcpus sql.NullInt64 `db:"InitialVcpus" json:"InitialVcpus"` + InitialRam sql.NullInt64 `db:"InitialRam" json:"InitialRam"` + SrmPlaceholder interface{} `db:"SrmPlaceholder" json:"SrmPlaceholder"` + PoweredOn interface{} `db:"PoweredOn" json:"PoweredOn"` } func (q *Queries) CreateInventory(ctx context.Context, arg CreateInventoryParams) (Inventory, error) { @@ -186,13 +186,13 @@ RETURNING Hid, InventoryId, ReportDate, UpdateTime, PreviousVcpus, PreviousRam, ` type CreateInventoryHistoryParams struct { - InventoryId sql.NullInt64 - ReportDate sql.NullInt64 - UpdateTime sql.NullInt64 - PreviousVcpus sql.NullInt64 - PreviousRam sql.NullInt64 - PreviousResourcePool sql.NullString - PreviousProvisionedDisk sql.NullFloat64 + InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"` + ReportDate sql.NullInt64 `db:"ReportDate" json:"ReportDate"` + UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"` + PreviousVcpus sql.NullInt64 `db:"PreviousVcpus" json:"PreviousVcpus"` + PreviousRam sql.NullInt64 `db:"PreviousRam" json:"PreviousRam"` + PreviousResourcePool sql.NullString `db:"PreviousResourcePool" json:"PreviousResourcePool"` + PreviousProvisionedDisk sql.NullFloat64 `db:"PreviousProvisionedDisk" json:"PreviousProvisionedDisk"` } func (q *Queries) CreateInventoryHistory(ctx context.Context, arg CreateInventoryHistoryParams) (InventoryHistory, error) { @@ -229,19 +229,19 @@ RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourc ` type CreateUpdateParams struct { - InventoryId sql.NullInt64 - Name sql.NullString - EventKey sql.NullString - EventId sql.NullString - UpdateTime sql.NullInt64 - UpdateType string - NewVcpus sql.NullInt64 - NewRam sql.NullInt64 - NewResourcePool sql.NullString - NewProvisionedDisk sql.NullFloat64 - UserName sql.NullString - PlaceholderChange sql.NullString - RawChangeString []byte + InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"` + Name sql.NullString `db:"Name" json:"Name"` + EventKey sql.NullString `db:"EventKey" json:"EventKey"` + EventId sql.NullString `db:"EventId" json:"EventId"` + UpdateTime sql.NullInt64 `db:"UpdateTime" json:"UpdateTime"` + UpdateType string `db:"UpdateType" json:"UpdateType"` + NewVcpus sql.NullInt64 `db:"NewVcpus" json:"NewVcpus"` + NewRam sql.NullInt64 `db:"NewRam" json:"NewRam"` + NewResourcePool sql.NullString `db:"NewResourcePool" json:"NewResourcePool"` + NewProvisionedDisk sql.NullFloat64 `db:"NewProvisionedDisk" json:"NewProvisionedDisk"` + UserName sql.NullString `db:"UserName" json:"UserName"` + PlaceholderChange sql.NullString `db:"PlaceholderChange" json:"PlaceholderChange"` + RawChangeString []byte `db:"RawChangeString" json:"RawChangeString"` } func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Update, error) { @@ -466,8 +466,8 @@ WHERE "VmId" = ?1 AND "Datacenter" = ?2 ` type GetInventoryVmIdParams struct { - VmId sql.NullString - DatacenterName sql.NullString + VmId sql.NullString `db:"vmId" json:"vmId"` + DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"` } func (q *Queries) GetInventoryVmId(ctx context.Context, arg GetInventoryVmIdParams) (Inventory, error) { @@ -504,8 +504,8 @@ WHERE "VmUuid" = ?1 AND "Datacenter" = ?2 ` type GetInventoryVmUuidParams struct { - VmUuid sql.NullString - DatacenterName sql.NullString + VmUuid sql.NullString `db:"vmUuid" json:"vmUuid"` + DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"` } func (q *Queries) GetInventoryVmUuid(ctx context.Context, arg GetInventoryVmUuidParams) (Inventory, error) { @@ -634,8 +634,8 @@ WHERE "UpdateType" = ?1 AND "InventoryId" = ?2 ` type GetVmUpdatesParams struct { - UpdateType string - InventoryId sql.NullInt64 + UpdateType string `db:"updateType" json:"updateType"` + InventoryId sql.NullInt64 `db:"InventoryId" json:"InventoryId"` } func (q *Queries) GetVmUpdates(ctx context.Context, arg GetVmUpdatesParams) ([]Update, error) { @@ -683,8 +683,8 @@ RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTim ` type InventoryCleanupParams struct { - VmId sql.NullString - DatacenterName sql.NullString + VmId sql.NullString `db:"vmId" json:"vmId"` + DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"` } func (q *Queries) InventoryCleanup(ctx context.Context, arg InventoryCleanupParams) error { @@ -721,9 +721,9 @@ WHERE "VmId" = ?2 AND "Datacenter" = ?3 ` type InventoryMarkDeletedParams struct { - DeletionTime sql.NullInt64 - VmId sql.NullString - DatacenterName sql.NullString + DeletionTime sql.NullInt64 `db:"deletionTime" json:"deletionTime"` + VmId sql.NullString `db:"vmId" json:"vmId"` + DatacenterName sql.NullString `db:"datacenterName" json:"datacenterName"` } func (q *Queries) InventoryMarkDeleted(ctx context.Context, arg InventoryMarkDeletedParams) error { @@ -738,9 +738,9 @@ WHERE "Iid" = ?3 ` type InventoryUpdateParams struct { - Uuid sql.NullString - SrmPlaceholder interface{} - Iid int64 + Uuid sql.NullString `db:"uuid" json:"uuid"` + SrmPlaceholder interface{} `db:"srmPlaceholder" json:"srmPlaceholder"` + Iid int64 `db:"iid" json:"iid"` } func (q *Queries) InventoryUpdate(ctx context.Context, arg InventoryUpdateParams) error { diff --git a/server/router/docs/docs.go b/server/router/docs/docs.go index 3e6b1e6..c3ef816 100644 --- a/server/router/docs/docs.go +++ b/server/router/docs/docs.go @@ -584,6 +584,63 @@ const docTemplate = `{ } } }, + "/api/snapshots/aggregate": { + "post": { + "description": "Forces regeneration of a daily or monthly summary table for a specified date or month.", + "produces": [ + "application/json" + ], + "tags": [ + "snapshots" + ], + "summary": "Force snapshot aggregation", + "parameters": [ + { + "type": "string", + "description": "Aggregation type: daily or monthly", + "name": "type", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Daily date (YYYY-MM-DD) or monthly date (YYYY-MM)", + "name": "date", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Aggregation complete", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Invalid request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Server error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, "/snapshots/daily": { "get": { "description": "Lists daily summary snapshot tables.", diff --git a/server/router/docs/swagger.json b/server/router/docs/swagger.json index 4fb3fa4..0008260 100644 --- a/server/router/docs/swagger.json +++ b/server/router/docs/swagger.json @@ -573,6 +573,63 @@ } } }, + "/api/snapshots/aggregate": { + "post": { + "description": "Forces regeneration of a daily or monthly summary table for a specified date or month.", + "produces": [ + "application/json" + ], + "tags": [ + "snapshots" + ], + "summary": "Force snapshot aggregation", + "parameters": [ + { + "type": "string", + "description": "Aggregation type: daily or monthly", + "name": "type", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "Daily date (YYYY-MM-DD) or monthly date (YYYY-MM)", + "name": "date", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Aggregation complete", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Invalid request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Server error", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, "/snapshots/daily": { "get": { "description": "Lists daily summary snapshot tables.", diff --git a/server/router/docs/swagger.yaml b/server/router/docs/swagger.yaml index 193708d..b467e43 100644 --- a/server/router/docs/swagger.yaml +++ b/server/router/docs/swagger.yaml @@ -530,6 +530,45 @@ paths: summary: Download updates report tags: - reports + /api/snapshots/aggregate: + post: + description: Forces regeneration of a daily or monthly summary table for a specified + date or month. + parameters: + - description: 'Aggregation type: daily or monthly' + in: query + name: type + required: true + type: string + - description: Daily date (YYYY-MM-DD) or monthly date (YYYY-MM) + in: query + name: date + required: true + type: string + produces: + - application/json + responses: + "200": + description: Aggregation complete + schema: + additionalProperties: + type: string + type: object + "400": + description: Invalid request + schema: + additionalProperties: + type: string + type: object + "500": + description: Server error + schema: + additionalProperties: + type: string + type: object + summary: Force snapshot aggregation + tags: + - snapshots /snapshots/daily: get: description: Lists daily summary snapshot tables.