feat(kol): repo support for cross-tenant revision lookup
This commit is contained in:
@@ -48,19 +48,25 @@ func (q *Queries) CountArticles(ctx context.Context, arg CountArticlesParams) (i
|
||||
}
|
||||
|
||||
const createArticle = `-- name: CreateArticle :one
|
||||
INSERT INTO articles (tenant_id, source_type, template_id, generate_status, publish_status)
|
||||
VALUES ($1, $2, $3, 'pending', 'unpublished')
|
||||
INSERT INTO articles (tenant_id, source_type, template_id, kol_prompt_id, generate_status, publish_status)
|
||||
VALUES ($1, $2, $3, $4, 'pending', 'unpublished')
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type CreateArticleParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
SourceType string `json:"source_type"`
|
||||
TemplateID pgtype.Int8 `json:"template_id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
SourceType string `json:"source_type"`
|
||||
TemplateID pgtype.Int8 `json:"template_id"`
|
||||
KolPromptID pgtype.Int8 `json:"kol_prompt_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateArticle(ctx context.Context, arg CreateArticleParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, createArticle, arg.TenantID, arg.SourceType, arg.TemplateID)
|
||||
row := q.db.QueryRow(ctx, createArticle,
|
||||
arg.TenantID,
|
||||
arg.SourceType,
|
||||
arg.TemplateID,
|
||||
arg.KolPromptID,
|
||||
)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
|
||||
@@ -62,9 +62,9 @@ func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams)
|
||||
}
|
||||
|
||||
const createGenerationTask = `-- name: CreateGenerationTask :one
|
||||
INSERT INTO generation_tasks (tenant_id, operator_id, article_id, quota_reservation_id, task_type, input_params_json, status)
|
||||
INSERT INTO generation_tasks (tenant_id, operator_id, article_id, quota_reservation_id, task_type, request_hash, input_params_json, status)
|
||||
VALUES ($1, $2, $3, $4,
|
||||
$5, $6, 'queued')
|
||||
$5, $6, $7, 'queued')
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
@@ -74,6 +74,7 @@ type CreateGenerationTaskParams struct {
|
||||
ArticleID pgtype.Int8 `json:"article_id"`
|
||||
QuotaReservationID pgtype.Int8 `json:"quota_reservation_id"`
|
||||
TaskType string `json:"task_type"`
|
||||
RequestHash pgtype.Text `json:"request_hash"`
|
||||
InputParamsJson []byte `json:"input_params_json"`
|
||||
}
|
||||
|
||||
@@ -84,6 +85,7 @@ func (q *Queries) CreateGenerationTask(ctx context.Context, arg CreateGeneration
|
||||
arg.ArticleID,
|
||||
arg.QuotaReservationID,
|
||||
arg.TaskType,
|
||||
arg.RequestHash,
|
||||
arg.InputParamsJson,
|
||||
)
|
||||
var id int64
|
||||
@@ -91,6 +93,36 @@ func (q *Queries) CreateGenerationTask(ctx context.Context, arg CreateGeneration
|
||||
return id, err
|
||||
}
|
||||
|
||||
const createTaskRecord = `-- name: CreateTaskRecord :one
|
||||
INSERT INTO task_records (tenant_id, operator_id, task_type, resource_type, resource_id, status)
|
||||
VALUES ($1, $2, $3,
|
||||
$4, $5, $6)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type CreateTaskRecordParams struct {
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
OperatorID pgtype.Int8 `json:"operator_id"`
|
||||
TaskType string `json:"task_type"`
|
||||
ResourceType string `json:"resource_type"`
|
||||
ResourceID int64 `json:"resource_id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateTaskRecord(ctx context.Context, arg CreateTaskRecordParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, createTaskRecord,
|
||||
arg.TenantID,
|
||||
arg.OperatorID,
|
||||
arg.TaskType,
|
||||
arg.ResourceType,
|
||||
arg.ResourceID,
|
||||
arg.Status,
|
||||
)
|
||||
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()
|
||||
@@ -117,3 +149,35 @@ func (q *Queries) UpdateGenerationTaskStatus(ctx context.Context, arg UpdateGene
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateTaskRecordStatus = `-- name: UpdateTaskRecordStatus :exec
|
||||
UPDATE task_records
|
||||
SET status = $1,
|
||||
error_message = $2,
|
||||
updated_at = NOW()
|
||||
WHERE tenant_id = $3
|
||||
AND task_type = $4
|
||||
AND resource_type = $5
|
||||
AND resource_id = $6
|
||||
`
|
||||
|
||||
type UpdateTaskRecordStatusParams struct {
|
||||
Status string `json:"status"`
|
||||
ErrorMessage pgtype.Text `json:"error_message"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
TaskType string `json:"task_type"`
|
||||
ResourceType string `json:"resource_type"`
|
||||
ResourceID int64 `json:"resource_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateTaskRecordStatus(ctx context.Context, arg UpdateTaskRecordStatusParams) error {
|
||||
_, err := q.db.Exec(ctx, updateTaskRecordStatus,
|
||||
arg.Status,
|
||||
arg.ErrorMessage,
|
||||
arg.TenantID,
|
||||
arg.TaskType,
|
||||
arg.ResourceType,
|
||||
arg.ResourceID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -182,7 +182,8 @@ SELECT sp.id, sp.tenant_id, sp.subscription_id, sp.package_id, sp.prompt_id,
|
||||
s.status AS subscription_status, s.end_at AS subscription_end_at,
|
||||
p.name AS prompt_name, p.platform_hint, p.status AS prompt_status,
|
||||
p.published_revision_no,
|
||||
k.name AS package_name, k.status AS package_status
|
||||
k.name AS package_name, k.status AS package_status,
|
||||
k.tenant_id AS creator_tenant_id
|
||||
FROM kol_subscription_prompts sp
|
||||
JOIN kol_subscriptions s ON s.id = sp.subscription_id
|
||||
JOIN kol_prompts p ON p.id = sp.prompt_id AND p.deleted_at IS NULL
|
||||
@@ -213,6 +214,7 @@ type GetSubscriptionPromptByIDRow struct {
|
||||
PublishedRevisionNo pgtype.Int4 `json:"published_revision_no"`
|
||||
PackageName string `json:"package_name"`
|
||||
PackageStatus string `json:"package_status"`
|
||||
CreatorTenantID int64 `json:"creator_tenant_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetSubscriptionPromptByID(ctx context.Context, arg GetSubscriptionPromptByIDParams) (GetSubscriptionPromptByIDRow, error) {
|
||||
@@ -235,6 +237,7 @@ func (q *Queries) GetSubscriptionPromptByID(ctx context.Context, arg GetSubscrip
|
||||
&i.PublishedRevisionNo,
|
||||
&i.PackageName,
|
||||
&i.PackageStatus,
|
||||
&i.CreatorTenantID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ type Querier interface {
|
||||
CreateQuotaReservation(ctx context.Context, arg CreateQuotaReservationParams) (int64, error)
|
||||
CreateScheduleTask(ctx context.Context, arg CreateScheduleTaskParams) (CreateScheduleTaskRow, error)
|
||||
CreateSubscriptionPrompt(ctx context.Context, arg CreateSubscriptionPromptParams) error
|
||||
CreateTaskRecord(ctx context.Context, arg CreateTaskRecordParams) (int64, error)
|
||||
DeleteImageFolder(ctx context.Context, arg DeleteImageFolderParams) error
|
||||
DeleteImageReferencesByArticle(ctx context.Context, arg DeleteImageReferencesByArticleParams) error
|
||||
DeleteImageReferencesByArticleScope(ctx context.Context, arg DeleteImageReferencesByArticleScopeParams) error
|
||||
@@ -172,6 +173,7 @@ type Querier interface {
|
||||
UpdateQuotaReservationResource(ctx context.Context, arg UpdateQuotaReservationResourceParams) error
|
||||
UpdateScheduleTask(ctx context.Context, arg UpdateScheduleTaskParams) error
|
||||
UpdateScheduleTaskStatus(ctx context.Context, arg UpdateScheduleTaskStatusParams) error
|
||||
UpdateTaskRecordStatus(ctx context.Context, arg UpdateTaskRecordStatusParams) error
|
||||
UpsertImageReference(ctx context.Context, arg UpsertImageReferenceParams) error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user