enhance implementation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
30
db/migrations/20250324011119_extend_incidents.sql
Normal file
30
db/migrations/20250324011119_extend_incidents.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
ALTER TABLE incidents ADD COLUMN incident_number TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN description TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN short_description TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN urgency INTEGER;
|
||||
ALTER TABLE incidents ADD COLUMN impact INTEGER;
|
||||
ALTER TABLE incidents ADD COLUMN state INTEGER;
|
||||
-- ALTER TABLE incidents ADD COLUMN work_notes TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN assignment_group TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN assigned_to TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN category TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN subcategory TEXT;
|
||||
ALTER TABLE incidents ADD COLUMN sys_id TEXT;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
ALTER TABLE incidents DROP COLUMN incident_number;
|
||||
ALTER TABLE incidents DROP COLUMN description;
|
||||
ALTER TABLE incidents DROP COLUMN short_description;
|
||||
ALTER TABLE incidents DROP COLUMN urgency;
|
||||
ALTER TABLE incidents DROP COLUMN impact;
|
||||
ALTER TABLE incidents DROP COLUMN state;
|
||||
ALTER TABLE incidents DROP COLUMN assignment_group;
|
||||
ALTER TABLE incidents DROP COLUMN assigned_to;
|
||||
ALTER TABLE incidents DROP COLUMN category;
|
||||
ALTER TABLE incidents DROP COLUMN subcategory;
|
||||
ALTER TABLE incidents DROP COLUMN sys_id;
|
||||
-- +goose StatementEnd
|
13
db/migrations/20250324011340_worknotes.sql
Normal file
13
db/migrations/20250324011340_worknotes.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE worknotes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
incident_number TEXT NOT NULL, -- must map to an incidents.incident_number
|
||||
note TEXT
|
||||
);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE IF EXISTS worknotes;
|
||||
-- +goose StatementEnd
|
@@ -9,9 +9,20 @@ import (
|
||||
)
|
||||
|
||||
type Incident struct {
|
||||
ID int64
|
||||
ExternalID string
|
||||
CreatedAt sql.NullTime
|
||||
ID int64
|
||||
ExternalID string
|
||||
CreatedAt sql.NullTime
|
||||
IncidentNumber sql.NullString
|
||||
Description sql.NullString
|
||||
ShortDescription sql.NullString
|
||||
Urgency sql.NullInt64
|
||||
Impact sql.NullInt64
|
||||
State sql.NullInt64
|
||||
AssignmentGroup sql.NullString
|
||||
AssignedTo sql.NullString
|
||||
Category sql.NullString
|
||||
Subcategory sql.NullString
|
||||
SysID sql.NullString
|
||||
}
|
||||
|
||||
type Incoming struct {
|
||||
@@ -30,3 +41,9 @@ type Incoming struct {
|
||||
Subcategory sql.NullString
|
||||
CreatedAt sql.NullTime
|
||||
}
|
||||
|
||||
type Worknote struct {
|
||||
ID int64
|
||||
IncidentNumber string
|
||||
Note sql.NullString
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
SELECT * FROM "Incoming"
|
||||
ORDER BY "id";
|
||||
|
||||
|
||||
-- name: CreateIncoming :one
|
||||
INSERT INTO "Incoming" (
|
||||
"incident_number", "description", "short_description", "urgency", "impact", "state", "external_id", "work_notes", "assignment_group", "assigned_to", "category", "subcategory", "created_at"
|
||||
@@ -12,6 +11,49 @@ INSERT INTO "Incoming" (
|
||||
RETURNING *;
|
||||
|
||||
-- name: CreateIncident :one
|
||||
INSERT INTO incidents (external_id)
|
||||
VALUES (?)
|
||||
RETURNING id;
|
||||
INSERT INTO incidents (
|
||||
"description", "short_description", "urgency", "impact", "state", "external_id", "assignment_group", "assigned_to", "category", "subcategory", "created_at", "sys_id"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: UpdateIncidentNumber :exec
|
||||
UPDATE incidents
|
||||
SET incident_number = sqlc.arg('incidentNumber')
|
||||
WHERE external_id = sqlc.arg('externalId');
|
||||
|
||||
-- name: UpdateIncidentState :exec
|
||||
UPDATE incidents
|
||||
SET state = sqlc.arg('state')
|
||||
WHERE incident_number = sqlc.arg('incidentNumber');
|
||||
|
||||
-- name: UpdateIncident :exec
|
||||
UPDATE incidents
|
||||
SET
|
||||
external_id = ?,
|
||||
description = ?,
|
||||
short_description = ?,
|
||||
urgency = ?,
|
||||
impact = ?,
|
||||
state = ?,
|
||||
assignment_group = ?,
|
||||
assigned_to = ?,
|
||||
category = ?,
|
||||
subcategory = ?
|
||||
WHERE incident_number = ?;
|
||||
|
||||
-- name: GetIncident :one
|
||||
SELECT * from incidents
|
||||
WHERE incident_number = sqlc.arg('incidentNumber');
|
||||
|
||||
-- name: ListIncidents :many
|
||||
SELECT * FROM incidents;
|
||||
|
||||
-- name: CreateWorkNote :one
|
||||
INSERT into worknotes (
|
||||
"incident_number", "note"
|
||||
) VALUES(
|
||||
?, ?
|
||||
)
|
||||
RETURNING *;
|
@@ -11,16 +11,62 @@ import (
|
||||
)
|
||||
|
||||
const createIncident = `-- name: CreateIncident :one
|
||||
INSERT INTO incidents (external_id)
|
||||
VALUES (?)
|
||||
RETURNING id
|
||||
INSERT INTO incidents (
|
||||
"description", "short_description", "urgency", "impact", "state", "external_id", "assignment_group", "assigned_to", "category", "subcategory", "created_at", "sys_id"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_id
|
||||
`
|
||||
|
||||
func (q *Queries) CreateIncident(ctx context.Context, externalID string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, createIncident, externalID)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
type CreateIncidentParams struct {
|
||||
Description sql.NullString
|
||||
ShortDescription sql.NullString
|
||||
Urgency sql.NullInt64
|
||||
Impact sql.NullInt64
|
||||
State sql.NullInt64
|
||||
ExternalID string
|
||||
AssignmentGroup sql.NullString
|
||||
AssignedTo sql.NullString
|
||||
Category sql.NullString
|
||||
Subcategory sql.NullString
|
||||
CreatedAt sql.NullTime
|
||||
SysID sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateIncident(ctx context.Context, arg CreateIncidentParams) (Incident, error) {
|
||||
row := q.db.QueryRowContext(ctx, createIncident,
|
||||
arg.Description,
|
||||
arg.ShortDescription,
|
||||
arg.Urgency,
|
||||
arg.Impact,
|
||||
arg.State,
|
||||
arg.ExternalID,
|
||||
arg.AssignmentGroup,
|
||||
arg.AssignedTo,
|
||||
arg.Category,
|
||||
arg.Subcategory,
|
||||
arg.CreatedAt,
|
||||
arg.SysID,
|
||||
)
|
||||
var i Incident
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ExternalID,
|
||||
&i.CreatedAt,
|
||||
&i.IncidentNumber,
|
||||
&i.Description,
|
||||
&i.ShortDescription,
|
||||
&i.Urgency,
|
||||
&i.Impact,
|
||||
&i.State,
|
||||
&i.AssignmentGroup,
|
||||
&i.AssignedTo,
|
||||
&i.Category,
|
||||
&i.Subcategory,
|
||||
&i.SysID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createIncoming = `-- name: CreateIncoming :one
|
||||
@@ -84,6 +130,96 @@ func (q *Queries) CreateIncoming(ctx context.Context, arg CreateIncomingParams)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createWorkNote = `-- name: CreateWorkNote :one
|
||||
INSERT into worknotes (
|
||||
"incident_number", "note"
|
||||
) VALUES(
|
||||
?, ?
|
||||
)
|
||||
RETURNING id, incident_number, note
|
||||
`
|
||||
|
||||
type CreateWorkNoteParams struct {
|
||||
IncidentNumber string
|
||||
Note sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateWorkNote(ctx context.Context, arg CreateWorkNoteParams) (Worknote, error) {
|
||||
row := q.db.QueryRowContext(ctx, createWorkNote, arg.IncidentNumber, arg.Note)
|
||||
var i Worknote
|
||||
err := row.Scan(&i.ID, &i.IncidentNumber, &i.Note)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getIncident = `-- name: GetIncident :one
|
||||
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_id from incidents
|
||||
WHERE incident_number = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) GetIncident(ctx context.Context, incidentnumber sql.NullString) (Incident, error) {
|
||||
row := q.db.QueryRowContext(ctx, getIncident, incidentnumber)
|
||||
var i Incident
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ExternalID,
|
||||
&i.CreatedAt,
|
||||
&i.IncidentNumber,
|
||||
&i.Description,
|
||||
&i.ShortDescription,
|
||||
&i.Urgency,
|
||||
&i.Impact,
|
||||
&i.State,
|
||||
&i.AssignmentGroup,
|
||||
&i.AssignedTo,
|
||||
&i.Category,
|
||||
&i.Subcategory,
|
||||
&i.SysID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listIncidents = `-- name: ListIncidents :many
|
||||
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_id FROM incidents
|
||||
`
|
||||
|
||||
func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listIncidents)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Incident
|
||||
for rows.Next() {
|
||||
var i Incident
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ExternalID,
|
||||
&i.CreatedAt,
|
||||
&i.IncidentNumber,
|
||||
&i.Description,
|
||||
&i.ShortDescription,
|
||||
&i.Urgency,
|
||||
&i.Impact,
|
||||
&i.State,
|
||||
&i.AssignmentGroup,
|
||||
&i.AssignedTo,
|
||||
&i.Category,
|
||||
&i.Subcategory,
|
||||
&i.SysID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listIncoming = `-- name: ListIncoming :many
|
||||
SELECT id, incident_number, description, short_description, urgency, impact, state, external_id, work_notes, assignment_group, assigned_to, category, subcategory, created_at FROM "Incoming"
|
||||
ORDER BY "id"
|
||||
@@ -126,3 +262,35 @@ func (q *Queries) ListIncoming(ctx context.Context) ([]Incoming, error) {
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateIncidentNumber = `-- name: UpdateIncidentNumber :exec
|
||||
UPDATE incidents
|
||||
SET incident_number = ?1
|
||||
WHERE external_id = ?2
|
||||
`
|
||||
|
||||
type UpdateIncidentNumberParams struct {
|
||||
IncidentNumber sql.NullString
|
||||
ExternalId string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncidentNumber(ctx context.Context, arg UpdateIncidentNumberParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateIncidentNumber, arg.IncidentNumber, arg.ExternalId)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateIncidentState = `-- name: UpdateIncidentState :exec
|
||||
UPDATE incidents
|
||||
SET state = ?1
|
||||
WHERE incident_number = ?2
|
||||
`
|
||||
|
||||
type UpdateIncidentStateParams struct {
|
||||
State sql.NullInt64
|
||||
IncidentNumber sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncidentState(ctx context.Context, arg UpdateIncidentStateParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateIncidentState, arg.State, arg.IncidentNumber)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user