import { MongoMigration } from '../mongo_migrator.js' export default class CreateCwmpExchangesCollection extends MongoMigration { async up(): Promise { const exchanges = this.db.collection('cwmp_exchanges') // Compound index for efficient retrieval by device, ordered by time await exchanges.createIndex( { deviceId: 1, timestamp: 1 }, { name: 'idx_deviceId_timestamp' } ) // Unique index for atomic sequence numbering and Last-Event-ID queries await exchanges.createIndex( { deviceId: 1, sequenceNumber: 1 }, { unique: true, name: 'idx_deviceId_sequenceNumber' } ) // TTL index to auto-remove exchanges older than 24h await exchanges.createIndex( { createdAt: 1 }, { expireAfterSeconds: 86400, name: 'idx_createdAt_ttl' } ) // Create counters collection for atomic sequence number generation this.db.collection('cwmp_exchange_counters') } async down(): Promise { await this.db.dropCollection('cwmp_exchanges').catch(() => {}) await this.db.dropCollection('cwmp_exchange_counters').catch(() => {}) } }