feat(migrations): Harden task audit tracking and optimize article templates

- 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.
This commit is contained in:
2026-04-02 00:31:28 +08:00
parent de30497f59
commit b31d8d0096
101 changed files with 16671 additions and 721 deletions
@@ -12,19 +12,36 @@ import (
)
const createAuditLog = `-- name: CreateAuditLog :exec
INSERT INTO audit_logs (operator_id, tenant_id, module, action, before_json, after_json, result)
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)
$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"`
BeforeJson []byte `json:"before_json"`
AfterJson []byte `json:"after_json"`
Result pgtype.Text `json:"result"`
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 {
@@ -33,22 +50,27 @@ func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams)
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, article_id, quota_reservation_id, task_type, input_params_json, status)
VALUES ($1, $2, $3,
$4, $5, 'queued')
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"`
@@ -58,6 +80,7 @@ type CreateGenerationTaskParams struct {
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,