feat(routes): unify route storage and management across config, email, dns, and API origins

This commit is contained in:
2026-04-13 17:38:23 +00:00
parent 5fd036eeb6
commit 4aba8cc353
20 changed files with 349 additions and 647 deletions
+28
View File
@@ -92,6 +92,34 @@ export async function createMigrationRunner(
'info',
`rename-record-source-manual-to-local: migrated ${result.modifiedCount} record(s)`,
);
})
.step('unify-routes-rename-collection')
.from('13.8.2').to('13.16.0')
.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();
if (collections.length > 0) {
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 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();
if (overrideCollections.length > 0) {
await db.collection('routeoverridedoc').drop();
ctx.log.log('info', 'Dropped routeoverridedoc collection');
}
});
return migration;