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.
145 lines
4.3 KiB
Go
145 lines
4.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: quota.sql
|
|
|
|
package generated
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const confirmReservation = `-- name: ConfirmReservation :exec
|
|
UPDATE quota_reservations SET status = 'confirmed', consumed_amount = reserved_amount, updated_at = NOW()
|
|
WHERE id = $1 AND tenant_id = $2
|
|
`
|
|
|
|
type ConfirmReservationParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) ConfirmReservation(ctx context.Context, arg ConfirmReservationParams) error {
|
|
_, err := q.db.Exec(ctx, confirmReservation, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|
|
|
|
const createQuotaReservation = `-- name: CreateQuotaReservation :one
|
|
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 pgtype.Int8 `json:"resource_id"`
|
|
ReservedAmount int32 `json:"reserved_amount"`
|
|
ExpireAt pgtype.Timestamptz `json:"expire_at"`
|
|
}
|
|
|
|
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,
|
|
arg.ReservedAmount,
|
|
arg.ExpireAt,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const getCurrentBalance = `-- name: GetCurrentBalance :one
|
|
SELECT COALESCE(
|
|
(SELECT balance_after FROM tenant_quota_ledgers
|
|
WHERE tenant_id = $1 AND quota_type = $2
|
|
ORDER BY created_at DESC LIMIT 1), 0
|
|
)::INT AS balance
|
|
`
|
|
|
|
type GetCurrentBalanceParams struct {
|
|
TenantID int64 `json:"tenant_id"`
|
|
QuotaType string `json:"quota_type"`
|
|
}
|
|
|
|
func (q *Queries) GetCurrentBalance(ctx context.Context, arg GetCurrentBalanceParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, getCurrentBalance, arg.TenantID, arg.QuotaType)
|
|
var balance int32
|
|
err := row.Scan(&balance)
|
|
return balance, err
|
|
}
|
|
|
|
const insertQuotaLedger = `-- name: InsertQuotaLedger :one
|
|
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"`
|
|
Reason pgtype.Text `json:"reason"`
|
|
ReferenceType pgtype.Text `json:"reference_type"`
|
|
ReferenceID pgtype.Int8 `json:"reference_id"`
|
|
}
|
|
|
|
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,
|
|
arg.Reason,
|
|
arg.ReferenceType,
|
|
arg.ReferenceID,
|
|
)
|
|
var id int64
|
|
err := row.Scan(&id)
|
|
return id, err
|
|
}
|
|
|
|
const refundReservation = `-- name: RefundReservation :exec
|
|
UPDATE quota_reservations SET status = 'refunded', refunded_amount = reserved_amount, updated_at = NOW()
|
|
WHERE id = $1 AND tenant_id = $2
|
|
`
|
|
|
|
type RefundReservationParams struct {
|
|
ID int64 `json:"id"`
|
|
TenantID int64 `json:"tenant_id"`
|
|
}
|
|
|
|
func (q *Queries) RefundReservation(ctx context.Context, arg RefundReservationParams) error {
|
|
_, err := q.db.Exec(ctx, refundReservation, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|
|
|
|
const updateQuotaReservationResource = `-- name: UpdateQuotaReservationResource :exec
|
|
UPDATE quota_reservations SET resource_id = $1, updated_at = NOW()
|
|
WHERE id = $2 AND tenant_id = $3
|
|
`
|
|
|
|
type UpdateQuotaReservationResourceParams struct {
|
|
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 {
|
|
_, err := q.db.Exec(ctx, updateQuotaReservationResource, arg.ResourceID, arg.ID, arg.TenantID)
|
|
return err
|
|
}
|