fix(migrations): use exact smartdata collection names in route unification migration
This commit is contained in:
@@ -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');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user