WIP main worktree changes before merge
This commit is contained in:
@@ -3,7 +3,8 @@ import type {
|
||||
FinancialCadence,
|
||||
FinancialSurfaceKind
|
||||
} from '@/lib/types';
|
||||
import { db } from '@/lib/server/db';
|
||||
import { db, getSqliteClient } from '@/lib/server/db';
|
||||
import { withFinancialIngestionSchemaRetry } from '@/lib/server/db/financial-ingestion-schema';
|
||||
import { companyFinancialBundle } from '@/lib/server/db/schema';
|
||||
|
||||
export const CURRENT_COMPANY_FINANCIAL_BUNDLE_VERSION = 14;
|
||||
@@ -64,34 +65,38 @@ export async function upsertCompanyFinancialBundle(input: {
|
||||
}) {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
const [saved] = await db
|
||||
.insert(companyFinancialBundle)
|
||||
.values({
|
||||
ticker: input.ticker.trim().toUpperCase(),
|
||||
surface_kind: input.surfaceKind,
|
||||
cadence: input.cadence,
|
||||
bundle_version: CURRENT_COMPANY_FINANCIAL_BUNDLE_VERSION,
|
||||
source_snapshot_ids: input.sourceSnapshotIds,
|
||||
source_signature: input.sourceSignature,
|
||||
payload: input.payload,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [
|
||||
companyFinancialBundle.ticker,
|
||||
companyFinancialBundle.surface_kind,
|
||||
companyFinancialBundle.cadence
|
||||
],
|
||||
set: {
|
||||
const [saved] = await withFinancialIngestionSchemaRetry({
|
||||
client: getSqliteClient(),
|
||||
context: 'company-financial-bundle-upsert',
|
||||
operation: async () => await db
|
||||
.insert(companyFinancialBundle)
|
||||
.values({
|
||||
ticker: input.ticker.trim().toUpperCase(),
|
||||
surface_kind: input.surfaceKind,
|
||||
cadence: input.cadence,
|
||||
bundle_version: CURRENT_COMPANY_FINANCIAL_BUNDLE_VERSION,
|
||||
source_snapshot_ids: input.sourceSnapshotIds,
|
||||
source_signature: input.sourceSignature,
|
||||
payload: input.payload,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
})
|
||||
.returning();
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [
|
||||
companyFinancialBundle.ticker,
|
||||
companyFinancialBundle.surface_kind,
|
||||
companyFinancialBundle.cadence
|
||||
],
|
||||
set: {
|
||||
bundle_version: CURRENT_COMPANY_FINANCIAL_BUNDLE_VERSION,
|
||||
source_snapshot_ids: input.sourceSnapshotIds,
|
||||
source_signature: input.sourceSignature,
|
||||
payload: input.payload,
|
||||
updated_at: now
|
||||
}
|
||||
})
|
||||
.returning()
|
||||
});
|
||||
|
||||
return toBundleRecord(saved);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user