Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print an error when index creation fails #4064

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/models/Action.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const actionSchema = require('./schema/action');

const Action = mongoose.model('action', actionSchema);

Action.on('index', (error) => {
if (error) {
logger.error(`Failed to create Action index ${error}`);
}
});

/**
* Update an action with new data without overwriting existing properties,
* or create a new action if it doesn't exist.
Expand Down
7 changes: 7 additions & 0 deletions api/models/Agent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const { GLOBAL_PROJECT_NAME } = require('librechat-data-provider').Constants;
const {
Expand All @@ -10,6 +11,12 @@ const agentSchema = require('./schema/agent');

const Agent = mongoose.model('agent', agentSchema);

Agent.on('index', (error) => {
if (error) {
logger.error(`Failed to create Agent index ${error}`);
}
});

/**
* Create an agent with the provided data.
* @param {Object} agentData - The agent data to create.
Expand Down
7 changes: 7 additions & 0 deletions api/models/Assistant.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const assistantSchema = require('./schema/assistant');

const Assistant = mongoose.model('assistant', assistantSchema);

Assistant.on('index', (error) => {
if (error) {
logger.error(`Failed to create Assistant index ${error}`);
}
});

/**
* Update an assistant with new data without overwriting existing properties,
* or create a new assistant if it doesn't exist.
Expand Down
9 changes: 8 additions & 1 deletion api/models/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ balanceSchema.statics.check = async function ({
return { canSpend: balance >= tokenCost, balance, tokenCost };
};

module.exports = mongoose.model('Balance', balanceSchema);
const Balance = mongoose.model('Balance', balanceSchema);
Balance.on('index', (error) => {
if (error) {
logger.error(`Failed to create Balance index ${error}`);
}
});

module.exports = Balance;
6 changes: 6 additions & 0 deletions api/models/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ configSchema.statics.updateByTag = async function (tag, update) {

const Config = mongoose.models.Config || mongoose.model('Config', configSchema);

Config.on('index', (error) => {
if (error) {
logger.error(`Failed to create Config index ${error}`);
}
});

module.exports = {
getConfigs: async (filter) => {
try {
Expand Down
7 changes: 7 additions & 0 deletions api/models/File.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const fileSchema = require('./schema/fileSchema');

const File = mongoose.model('File', fileSchema);

File.on('index', (error) => {
if (error) {
logger.error(`Failed to create File index ${error}`);
}
});

/**
* Finds a file by its file_id with additional query options.
* @param {string} file_id - The unique identifier of the file.
Expand Down
11 changes: 10 additions & 1 deletion api/models/Key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const keySchema = require('./schema/key');

module.exports = mongoose.model('Key', keySchema);
const Key = mongoose.model('Key', keySchema);

Key.on('index', (error) => {
if (error) {
logger.error(`Failed to create Key index ${error}`);
}
});

module.exports = Key;
6 changes: 6 additions & 0 deletions api/models/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ sessionSchema.statics.deleteAllUserSessions = async function (userId) {

const Session = mongoose.model('Session', sessionSchema);

Session.on('index', (error) => {
if (error) {
logger.error(`Failed to create Session index ${error}`);
}
});

module.exports = Session;
6 changes: 6 additions & 0 deletions api/models/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const { logger } = require('~/config');
*/
const Token = mongoose.model('Token', tokenSchema);

Token.on('index', (error) => {
if (error) {
logger.error(`Failed to create Token index ${error}`);
}
});

