Spaces:
Sleeping

edi.chat.test / scripts /init-mongo.js
Claude Code Bot
Claude
Deploy edi.chat UGA AI Assistant to Hugging Face Spaces
0b355ec
Raw History Blame Contribute Delete
9.09 kB
// MongoDB initialization script
// This script runs when the MongoDB container first starts
print('Initializing UGA Chatbot database...');
// Switch to the uga_chatbot database
db = db.getSiblingDB('uga_chatbot');
// Create collections with validation
db.createCollection('users', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['ugaId', 'email', 'firstName', 'lastName', 'role'],
properties: {
ugaId: { bsonType: 'string' },
email: { bsonType: 'string' },
firstName: { bsonType: 'string' },
lastName: { bsonType: 'string' },
role: { enum: ['student', 'faculty', 'admin'] },
classification: { bsonType: 'string' },
major: { bsonType: 'string' },
college: { bsonType: 'string' },
phone: { bsonType: 'string' },
address: { bsonType: 'string' },
preferences: { bsonType: 'object' },
lastLogin: { bsonType: 'date' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('conversations', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['userId', 'title', 'category'],
properties: {
userId: { bsonType: 'objectId' },
title: { bsonType: 'string' },
category: { bsonType: 'string' },
lastActivity: { bsonType: 'date' },
messageCount: { bsonType: 'int' },
archived: { bsonType: 'bool' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('messages', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['conversationId', 'role', 'content'],
properties: {
conversationId: { bsonType: 'objectId' },
role: { enum: ['user', 'assistant'] },
content: { bsonType: 'string' },
metadata: { bsonType: 'object' },
tokens: { bsonType: 'int' },
timestamp: { bsonType: 'date' },
createdAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('knowledgebase', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['title', 'content', 'category'],
properties: {
title: { bsonType: 'string' },
content: { bsonType: 'string' },
category: { bsonType: 'string' },
tags: { bsonType: 'array', items: { bsonType: 'string' } },
helpful: { bsonType: 'int' },
views: { bsonType: 'int' },
lastUpdated: { bsonType: 'date' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
db.createCollection('agentactions', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['userId', 'action', 'status'],
properties: {
userId: { bsonType: 'objectId' },
conversationId: { bsonType: 'objectId' },
messageId: { bsonType: 'objectId' },
action: { bsonType: 'string' },
parameters: { bsonType: 'object' },
status: { enum: ['pending', 'in_progress', 'completed', 'failed'] },
result: { bsonType: 'object' },
error: { bsonType: 'string' },
executionTime: { bsonType: 'int' },
createdAt: { bsonType: 'date' },
updatedAt: { bsonType: 'date' }
}
}
}
});
// Create indexes for performance
print('Creating database indexes...');
// Users collection indexes
db.users.createIndex({ ugaId: 1 }, { unique: true });
db.users.createIndex({ email: 1 }, { unique: true });
db.users.createIndex({ role: 1 });
db.users.createIndex({ createdAt: 1 });
// Conversations collection indexes
db.conversations.createIndex({ userId: 1 });
db.conversations.createIndex({ lastActivity: -1 });
db.conversations.createIndex({ category: 1 });
db.conversations.createIndex({ userId: 1, lastActivity: -1 });
// Messages collection indexes
db.messages.createIndex({ conversationId: 1 });
db.messages.createIndex({ timestamp: -1 });
db.messages.createIndex({ conversationId: 1, timestamp: 1 });
db.messages.createIndex({ role: 1 });
// Knowledge base collection indexes
db.knowledgebase.createIndex({ title: 'text', content: 'text', tags: 'text' });
db.knowledgebase.createIndex({ category: 1 });
db.knowledgebase.createIndex({ views: -1 });
db.knowledgebase.createIndex({ helpful: -1 });
db.knowledgebase.createIndex({ lastUpdated: -1 });
// Agent actions collection indexes
db.agentactions.createIndex({ userId: 1 });
db.agentactions.createIndex({ conversationId: 1 });
db.agentactions.createIndex({ status: 1 });
db.agentactions.createIndex({ action: 1 });
db.agentactions.createIndex({ createdAt: -1 });
// Create admin user if it doesn't exist
print('Creating admin user...');
const adminExists = db.users.findOne({ email: 'admin@uga.edu' });
if (!adminExists) {
db.users.insertOne({
ugaId: '000000000',
email: 'admin@uga.edu',
firstName: 'System',
lastName: 'Administrator',
role: 'admin',
preferences: {
notifications: {
email: true,
push: true,
sms: false
},
appearance: {
theme: 'light',
language: 'en'
}
},
createdAt: new Date(),
updatedAt: new Date()
});
print('Admin user created');
} else {
print('Admin user already exists');
}
// Seed knowledge base with essential UGA information
print('Seeding knowledge base...');
const essentialArticles = [
{
title: 'How to Register for Classes',
content: 'To register for classes at UGA, you need to use the Athena student information system. First, log in to Athena with your MyID credentials. Then navigate to Student Services > Registration. Check your registration time ticket to see when you can register. Search for classes by subject, course number, or instructor. Add classes to your cart and then enroll when your time ticket opens.',
category: 'academics',
tags: ['registration', 'athena', 'courses', 'enrollment'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'UGA MyID and ArchPass Authentication',
content: 'MyID is your universal UGA login that provides access to all university systems. ArchPass (powered by Duo) provides two-factor authentication for enhanced security. To set up ArchPass, go to archpass.uga.edu, log in with your MyID, and follow the instructions to register your device. You can use the Duo Mobile app, SMS, or phone calls for verification.',
category: 'technology',
tags: ['myid', 'archpass', 'duo', 'authentication', '2fa'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Financial Aid and HOPE Scholarship',
content: 'UGA offers various financial aid options including HOPE Scholarship, Pell Grants, and student loans. To apply for financial aid, complete the FAFSA form. HOPE Scholarship requires maintaining a 3.0 GPA for continued eligibility. Check your financial aid status in Athena under Financial Aid. For questions, contact the Financial Aid Office at 706-542-6147.',
category: 'financial',
tags: ['financial aid', 'hope', 'fafsa', 'scholarships', 'grants'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Campus Dining Locations and Hours',
content: 'UGA has numerous dining locations across campus. Major dining halls include ECV (East Campus Village), Oglethorpe House, Snelling, and Bolton. Most dining halls are open for breakfast, lunch, and dinner with extended hours during the week. Use your meal plan or Paw Points to pay. Check the UGA Dining website or mobile app for current hours and menus.',
category: 'campus-life',
tags: ['dining', 'food', 'meal-plan', 'hours', 'ecv'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
},
{
title: 'Getting Help from EITS',
content: 'Enterprise Information Technology Services (EITS) provides IT support for students, faculty, and staff. Contact EITS by phone at 706-542-3106, email at helpdesk@uga.edu, or visit the Help Desk in the Miller Learning Center. EITS can help with MyID issues, software problems, network connectivity, and more. Online chat support is also available.',
category: 'technology',
tags: ['eits', 'help-desk', 'it-support', 'technical-help'],
helpful: 0,
views: 0,
lastUpdated: new Date(),
createdAt: new Date(),
updatedAt: new Date()
}
];
// Insert articles if they don't exist
essentialArticles.forEach(article => {
const exists = db.knowledgebase.findOne({ title: article.title });
if (!exists) {
db.knowledgebase.insertOne(article);
print(`Inserted article: ${article.title}`);
}
});
print('Database initialization completed successfully!');
print('Collections created:', db.getCollectionNames().length);
print('Indexes created for optimal performance');
print('Essential knowledge base articles seeded');