How would you design a scalable database schema to handle high-volume transaction logging and reporting requirements? Use the provided schema to produce a monthly report for active Mastercard merchants from January through March 2025, considering only transactions whose latest event is SETTLED.
merchant_id, merchant_name, report_month, transaction_count, total_amount, prior_month_amount, month_over_month_pct, and cumulative_amountmerchant_id, then report_month ascending2025-01-01 through 2025-03-31 inclusively, with timestamps on or after 2025-01-01 00:00:00 and before 2025-04-01 00:00:00.report_month as the first day of its month: 2025-01-01, 2025-02-01, and 2025-03-01.event_id as its latest event, and include it only when that event is SETTLED.total_amount and cumulative_amount as numeric values with exactly two decimal places, replacing missing totals with 0.00.prior_month_amount to NULL for the first month, and calculate it as the preceding reporting month's total_amount.month_over_month_pct rounded to two decimals, but use NULL when prior_month_amount is NULL or zero.| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Unique Mastercard merchant identifier |
| merchant_name | VARCHAR(120) | Merchant display name |
| merchant_category | VARCHAR(60) | Merchant business category |
| is_active | BOOLEAN | Whether the merchant is active for reporting |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | BIGINT | Unique transaction identifier |
| merchant_id | INT | Merchant associated with the transaction |
| created_at | TIMESTAMP | Transaction creation timestamp |
| amount | NUMERIC(12,2) | Transaction amount in the transaction currency |
| currency | VARCHAR(3) | ISO 4217 currency code |
| Column | Type | Description |
|---|---|---|
| event_idPK | BIGINT | Monotonically increasing event identifier |
| transaction_id | BIGINT | Transaction whose state changed |
| event_type | VARCHAR(30) | Transaction lifecycle state |
| event_at | TIMESTAMP | Time at which the event occurred |