add SysUpdatedOn
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-26 13:19:34 +11:00
parent bb999afbb7
commit 6581164fc4
6 changed files with 40 additions and 19 deletions

View File

@@ -0,0 +1,10 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE incidents ADD COLUMN updated_at DATETIME;
UPDATE incidents SET updated_at = CURRENT_TIMESTAMP WHERE updated_at IS NULL;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE incidents DROP COLUMN updated_at;
-- +goose StatementEnd

View File

@@ -23,6 +23,7 @@ type Incident struct {
Category sql.NullString
SubCategory sql.NullString
SysID sql.NullString
UpdatedAt sql.NullTime
}
type Incoming struct {

View File

@@ -30,7 +30,7 @@ WHERE sys_id = sqlc.arg('sysId');
-- name: UpdateIncidentState :exec
UPDATE incidents
SET state = sqlc.arg('state')
SET state = sqlc.arg('state'), updated_at = CURRENT_TIMESTAMP
WHERE incident_number = sqlc.arg('incidentNumber');
-- name: UpdateIncident :exec
@@ -45,7 +45,8 @@ SET
assignment_group = ?,
assigned_to = ?,
category = ?,
sub_category = ?
sub_category = ?,
updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?;
-- name: GetIncident :one

View File

@@ -16,7 +16,7 @@ INSERT INTO incidents (
) VALUES(
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at
`
type CreateIncidentParams struct {
@@ -65,6 +65,7 @@ func (q *Queries) CreateIncident(ctx context.Context, arg CreateIncidentParams)
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
)
return i, err
}
@@ -157,7 +158,7 @@ func (q *Queries) CreateWorkNote(ctx context.Context, arg CreateWorkNoteParams)
}
const getIncident = `-- name: GetIncident :one
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id from incidents
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at from incidents
WHERE incident_number = ?1
`
@@ -179,12 +180,13 @@ func (q *Queries) GetIncident(ctx context.Context, incidentnumber sql.NullString
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
)
return i, err
}
const getIncidentReport = `-- name: GetIncidentReport :many
SELECT incidents.id, incidents.external_id, incidents.created_at, incidents.incident_number, incidents.description, incidents.short_description, incidents.urgency, incidents.impact, incidents.state, incidents.assignment_group, incidents.assigned_to, incidents.category, incidents.sub_category, incidents.sys_id, IFNULL(GROUP_CONCAT(worknotes.note, '<br />'), ' ') AS all_notes
SELECT incidents.id, incidents.external_id, incidents.created_at, incidents.incident_number, incidents.description, incidents.short_description, incidents.urgency, incidents.impact, incidents.state, incidents.assignment_group, incidents.assigned_to, incidents.category, incidents.sub_category, incidents.sys_id, incidents.updated_at, IFNULL(GROUP_CONCAT(worknotes.note, '<br />'), ' ') AS all_notes
FROM incidents LEFT JOIN worknotes ON incidents.incident_number = worknotes.incident_number
GROUP BY incidents.id
`
@@ -204,6 +206,7 @@ type GetIncidentReportRow struct {
Category sql.NullString
SubCategory sql.NullString
SysID sql.NullString
UpdatedAt sql.NullTime
AllNotes interface{}
}
@@ -231,6 +234,7 @@ func (q *Queries) GetIncidentReport(ctx context.Context) ([]GetIncidentReportRow
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
&i.AllNotes,
); err != nil {
return nil, err
@@ -280,7 +284,7 @@ func (q *Queries) GetIncidentWorkNotes(ctx context.Context, incidentnumber strin
}
const listIncidents = `-- name: ListIncidents :many
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id FROM incidents
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at FROM incidents
`
func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
@@ -307,6 +311,7 @@ func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
); err != nil {
return nil, err
}
@@ -408,7 +413,8 @@ SET
assignment_group = ?,
assigned_to = ?,
category = ?,
sub_category = ?
sub_category = ?,
updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?
`
@@ -477,7 +483,7 @@ func (q *Queries) UpdateIncidentNumberSysId(ctx context.Context, arg UpdateIncid
const updateIncidentState = `-- name: UpdateIncidentState :exec
UPDATE incidents
SET state = ?1
SET state = ?1, updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?2
`