| import { logger } from '@librechat/data-schemas'; |
| import type { mongo } from 'mongoose'; |
|
|
| |
| |
| |
| |
| |
| |
| export async function ensureCollectionExists(db: mongo.Db, collectionName: string): Promise<void> { |
| try { |
| const collections = await db.listCollections({ name: collectionName }).toArray(); |
| if (collections.length === 0) { |
| await db.createCollection(collectionName); |
| logger.info(`Created collection: ${collectionName}`); |
| } else { |
| logger.debug(`Collection already exists: ${collectionName}`); |
| } |
| } catch (error) { |
| logger.error(`Failed to check/create "${collectionName}" collection:`, error); |
| |
| try { |
| |
| await db.collection(collectionName).findOne({}, { projection: { _id: 1 } }); |
| } catch (createError) { |
| logger.error(`Could not ensure collection ${collectionName} exists:`, createError); |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function ensureRequiredCollectionsExist(db: mongo.Db): Promise<void> { |
| const requiredCollections = [ |
| 'aclentries', |
| 'groups', |
| 'accessroles', |
| 'agents', |
| 'promptgroups', |
| 'projects', |
| ]; |
|
|
| logger.debug('Ensuring required collections exist for permission system'); |
|
|
| for (const collectionName of requiredCollections) { |
| await ensureCollectionExists(db, collectionName); |
| } |
|
|
| logger.debug('All required collections have been checked/created'); |
| } |
|
|