Remove PRD/doc paths, bead IDs, phase notes and deleted-test references from comments; drop test-only hooks left by the test deletion. Includes in-progress archied bootstrap, gateway and query changes.
99 lines
2.3 KiB
Go
99 lines
2.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: audit.sql
|
|
|
|
package postgresdb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const auditForRecords = `-- name: AuditForRecords :many
|
|
SELECT id, at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id
|
|
FROM sys_audit
|
|
WHERE table_name = $1::text AND record_key = ANY($2::text[])
|
|
ORDER BY id DESC
|
|
LIMIT $3::bigint
|
|
`
|
|
|
|
type AuditForRecordsParams struct {
|
|
TableName string
|
|
RecordKeys []string
|
|
EntryLimit int64
|
|
}
|
|
|
|
func (q *Queries) AuditForRecords(ctx context.Context, arg AuditForRecordsParams) ([]SysAudit, error) {
|
|
rows, err := q.db.Query(ctx, auditForRecords, arg.TableName, arg.RecordKeys, arg.EntryLimit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []SysAudit
|
|
for rows.Next() {
|
|
var i SysAudit
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.At,
|
|
&i.TableName,
|
|
&i.RecordKey,
|
|
&i.Field,
|
|
&i.OldValue,
|
|
&i.NewValue,
|
|
&i.RecordVersion,
|
|
&i.Actor,
|
|
&i.Source,
|
|
&i.RequestID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const insertResourceAudit = `-- name: InsertResourceAudit :exec
|
|
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
|
SELECT $1::timestamptz, 'resources', $2::text, d.field, d.old_value, d.new_value,
|
|
$3::bigint, $4::text, $5::text, $6::text
|
|
FROM audit_json_diff(
|
|
(SELECT convert_from(h.value, 'UTF8')::jsonb FROM resource_history h
|
|
WHERE h.org_id = $7::text AND h.kind = $8::text AND h.version = $9::bigint),
|
|
convert_from($10::bytea, 'UTF8')::jsonb
|
|
) d
|
|
ORDER BY d.field
|
|
`
|
|
|
|
type InsertResourceAuditParams struct {
|
|
At time.Time
|
|
RecordKey string
|
|
Version int64
|
|
Actor string
|
|
Source string
|
|
RequestID string
|
|
OrgID string
|
|
Kind string
|
|
PreviousVersion int64
|
|
Value []byte
|
|
}
|
|
|
|
func (q *Queries) InsertResourceAudit(ctx context.Context, arg InsertResourceAuditParams) error {
|
|
_, err := q.db.Exec(ctx, insertResourceAudit,
|
|
arg.At,
|
|
arg.RecordKey,
|
|
arg.Version,
|
|
arg.Actor,
|
|
arg.Source,
|
|
arg.RequestID,
|
|
arg.OrgID,
|
|
arg.Kind,
|
|
arg.PreviousVersion,
|
|
arg.Value,
|
|
)
|
|
return err
|
|
}
|