Files
adam-acs/database/mongo_migrations/011_create_cwmp_exchanges_collection.ts
T
Kevin L'Hereec f9e56c78b1 refactor: migrate all internal imports to package.json subpath aliases
- Add #domain, #protocol, #utils aliases to package.json imports map
- Replace all relative imports (./, ../, ../..) in app/ and
  database/mongo_migrations/ with the corresponding #alias imports,
  eliminating relative path traversal across the codebase
- Remove dead code: ConfigurationVersionModel.findByConfigurationIdentifier
  (unused, superseded by paginateVersions) and unused exception classes
  (NotFoundException, UnprocessableEntityException, DatabaseException)
  from app/exceptions/index.ts, keeping only BadRequestException
- Fix pre-existing syntax error in configuration_version.ts (mismatched
  parenthesis) that broke tsc
- Fix eqeqeq violation in configuration_service.ts and isNaN ->
  Number.isNaN in configuration_engine.ts / cwmp-1-0.ts / exchange_controller.ts
- Fix no-shadow violation in cwmp-1-0.ts EventStruct constructor
- Prettier formatting pass on touched files

Validated: tsc --noEmit clean, eslint app/ clean, full test suite green.
2026-07-22 11:45:14 +02:00

34 lines
1.1 KiB
TypeScript

import { MongoMigration } from '#database/mongo_migrator'
export default class CreateCwmpExchangesCollection extends MongoMigration {
async up(): Promise<void> {
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<void> {
await this.db.dropCollection('cwmp_exchanges').catch(() => {})
await this.db.dropCollection('cwmp_exchange_counters').catch(() => {})
}
}