Configuration
This page covers the environment variables, service dependencies, and setup required for the currency management features.
Batch Service Configuration
Environment Variables
| Variable | Description | Example |
|---|---|---|
SUBSCRIPTION_SERVICE_URL | Base URL for the subscription service API | http://localhost:3007 |
DB_HOST | PostgreSQL host | db.example.supabase.co |
DB_PORT | PostgreSQL port | 5432 |
DB_USERNAME | Database username | postgres |
DB_PASSWORD | Database password | — |
DB_DATABASE | Database name | postgres |
DB_SCHEMA | Default schema | public |
Redis Configuration
BullMQ requires a Redis instance for job queue management. Redis connection settings are defined in batch-service/src/config/redis.config.ts.
OpenExchangeRates API
The API key for OpenExchangeRates is currently configured in the batch processor. To use a different key or provider, update the FetchExchangeRates case in batch-service/src/jobs/daily-batch.processor.ts.
Service Dependencies
The currency management feature spans multiple services:
┌─────────────────┐ ┌──────────────────────┐ ┌──────────────────┐
│ batch-service │────>│ subscription-service │<────│ reporting-service│
│ (rate sync) │ │ (currency storage) │ │ (analytics SQL) │
└─────────────────┘ └──────────────────────┘ └──────────────────┘
│
┌──────▼──────────┐
│ user-tenant- │
│ service │
│ (base currency) │
└─────────────────┘| Service | Port | Role |
|---|---|---|
| batch-service | — | Fetches exchange rates on schedule and persists via subscription-service |
| subscription-service | 3007 | Stores currencies, conversion rates, and exchange rates. Manages account currency. |
| user-tenant-service | — | Stores tenant-level base_currency_code |
| reporting-service | — | Applies currency conversion CTEs in analytics SQL queries |
| billhive-facade | 4001 | Orchestrates currency sync to tenant, validates currency at order time, enforces currency lock on accounts |
Database Schema Setup
Required Tables
subscription.currency — Tenant currency configuration:
| Column | Type | Description |
|---|---|---|
id | uuid | Primary key |
tenant_id | uuid | Owning tenant |
currency_code | varchar(5) | ISO currency code |
base_currency_code | varchar(5) | Tenant’s base currency code |
conversion_rate | numeric | Units of this currency per 1 base currency unit |
is_base_currency | boolean | Whether this is the tenant’s base currency |
subscription.currency_conversions — Exchange rates from external provider:
| Column | Type | Description |
|---|---|---|
base_currency | varchar | Source currency (typically USD) |
target_currency | varchar | Target currency |
exchange_rate | numeric | Conversion rate (4-decimal precision) |
user_tenant.tenant — Tenant record (relevant column):
| Column | Type | Description |
|---|---|---|
base_currency_code | varchar(5) | Tenant’s base currency, synced from subscription.currency |
Migration
The base_currency_code column on user_tenant.tenant is populated via migration:
-- Add column
ALTER TABLE user_tenant.tenant
ADD COLUMN base_currency_code VARCHAR(5);
-- Backfill from existing currency data
UPDATE user_tenant.tenant t
SET base_currency_code = c.base_currency_code
FROM subscription.currency c
WHERE c.tenant_id = t.id AND c.is_base_currency = true;
-- Default for tenants without currency config
UPDATE user_tenant.tenant
SET base_currency_code = 'USD'
WHERE base_currency_code IS NULL;Currency Enum
The PostgreSQL enum type subscription."Currency" defines the allowed currency values. When joining against varchar columns (e.g., in analytics queries), cast the enum column with ::text:
LEFT JOIN currency_rates cr ON cr.currency_code = t.currency::textAdding a New Currency
To add support for a new currency:
- Add the currency code to the
Currencyenum inpackages/enums/src/currency.enum.ts - Add the corresponding PostgreSQL enum value via migration
- Add the currency to the
targetCurrenciesarray inbatch-service/src/flows/update-exchange-rates/exchange-rate-flow.ts - Add the currency symbol mapping in the frontend
currency_mapper - Create the currency record for each tenant via the currency management UI or API