fix: handle optional growth provider metadata
This commit is contained in:
@@ -204,7 +204,8 @@ func scanRecord(row rowScanner) (Record, error) {
|
|||||||
var evidence []byte
|
var evidence []byte
|
||||||
var ai []byte
|
var ai []byte
|
||||||
var terminalSource *string
|
var terminalSource *string
|
||||||
err := row.Scan(&r.ReportID, &r.Revision, &r.MerchantID, &r.TerminalDBID, &terminalSource, &r.Fingerprint, &status, &r.HorizonDays, &r.ForecastStartDate, &r.DatasetWatermark, &r.CatalogVersion, &r.AnalyticsVersion, &r.PromptVersion, &r.SchemaVersion, &r.Model, &evidence, &ai, &r.FailureCode, &r.Usage.InputTokens, &r.Usage.OutputTokens, &r.Usage.LatencyMS, &r.Usage.ProviderRequestID, &r.Usage.EstimatedCost, &r.ManualRefresh, &r.TehranRefreshDay, &r.CreatedAt, &r.UpdatedAt)
|
var providerRequestID, estimatedCost *string
|
||||||
|
err := row.Scan(&r.ReportID, &r.Revision, &r.MerchantID, &r.TerminalDBID, &terminalSource, &r.Fingerprint, &status, &r.HorizonDays, &r.ForecastStartDate, &r.DatasetWatermark, &r.CatalogVersion, &r.AnalyticsVersion, &r.PromptVersion, &r.SchemaVersion, &r.Model, &evidence, &ai, &r.FailureCode, &r.Usage.InputTokens, &r.Usage.OutputTokens, &r.Usage.LatencyMS, &providerRequestID, &estimatedCost, &r.ManualRefresh, &r.TehranRefreshDay, &r.CreatedAt, &r.UpdatedAt)
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return Record{}, ErrNotFound
|
return Record{}, ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -212,6 +213,12 @@ func scanRecord(row rowScanner) (Record, error) {
|
|||||||
return Record{}, fmt.Errorf("scanning growth report: %w", err)
|
return Record{}, fmt.Errorf("scanning growth report: %w", err)
|
||||||
}
|
}
|
||||||
r.Status = Status(status)
|
r.Status = Status(status)
|
||||||
|
if providerRequestID != nil {
|
||||||
|
r.Usage.ProviderRequestID = *providerRequestID
|
||||||
|
}
|
||||||
|
if estimatedCost != nil {
|
||||||
|
r.Usage.EstimatedCost = *estimatedCost
|
||||||
|
}
|
||||||
if terminalSource != nil {
|
if terminalSource != nil {
|
||||||
r.Scope.TerminalID = terminalSource
|
r.Scope.TerminalID = terminalSource
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ CREATE TABLE IF NOT EXISTS growth_reports (
|
|||||||
completed_at timestamptz
|
completed_at timestamptz
|
||||||
);
|
);
|
||||||
-- statement-break
|
-- statement-break
|
||||||
|
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS provider_request_id text;
|
||||||
|
-- statement-break
|
||||||
|
ALTER TABLE growth_reports ADD COLUMN IF NOT EXISTS estimated_cost text;
|
||||||
|
-- statement-break
|
||||||
|
ALTER TABLE growth_reports ALTER COLUMN deterministic_evidence DROP NOT NULL;
|
||||||
|
-- statement-break
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS growth_reports_current_fingerprint_idx
|
CREATE UNIQUE INDEX IF NOT EXISTS growth_reports_current_fingerprint_idx
|
||||||
ON growth_reports (merchant_id, fingerprint)
|
ON growth_reports (merchant_id, fingerprint)
|
||||||
WHERE manual_refresh = false AND status IN ('QUEUED','ANALYZING','GENERATING','READY','PARTIAL');
|
WHERE manual_refresh = false AND status IN ('QUEUED','ANALYZING','GENERATING','READY','PARTIAL');
|
||||||
|
|||||||
Reference in New Issue
Block a user