Files
back_end_oudelaa/scripts/sync-feature-indexes.js
boutmoun123 674fa77975
API Gateway CI / Build, lint, and test (push) Successful in 14m54s
API Gateway CI / Build API Gateway image (push) Successful in 6m31s
API Gateway CI / Build Notification Service image (push) Successful in 49s
feat: add Music World backend APIs for Flutter
2026-11-22 14:20:32 +03:00

25 lines
1.6 KiB
JavaScript

// Add named feature indexes only. No .env loading and no index deletions.
const mongoose = require('mongoose');
const { PostSchema } = require('../dist/legacy/src/modules/posts/schemas/post.schema');
const { UserSchema } = require('../dist/legacy/src/modules/users/schemas/user.schema');
const { musicIndexes } = require('../dist/legacy/src/modules/music-commerce/music-commerce.store');
async function main() {
const specs = [
{ collection: 'posts', schema: PostSchema, allowed: (name) => name?.startsWith('feed_') || name === 'video_worker_claim_v1' },
{ collection: 'users', schema: UserSchema, allowed: (name) => name?.startsWith('talent_') },
].map(({ collection, schema, allowed }) => ({ collection,
indexes: schema.indexes().filter(([, options]) => allowed(options.name)).map(([key, options]) => ({ key, ...options })) }));
specs.push(...Object.entries(musicIndexes).map(([collection, indexes]) => ({ collection, indexes })));
if (process.argv.includes('--dry-run')) { console.log(JSON.stringify(specs, null, 2)); return; }
if (!process.env.MONGODB_URI) throw new Error('Set MONGODB_URI explicitly');
const connection = await mongoose.createConnection(process.env.MONGODB_URI, { autoIndex: false }).asPromise();
try {
for (const spec of specs) {
const indexes = await connection.collection(spec.collection).createIndexes(spec.indexes);
console.log(JSON.stringify({ collection: spec.collection, indexes }));
}
} finally { await connection.close(); }
}
main().catch(() => { console.error('Feature index synchronization failed; verify the build and database configuration'); process.exitCode = 1; });