b31d8d0096
- Added migration to harden task audit tracking by modifying audit_logs and related tables. - Introduced operator_id to several tables for better tracking of actions. - Updated article_templates with new prompt templates for various article types, enhancing content generation. - Created prompt_rules and schedule_tasks tables to manage content generation rules and scheduling. - Added foreign key constraints to articles for better data integrity.
120 lines
3.1 KiB
Go
120 lines
3.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: audit.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createAuditLog = `-- name: CreateAuditLog :exec
|
|
INSERT INTO audit_logs (
|
|
operator_id,
|
|
tenant_id,
|
|
module,
|
|
action,
|
|
resource_type,
|
|
resource_id,
|
|
request_id,
|
|
before_json,
|
|
after_json,
|
|
result,
|
|
error_message
|
|
)
|
|
VALUES ($1, $2, $3, $4,
|
|
$5, $6, $7,
|
|
$8, $9, $10, $11)
|
|
`
|
|
|
|
type CreateAuditLogParams struct {
|
|
OperatorID int64 `json:"operator_id"`
|
|
TenantID pgtype.Int8 `json:"tenant_id"`
|
|
Module string `json:"module"`
|
|
Action string `json:"action"`
|
|
ResourceType pgtype.Text `json:"resource_type"`
|
|
ResourceID pgtype.Int8 `json:"resource_id"`
|
|
RequestID pgtype.Text `json:"request_id"`
|
|
BeforeJson []byte `json:"before_json"`
|
|
AfterJson []byte `json:"after_json"`
|
|
Result pgtype.Text `json:"result"`
|
|
ErrorMessage pgtype.Text `json:"error_message"`
|
|
}
|
|
|
|
func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams) error {
|
|
_, err := q.db.Exec(ctx, createAuditLog,
|
|
arg.OperatorID,
|
|
arg.TenantID,
|
|
arg.Module,
|
|
arg.Action,
|
|
arg.ResourceType,
|
|
arg.ResourceID,
|
|
arg.RequestID,
|
|
arg.BeforeJson,
|
|
arg.AfterJson,
|
|
arg.Result,
|
|
arg.ErrorMessage,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const createGenerationTask = `-- name: CreateGenerationTask :one
|
|
INSERT INTO generation_tasks (tenant_id, operator_id, article_id, quota_reservation_id, task_type, input_params_json, status)
|
|
VALUES ($1, $2, $3, $4,
|
|
$5, $6, 'queued')
|
|
RETURNING id
|
|
`
|
|
|
|
type CreateGenerationTaskParams struct {
|
|
TenantID int64 `json:"tenant_id"`
|
|
OperatorID pgtype.Int8 `json:"operator_id"`
|
|
ArticleID pgtype.Int8 `json:"article_id"`
|
|
QuotaReservationID pgtype.Int8 `json:"quota_reservation_id"`
|
|
TaskType string `json:"task_type"`
|
|
InputParamsJson []byte `json:"input_params_json"`
|
|
}
|
|
|
|
func (q *Queries) CreateGenerationTask(ctx context.Context, arg CreateGenerationTaskParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, createGenerationTask,
|
|
arg.TenantID,
|
|
arg.OperatorID,
|
|
arg.ArticleID,
|
|
arg.QuotaReservationID,
|
|
arg.TaskType,
|
|
arg.InputParamsJson,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const updateGenerationTaskStatus = `-- name: UpdateGenerationTaskStatus :exec
|
|
UPDATE generation_tasks SET status = $1, error_message = $2,
|
|
started_at = $3, completed_at = $4, updated_at = NOW()
|
|
WHERE id = $5 AND tenant_id = $6
|
|
`
|
|
|
|
type UpdateGenerationTaskStatusParams struct {
|
|
Status string `json:"status"`
|
|
ErrorMessage pgtype.Text `json:"error_message"`
|
|
StartedAt pgtype.Timestamptz `json:"started_at"`
|
|
CompletedAt pgtype.Timestamptz `json:"completed_at"`
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateGenerationTaskStatus(ctx context.Context, arg UpdateGenerationTaskStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateGenerationTaskStatus,
|
|
arg.Status,
|
|
arg.ErrorMessage,
|
|
arg.StartedAt,
|
|
arg.CompletedAt,
|
|
arg.ID,
|
|
arg.TenantID,
|
|
)
|
|
return err
|
|
}
|