From ca7a56142b48c22a2e94d6612a1f01455d3e8a04 Mon Sep 17 00:00:00 2001 From: Ben Stokes Date: Mon, 23 Nov 2026 16:18:29 +0000 Subject: [PATCH] feat: build default indexes for all collections --- apps/api/src/modules/Database.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/api/src/modules/Database.ts b/apps/api/src/modules/Database.ts index e17c696..b30288f 100644 --- a/apps/api/src/modules/Database.ts +++ b/apps/api/src/modules/Database.ts @@ -441,21 +441,33 @@ export class Database { */ async EnsureCollections(): Promise { const collections = [ - 'Accounts', 'AccountLinks', + 'Accounts', 'ApiKeys', 'AppSecrets', - 'Balances', 'BalanceTransactions', + 'Balances', + 'Charges', + 'CheckoutSessions', + 'Customers', 'Events', 'ExternalWallets', + 'IdempotencyKeys', + 'InvoiceItems', + 'Invoices', 'LoginLinks', + 'PaymentIntents', + 'PaymentLinks', 'Payouts', 'Persons', + 'Prices', + 'Products', + 'SubscriptionItems', + 'Subscriptions', + 'TelemetryConfigs', 'TopUps', 'Transfers', 'UsageCounters', - 'TelemetryConfigs', 'VerificationSessions', 'WebhookDeliveries', 'WebhookEndpoints', @@ -493,6 +505,14 @@ export class Database { flexibleSchema.index({ status: 1, next_attempt_at: 1 }); } + // Per-platform lists filter by platform and sort newest first. + if ( + collectionName === 'Events' || + collectionName === 'BalanceTransactions' + ) { + flexibleSchema.index({ platform_account: 1, created: -1 }); + } + return mongoose.model(collectionName, flexibleSchema); }