diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..7812ced --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,17 @@ +# Agent Instructions for dcrouter + +## Database & Migrations + +### Collection Names +smartdata uses the **exact class name** as the MongoDB collection name. No lowercasing. +- `StoredRouteDoc` → collection `StoredRouteDoc` +- `TargetProfileDoc` → collection `TargetProfileDoc` +- `RouteDoc` → collection `RouteDoc` + +When writing migrations in `ts_migrations/index.ts`, use the exact class name casing in `ctx.mongo!.collection('ClassName')` and `db.listCollections({ name: 'ClassName' })`. + +### Migration Rules +- All DB schema migrations go EXCLUSIVELY in `ts_migrations/index.ts` as smartmigration steps. +- NEVER put migration logic in application code (services, managers, startup hooks). +- Migration step `.to()` version must match the release version so smartmigration can plan the step. +- Steps must be idempotent — smartmigration may re-run them in skip-forward resume mode. diff --git a/changelog.md b/changelog.md index ef0070e..9622029 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-04-13 - 13.16.1 - fix(migrations) +use exact smartdata collection names in route unification migration + +- Update the 13.16.0 migration to rename StoredRouteDoc to RouteDoc using case-sensitive collection names +- Apply the origin backfill against the RouteDoc collection and drop RouteOverrideDoc with matching class-name casing +- Clarify migration description and comments to reflect smartdata's exact class-name collection mapping + ## 2026-04-13 - 13.16.0 - feat(routes) unify route storage and management across config, email, dns, and API origins diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 27ca71a..914b5dc 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/dcrouter', - version: '13.16.0', + version: '13.16.1', description: 'A multifaceted routing service handling mail and SMS delivery functions.' } diff --git a/ts_migrations/index.ts b/ts_migrations/index.ts index 35e517f..d7a3105 100644 --- a/ts_migrations/index.ts +++ b/ts_migrations/index.ts @@ -95,30 +95,30 @@ export async function createMigrationRunner( }) .step('unify-routes-rename-collection') .from('13.8.2').to('13.16.0') - .description('Rename storedroutedoc → routedoc, add origin field, drop routeoverridedoc') + .description('Rename StoredRouteDoc → RouteDoc, add origin field, drop RouteOverrideDoc') .up(async (ctx) => { const db = ctx.mongo!; - // 1. Rename storedroutedoc → routedoc - const collections = await db.listCollections({ name: 'storedroutedoc' }).toArray(); + // 1. Rename StoredRouteDoc → RouteDoc (smartdata uses exact class names) + const collections = await db.listCollections({ name: 'StoredRouteDoc' }).toArray(); if (collections.length > 0) { - await db.renameCollection('storedroutedoc', 'routedoc'); - ctx.log.log('info', 'Renamed storedroutedoc → routedoc'); + await db.renameCollection('StoredRouteDoc', 'RouteDoc'); + ctx.log.log('info', 'Renamed StoredRouteDoc → RouteDoc'); } // 2. Set origin='api' on all migrated docs (they were API-created) - const routeCol = db.collection('routedoc'); + const routeCol = db.collection('RouteDoc'); const result = await routeCol.updateMany( { origin: { $exists: false } }, { $set: { origin: 'api' } }, ); ctx.log.log('info', `Set origin='api' on ${result.modifiedCount} migrated route(s)`); - // 3. Drop routeoverridedoc collection - const overrideCollections = await db.listCollections({ name: 'routeoverridedoc' }).toArray(); + // 3. Drop RouteOverrideDoc collection + const overrideCollections = await db.listCollections({ name: 'RouteOverrideDoc' }).toArray(); if (overrideCollections.length > 0) { - await db.collection('routeoverridedoc').drop(); - ctx.log.log('info', 'Dropped routeoverridedoc collection'); + await db.collection('RouteOverrideDoc').drop(); + ctx.log.log('info', 'Dropped RouteOverrideDoc collection'); } }); diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index 27ca71a..914b5dc 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/dcrouter', - version: '13.16.0', + version: '13.16.1', description: 'A multifaceted routing service handling mail and SMS delivery functions.' }