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:
@@ -0,0 +1,290 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: schedule_task.sql
|
||||
|
||||
package generated
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countScheduleTasks = `-- name: CountScheduleTasks :one
|
||||
SELECT COUNT(*)
|
||||
FROM schedule_tasks
|
||||
WHERE tenant_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND ($2::text IS NULL OR status = $2)
|
||||
AND ($3::bigint IS NULL OR prompt_rule_id = $3)
|
||||
`
|
||||
|
||||
type CountScheduleTasksParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountScheduleTasks(ctx context.Context, arg CountScheduleTasksParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countScheduleTasks, arg.TenantID, arg.Status, arg.PromptRuleID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createScheduleTask = `-- name: CreateScheduleTask :one
|
||||
INSERT INTO schedule_tasks (tenant_id, prompt_rule_id, brand_id, name, cron_expr,
|
||||
target_platform, start_at, end_at, next_run_at)
|
||||
VALUES ($1, $2, $3, $4,
|
||||
$5, $6, $7, $8,
|
||||
$9)
|
||||
RETURNING id, created_at
|
||||
`
|
||||
|
||||
type CreateScheduleTaskParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
PromptRuleID int64 `json:"prompt_rule_id"`
|
||||
BrandID pgtype.Int8 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CronExpr string `json:"cron_expr"`
|
||||
TargetPlatform pgtype.Text `json:"target_platform"`
|
||||
StartAt pgtype.Timestamptz `json:"start_at"`
|
||||
EndAt pgtype.Timestamptz `json:"end_at"`
|
||||
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
||||
}
|
||||
|
||||
type CreateScheduleTaskRow struct {
|
||||
ID int64 `json:"id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateScheduleTask(ctx context.Context, arg CreateScheduleTaskParams) (CreateScheduleTaskRow, error) {
|
||||
row := q.db.QueryRow(ctx, createScheduleTask,
|
||||
arg.TenantID,
|
||||
arg.PromptRuleID,
|
||||
arg.BrandID,
|
||||
arg.Name,
|
||||
arg.CronExpr,
|
||||
arg.TargetPlatform,
|
||||
arg.StartAt,
|
||||
arg.EndAt,
|
||||
arg.NextRunAt,
|
||||
)
|
||||
var i CreateScheduleTaskRow
|
||||
err := row.Scan(&i.ID, &i.CreatedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getScheduleTaskByID = `-- name: GetScheduleTaskByID :one
|
||||
SELECT st.id, st.tenant_id, st.prompt_rule_id, st.brand_id, st.name,
|
||||
st.cron_expr, st.target_platform, st.start_at, st.end_at,
|
||||
st.next_run_at, st.status, st.created_at, st.updated_at,
|
||||
pr.name AS prompt_rule_name,
|
||||
b.name AS brand_name
|
||||
FROM schedule_tasks st
|
||||
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
||||
LEFT JOIN brands b ON b.id = st.brand_id
|
||||
WHERE st.id = $1 AND st.tenant_id = $2 AND st.deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetScheduleTaskByIDParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
type GetScheduleTaskByIDRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
PromptRuleID int64 `json:"prompt_rule_id"`
|
||||
BrandID pgtype.Int8 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CronExpr string `json:"cron_expr"`
|
||||
TargetPlatform pgtype.Text `json:"target_platform"`
|
||||
StartAt pgtype.Timestamptz `json:"start_at"`
|
||||
EndAt pgtype.Timestamptz `json:"end_at"`
|
||||
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
PromptRuleName pgtype.Text `json:"prompt_rule_name"`
|
||||
BrandName pgtype.Text `json:"brand_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetScheduleTaskByID(ctx context.Context, arg GetScheduleTaskByIDParams) (GetScheduleTaskByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getScheduleTaskByID, arg.ID, arg.TenantID)
|
||||
var i GetScheduleTaskByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.PromptRuleID,
|
||||
&i.BrandID,
|
||||
&i.Name,
|
||||
&i.CronExpr,
|
||||
&i.TargetPlatform,
|
||||
&i.StartAt,
|
||||
&i.EndAt,
|
||||
&i.NextRunAt,
|
||||
&i.Status,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.PromptRuleName,
|
||||
&i.BrandName,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listScheduleTasks = `-- name: ListScheduleTasks :many
|
||||
SELECT st.id, st.tenant_id, st.prompt_rule_id, st.brand_id, st.name,
|
||||
st.cron_expr, st.target_platform, st.start_at, st.end_at,
|
||||
st.next_run_at, st.status, st.created_at, st.updated_at,
|
||||
pr.name AS prompt_rule_name,
|
||||
b.name AS brand_name
|
||||
FROM schedule_tasks st
|
||||
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
||||
LEFT JOIN brands b ON b.id = st.brand_id
|
||||
WHERE st.tenant_id = $1
|
||||
AND st.deleted_at IS NULL
|
||||
AND ($2::text IS NULL OR st.status = $2)
|
||||
AND ($3::bigint IS NULL OR st.prompt_rule_id = $3)
|
||||
ORDER BY st.created_at DESC
|
||||
LIMIT $5 OFFSET $4
|
||||
`
|
||||
|
||||
type ListScheduleTasksParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
Status pgtype.Text `json:"status"`
|
||||
PromptRuleID pgtype.Int8 `json:"prompt_rule_id"`
|
||||
PageOffset int32 `json:"page_offset"`
|
||||
PageSize int32 `json:"page_size"`
|
||||
}
|
||||
|
||||
type ListScheduleTasksRow struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
PromptRuleID int64 `json:"prompt_rule_id"`
|
||||
BrandID pgtype.Int8 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CronExpr string `json:"cron_expr"`
|
||||
TargetPlatform pgtype.Text `json:"target_platform"`
|
||||
StartAt pgtype.Timestamptz `json:"start_at"`
|
||||
EndAt pgtype.Timestamptz `json:"end_at"`
|
||||
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
PromptRuleName pgtype.Text `json:"prompt_rule_name"`
|
||||
BrandName pgtype.Text `json:"brand_name"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListScheduleTasks(ctx context.Context, arg ListScheduleTasksParams) ([]ListScheduleTasksRow, error) {
|
||||
rows, err := q.db.Query(ctx, listScheduleTasks,
|
||||
arg.TenantID,
|
||||
arg.Status,
|
||||
arg.PromptRuleID,
|
||||
arg.PageOffset,
|
||||
arg.PageSize,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListScheduleTasksRow
|
||||
for rows.Next() {
|
||||
var i ListScheduleTasksRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.TenantID,
|
||||
&i.PromptRuleID,
|
||||
&i.BrandID,
|
||||
&i.Name,
|
||||
&i.CronExpr,
|
||||
&i.TargetPlatform,
|
||||
&i.StartAt,
|
||||
&i.EndAt,
|
||||
&i.NextRunAt,
|
||||
&i.Status,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.PromptRuleName,
|
||||
&i.BrandName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const softDeleteScheduleTask = `-- name: SoftDeleteScheduleTask :exec
|
||||
UPDATE schedule_tasks SET deleted_at = NOW(), updated_at = NOW()
|
||||
WHERE id = $1 AND tenant_id = $2 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type SoftDeleteScheduleTaskParams struct {
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) SoftDeleteScheduleTask(ctx context.Context, arg SoftDeleteScheduleTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteScheduleTask, arg.ID, arg.TenantID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateScheduleTask = `-- name: UpdateScheduleTask :exec
|
||||
UPDATE schedule_tasks
|
||||
SET prompt_rule_id = $1, brand_id = $2,
|
||||
name = $3, cron_expr = $4,
|
||||
target_platform = $5,
|
||||
start_at = $6, end_at = $7,
|
||||
next_run_at = $8, updated_at = NOW()
|
||||
WHERE id = $9 AND tenant_id = $10 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type UpdateScheduleTaskParams struct {
|
||||
PromptRuleID int64 `json:"prompt_rule_id"`
|
||||
BrandID pgtype.Int8 `json:"brand_id"`
|
||||
Name string `json:"name"`
|
||||
CronExpr string `json:"cron_expr"`
|
||||
TargetPlatform pgtype.Text `json:"target_platform"`
|
||||
StartAt pgtype.Timestamptz `json:"start_at"`
|
||||
EndAt pgtype.Timestamptz `json:"end_at"`
|
||||
NextRunAt pgtype.Timestamptz `json:"next_run_at"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateScheduleTask(ctx context.Context, arg UpdateScheduleTaskParams) error {
|
||||
_, err := q.db.Exec(ctx, updateScheduleTask,
|
||||
arg.PromptRuleID,
|
||||
arg.BrandID,
|
||||
arg.Name,
|
||||
arg.CronExpr,
|
||||
arg.TargetPlatform,
|
||||
arg.StartAt,
|
||||
arg.EndAt,
|
||||
arg.NextRunAt,
|
||||
arg.ID,
|
||||
arg.TenantID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateScheduleTaskStatus = `-- name: UpdateScheduleTaskStatus :exec
|
||||
UPDATE schedule_tasks SET status = $1, updated_at = NOW()
|
||||
WHERE id = $2 AND tenant_id = $3 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type UpdateScheduleTaskStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
ID int64 `json:"id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateScheduleTaskStatus(ctx context.Context, arg UpdateScheduleTaskStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateScheduleTaskStatus, arg.Status, arg.ID, arg.TenantID)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user