Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.1 KB
Raw Blame
require('dotenv').config();
const mongoose = require('mongoose');
const { backfillSearchTokens } = require('@librechat/data-schemas');
const connect = require('./connect');

/**
 * Backfills the word-prefix search tokens on users and groups saved before they existed.
 * Idempotent; safe to run while the server is up.
 *
 * Usage: npm run migrate:search-tokens [-- --dry-run] [-- --batch-size=500]
 */
(async () => {
  let exitCode = 0;
  try {
    await connect();
    const batchArg = process.argv.find((arg) => arg.startsWith('--batch-size='));
    const result = await backfillSearchTokens(mongoose.connection, {
      dryRun: process.argv.includes('--dry-run'),
      batchSize: batchArg ? parseInt(batchArg.split('=')[1], 10) || undefined : undefined,
    });
    console.log(JSON.stringify(result, null, 2));
  } catch (error) {
    console.error('Search token migration failed:', error);
    exitCode = 1;
  } finally {
    await mongoose.disconnect();
  }
  /** Exit explicitly: with Redis enabled, the cache clients opened on connect keep the process alive. */
  process.exit(exitCode);
})();