stats step 2: World Bank, IMF WEO, OWID, Energy-Charts, Rijksfinanciën, US Treasury, USAspending collectors + tables, timers
All checks were successful
Deploy production / deploy (push) Successful in 1m10s

This commit is contained in:
2026-10-25 21:05:51 +00:00
parent 7e905b1651
commit 8958d3ff8f
21 changed files with 34655 additions and 3 deletions

View File

@@ -202,3 +202,155 @@ export const statsBisPolicyRate = statsSchema.table(
},
(t) => [primaryKey({ columns: [t.refArea, t.freq, t.period] })]
);
// ── A3 World Bank indicators, A4 IMF WEO (DataMapper) ─────────────────────────────────────
export const statsWbIndicator = statsSchema.table(
'wb_indicator',
{
indicatorId: text('indicator_id').notNull(),
countryIso3: text('country_iso3').notNull(),
year: integer('year').notNull(),
value: doublePrecision('value')
},
(t) => [primaryKey({ columns: [t.indicatorId, t.countryIso3, t.year] })]
);
export const statsImfWeo = statsSchema.table(
'imf_weo',
{
/** WEO round the values come from, e.g. '2026-10' (October 2026 WEO). */
vintage: text('vintage').notNull(),
indicator: text('indicator').notNull(),
countryIso3: text('country_iso3').notNull(),
year: integer('year').notNull(),
value: doublePrecision('value'),
isForecast: boolean('is_forecast').notNull()
},
(t) => [primaryKey({ columns: [t.vintage, t.indicator, t.countryIso3, t.year] })]
);
// ── A9 Our World in Data (Maddison GDP per capita, energy dataset) ───────────────────────
export const statsOwidMaddison = statsSchema.table(
'owid_maddison',
{
entity: text('entity').notNull(),
/** null for OWID regions (Western Europe, World, …). */
iso3: text('iso3'),
year: integer('year').notNull(),
/** International-$ at 2011 prices. */
gdpPc: doublePrecision('gdp_pc')
},
(t) => [primaryKey({ columns: [t.entity, t.year] })]
);
export const statsOwidEnergy = statsSchema.table(
'owid_energy',
{
country: text('country').notNull(),
iso3: text('iso3'),
year: integer('year').notNull(),
/** Selected OWID columns as-is: {"solar_share_elec": 21.3, "energy_per_capita": 40000, …}. */
values: jsonb('values').$type<Record<string, number>>().notNull()
},
(t) => [primaryKey({ columns: [t.country, t.year] })]
);
// ── A10 Energy-Charts (Fraunhofer ISE): day-ahead prices, cross-border physical flows ─────
export const statsEcDayaheadPrice = statsSchema.table(
'ec_dayahead_price',
{
bzn: text('bzn').notNull(),
ts: timestamptz('ts').notNull(),
eurMwh: doublePrecision('eur_mwh')
},
(t) => [primaryKey({ columns: [t.bzn, t.ts] })]
);
export const statsEcCrossborder = statsSchema.table(
'ec_crossborder',
{
/** Lower-case Energy-Charts country code, e.g. 'nl'. */
country: text('country').notNull(),
/** Neighbour name as Energy-Charts reports it ('Belgium', …, 'sum'). */
neighbour: text('neighbour').notNull(),
ts: timestamptz('ts').notNull(),
/** GW; positive = import into `country`, negative = export. */
gw: doublePrecision('gw')
},
(t) => [primaryKey({ columns: [t.country, t.neighbour, t.ts] })]
);
// ── A13 Rijksfinanciën (NL central-government budget tables) ──────────────────────────────
export const statsRfBudgetTable = statsSchema.table(
'rf_budget_table',
{
year: integer('year').notNull(),
/** OWB (budget), O1/O2 (supplementary budgets), JV (annual report). */
phase: text('phase').notNull(),
/** Rijksfinanciën row index, unique within year + phase (includes chapter/article/vuo). */
rowKey: text('row_key').notNull(),
/** U = expenditure, O = revenue, V = commitments. */
vuo: char('vuo', { length: 1 }).notNull(),
chapter: text('chapter').notNull(),
chapterName: text('chapter_name').notNull(),
article: text('article'),
articleName: text('article_name'),
detail: jsonb('detail').$type<Record<string, unknown>>().notNull().default({}),
/** Thousand euro. */
amountEurK: doublePrecision('amount_eur_k')
},
(t) => [
primaryKey({ columns: [t.year, t.phase, t.rowKey] }),
index('rf_budget_table_chapter_idx').on(t.year, t.vuo, t.chapter)
]
);
// ── A11 US Treasury Fiscal Data (Monthly Treasury Statement, Debt to the Penny) ───────────
const mtsColumns = {
recordDate: date('record_date', { mode: 'string' }).notNull(),
classificationId: text('classification_id').notNull(),
parentId: text('parent_id'),
description: text('description').notNull(),
level: integer('level'),
printOrder: integer('print_order'),
/** Net amount for the month and fiscal year to date, USD. */
netMonth: doublePrecision('net_month'),
netFytd: doublePrecision('net_fytd'),
grossMonth: doublePrecision('gross_month')
};
export const statsUstMtsReceipts = statsSchema.table('ust_mts_receipts', mtsColumns, (t) => [
primaryKey({ columns: [t.recordDate, t.classificationId] })
]);
export const statsUstMtsOutlays = statsSchema.table('ust_mts_outlays', { ...mtsColumns }, (t) => [
primaryKey({ columns: [t.recordDate, t.classificationId] })
]);
export const statsUstDebtDaily = statsSchema.table('ust_debt_daily', {
recordDate: date('record_date', { mode: 'string' }).primaryKey(),
debtHeldPublic: doublePrecision('debt_held_public'),
intragovHoldings: doublePrecision('intragov_holdings'),
totalDebt: doublePrecision('total_debt')
});
// ── A12 USAspending (budgetary resources per top-tier agency and fiscal year) ─────────────
export const statsUsasAgencyFy = statsSchema.table(
'usas_agency_fy',
{
toptierCode: text('toptier_code').notNull(),
fiscalYear: integer('fiscal_year').notNull(),
agencyName: text('agency_name').notNull(),
abbreviation: text('abbreviation'),
budgetaryResources: doublePrecision('budgetary_resources'),
obligated: doublePrecision('obligated'),
outlayed: doublePrecision('outlayed')
},
(t) => [primaryKey({ columns: [t.toptierCode, t.fiscalYear] })]
);