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
@@ -27,17 +27,18 @@ func (q *Queries) ConfirmReservation(ctx context.Context, arg ConfirmReservation
}
const createQuotaReservation = `-- name: CreateQuotaReservation :one
INSERT INTO quota_reservations (tenant_id, quota_type, resource_type, resource_id, reserved_amount, status, expire_at)
VALUES ($1, $2, $3, $4,
$5, 'pending', $6)
INSERT INTO quota_reservations (tenant_id, operator_id, quota_type, resource_type, resource_id, reserved_amount, status, expire_at)
VALUES ($1, $2, $3, $4, $5,
$6, 'pending', $7)
RETURNING id
`
type CreateQuotaReservationParams struct {
TenantID int64 `json:"tenant_id"`
OperatorID pgtype.Int8 `json:"operator_id"`
QuotaType string `json:"quota_type"`
ResourceType string `json:"resource_type"`
ResourceID int64 `json:"resource_id"`
ResourceID pgtype.Int8 `json:"resource_id"`
ReservedAmount int32 `json:"reserved_amount"`
ExpireAt pgtype.Timestamptz `json:"expire_at"`
}
@@ -45,6 +46,7 @@ type CreateQuotaReservationParams struct {
func (q *Queries) CreateQuotaReservation(ctx context.Context, arg CreateQuotaReservationParams) (int64, error) {
row := q.db.QueryRow(ctx, createQuotaReservation,
arg.TenantID,
arg.OperatorID,
arg.QuotaType,
arg.ResourceType,
arg.ResourceID,
@@ -77,14 +79,15 @@ func (q *Queries) GetCurrentBalance(ctx context.Context, arg GetCurrentBalancePa
}
const insertQuotaLedger = `-- name: InsertQuotaLedger :one
INSERT INTO tenant_quota_ledgers (tenant_id, quota_type, delta, balance_after, reason, reference_type, reference_id)
VALUES ($1, $2, $3, $4,
$5, $6, $7)
INSERT INTO tenant_quota_ledgers (tenant_id, operator_id, quota_type, delta, balance_after, reason, reference_type, reference_id)
VALUES ($1, $2, $3, $4, $5,
$6, $7, $8)
RETURNING id
`
type InsertQuotaLedgerParams struct {
TenantID int64 `json:"tenant_id"`
OperatorID pgtype.Int8 `json:"operator_id"`
QuotaType string `json:"quota_type"`
Delta int32 `json:"delta"`
BalanceAfter int32 `json:"balance_after"`
@@ -96,6 +99,7 @@ type InsertQuotaLedgerParams struct {
func (q *Queries) InsertQuotaLedger(ctx context.Context, arg InsertQuotaLedgerParams) (int64, error) {
row := q.db.QueryRow(ctx, insertQuotaLedger,
arg.TenantID,
arg.OperatorID,
arg.QuotaType,
arg.Delta,
arg.BalanceAfter,
@@ -129,9 +133,9 @@ WHERE id = $2 AND tenant_id = $3
`
type UpdateQuotaReservationResourceParams struct {
ResourceID int64 `json:"resource_id"`
ID int64 `json:"id"`
TenantID int64 `json:"tenant_id"`
ResourceID pgtype.Int8 `json:"resource_id"`
ID int64 `json:"id"`
TenantID int64 `json:"tenant_id"`
}
func (q *Queries) UpdateQuotaReservationResource(ctx context.Context, arg UpdateQuotaReservationResourceParams) error {