/**
* Creates a new Token instance.
* @param {Object} tokenData - The data for the new Token.
Expand Down
6 changes: 6 additions & 0 deletions api/models/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ transactionSchema.methods.calculateStructuredTokenValue = function () {

const Transaction = mongoose.model('Transaction', transactionSchema);

Transaction.on('index', (error) => {
if (error) {
logger.error(`Failed to create Transaction index ${error}`);
}
});

/**
* Queries and retrieves transactions based on a given filter.
* @async
Expand Down
7 changes: 7 additions & 0 deletions api/models/User.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const userSchema = require('~/models/schema/userSchema');

const User = mongoose.model('User', userSchema);

User.on('index', (error) => {
if (error) {
logger.error(`Failed to create User index ${error}`);
}
});

module.exports = User;
8 changes: 8 additions & 0 deletions api/models/schema/banner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');

const bannerSchema = mongoose.Schema(
Expand Down Expand Up @@ -33,4 +34,11 @@ const bannerSchema = mongoose.Schema(
);

const Banner = mongoose.model('Banner', bannerSchema);

Banner.on('index', (error) => {
if (error) {
logger.error(`Failed to create Banner index ${error}`);
}
});

module.exports = Banner;
11 changes: 9 additions & 2 deletions api/models/schema/categories.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

Expand All @@ -14,6 +15,12 @@ const categoriesSchema = new Schema({
},
});

const categories = mongoose.model('categories', categoriesSchema);
const Categories = mongoose.model('categories', categoriesSchema);

module.exports = { Categories: categories };
Categories.on('index', (error) => {
if (error) {
logger.error(`Failed to create Categories index ${error}`);
}
});

module.exports = Categories;
11 changes: 10 additions & 1 deletion api/models/schema/conversationTagSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');

const conversationTagSchema = mongoose.Schema(
Expand Down Expand Up @@ -28,4 +29,12 @@ const conversationTagSchema = mongoose.Schema(

conversationTagSchema.index({ tag: 1, user: 1 }, { unique: true });

module.exports = mongoose.model('ConversationTag', conversationTagSchema);
const ConversationTag = mongoose.model('ConversationTag', conversationTagSchema);

ConversationTag.on('index', (error) => {
if (error) {
logger.error(`Failed to create ConversationTag index ${error}`);
}
});

module.exports = ConversationTag;
7 changes: 7 additions & 0 deletions api/models/schema/convoSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const mongoMeili = require('../plugins/mongoMeili');
const { conversationPreset } = require('./defaults');
Expand Down Expand Up @@ -65,4 +66,10 @@ convoSchema.index({ conversationId: 1, user: 1 }, { unique: true });

const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);

Conversation.on('index', (error) => {
if (error) {
logger.error(`Failed to create Conversation index ${error}`);
}
});

module.exports = Conversation;
7 changes: 7 additions & 0 deletions api/models/schema/messageSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const mongoMeili = require('~/models/plugins/mongoMeili');
const messageSchema = mongoose.Schema(
Expand Down Expand Up @@ -134,4 +135,10 @@ messageSchema.index({ messageId: 1, user: 1 }, { unique: true });
/** @type {mongoose.Model<TMessage>} */
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);

Message.on('index', (error) => {
if (error) {
logger.error(`Failed to create Message index ${error}`);
}
});

module.exports = Message;
7 changes: 7 additions & 0 deletions api/models/schema/pluginAuthSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');

const pluginAuthSchema = mongoose.Schema(
Expand All @@ -23,4 +24,10 @@ const pluginAuthSchema = mongoose.Schema(

const PluginAuth = mongoose.models.Plugin || mongoose.model('PluginAuth', pluginAuthSchema);

PluginAuth.on('index', (error) => {
if (error) {
logger.error(`Failed to create PluginAuth index ${error}`);
}
});

module.exports = PluginAuth;
7 changes: 7 additions & 0 deletions api/models/schema/presetSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const { conversationPreset } = require('./defaults');
const presetSchema = mongoose.Schema(
Expand Down Expand Up @@ -36,4 +37,10 @@ const presetSchema = mongoose.Schema(

const Preset = mongoose.models.Preset || mongoose.model('Preset', presetSchema);

Preset.on('index', (error) => {
if (error) {
logger.error(`Failed to create Preset index ${error}`);
}
});

module.exports = Preset;
13 changes: 13 additions & 0 deletions api/models/schema/promptSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');
const { Constants } = require('librechat-data-provider');
const Schema = mongoose.Schema;
Expand Down Expand Up @@ -82,6 +83,12 @@ const promptGroupSchema = new Schema(

const PromptGroup = mongoose.model('PromptGroup', promptGroupSchema);

PromptGroup.on('PromptGroup', (error) => {
if (error) {
logger.error(`Failed to create PromptGroup index ${error}`);
}
});

const promptSchema = new Schema(
{
groupId: {
Expand Down Expand Up @@ -112,6 +119,12 @@ const promptSchema = new Schema(

const Prompt = mongoose.model('Prompt', promptSchema);

Prompt.on('index', (error) => {
if (error) {
logger.error(`Failed to create Prompt index ${error}`);
}
});

promptSchema.index({ createdAt: 1, updatedAt: 1 });
promptGroupSchema.index({ createdAt: 1, updatedAt: 1 });

Expand Down
7 changes: 7 additions & 0 deletions api/models/schema/roleSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const { PermissionTypes, Permissions } = require('librechat-data-provider');
const mongoose = require('mongoose');

Expand Down Expand Up @@ -52,4 +53,10 @@ const roleSchema = new mongoose.Schema({

const Role = mongoose.model('Role', roleSchema);

Role.on('index', (error) => {
if (error) {
logger.error(`Failed to create Role index ${error}`);
}
});

module.exports = Role;
11 changes: 10 additions & 1 deletion api/models/schema/shareSchema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('~/config');
const mongoose = require('mongoose');

const shareSchema = mongoose.Schema(
Expand Down Expand Up @@ -35,4 +36,12 @@ const shareSchema = mongoose.Schema(
{ timestamps: true },
);

module.exports = mongoose.model('SharedLink', shareSchema);
const SharedLink = mongoose.model('SharedLink', shareSchema);

SharedLink.on('index', (error) => {
if (error) {
logger.error(`Failed to create SharedLink index ${error}`);
}
});

module.exports = SharedLink;