Sindbad~EG File Manager
-- AI Chatbot System Database Schema
-- Creates tables for FAQs, chat history, knowledge base, and document indexing
-- FAQ Management Table
CREATE TABLE IF NOT EXISTS chatbot_faqs (
id INT AUTO_INCREMENT PRIMARY KEY,
question TEXT NOT NULL,
answer TEXT NOT NULL,
category VARCHAR(100) DEFAULT 'General',
keywords TEXT,
is_active BOOLEAN DEFAULT TRUE,
priority INT DEFAULT 0,
view_count INT DEFAULT 0,
helpful_count INT DEFAULT 0,
not_helpful_count INT DEFAULT 0,
created_by INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL,
FULLTEXT INDEX idx_faq_search (question, answer, keywords)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Document Knowledge Base
CREATE TABLE IF NOT EXISTS chatbot_documents (
id INT AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL,
original_filename VARCHAR(255) NOT NULL,
file_path VARCHAR(500) NOT NULL,
file_type VARCHAR(50),
file_size INT,
title VARCHAR(255),
description TEXT,
content_text LONGTEXT,
is_active BOOLEAN DEFAULT TRUE,
uploaded_by INT,
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_indexed_at TIMESTAMP NULL,
FOREIGN KEY (uploaded_by) REFERENCES users(id) ON DELETE SET NULL,
FULLTEXT INDEX idx_doc_content (title, description, content_text)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Chat Conversations
CREATE TABLE IF NOT EXISTS chatbot_conversations (
id INT AUTO_INCREMENT PRIMARY KEY,
session_id VARCHAR(100) NOT NULL,
user_id INT NULL,
user_name VARCHAR(255),
user_email VARCHAR(255),
ip_address VARCHAR(45),
user_agent TEXT,
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_activity_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
is_active BOOLEAN DEFAULT TRUE,
rating INT NULL,
feedback TEXT NULL,
INDEX idx_session (session_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Chat Messages
CREATE TABLE IF NOT EXISTS chatbot_messages (
id INT AUTO_INCREMENT PRIMARY KEY,
conversation_id INT NOT NULL,
message_type ENUM('user', 'bot') NOT NULL,
message TEXT NOT NULL,
context_used JSON,
sources JSON,
response_time_ms INT,
is_helpful BOOLEAN NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (conversation_id) REFERENCES chatbot_conversations(id) ON DELETE CASCADE,
FULLTEXT INDEX idx_message_search (message)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- System Learning / Context
CREATE TABLE IF NOT EXISTS chatbot_context (
id INT AUTO_INCREMENT PRIMARY KEY,
context_type ENUM('page', 'module', 'feature', 'error') NOT NULL,
context_key VARCHAR(255) NOT NULL,
context_title VARCHAR(255),
context_content TEXT,
usage_count INT DEFAULT 0,
last_used_at TIMESTAMP NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY unique_context (context_type, context_key),
FULLTEXT INDEX idx_context_search (context_title, context_content)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Chatbot Settings
CREATE TABLE IF NOT EXISTS chatbot_settings (
id INT AUTO_INCREMENT PRIMARY KEY,
setting_key VARCHAR(100) UNIQUE NOT NULL,
setting_value TEXT,
updated_by INT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (updated_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Insert default settings
INSERT INTO chatbot_settings (setting_key, setting_value) VALUES
('enabled', '1'),
('welcome_message', 'Hello! 👋 I''m your AI assistant. How can I help you today?'),
('chat_welcome_message', 'Need help? Chat with us!'),
('placeholder_text', 'Type your message...'),
('primary_color', '#1E40AF'),
('bot_name', 'Church Assistant'),
('bot_avatar', '🤖'),
('ai_provider', 'local'),
('max_history', '10'),
('response_delay', '500'),
('show_typing_indicator', '1'),
('allow_feedback', '1'),
('learn_from_interactions', '1')
ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value);
-- Insert sample FAQs
INSERT INTO chatbot_faqs (question, answer, category, keywords, priority) VALUES
('How do I register as a member?',
'To register as a member, click on the "Create Account" button on the login page. Fill in your details and submit. You will receive a confirmation email with your login credentials.',
'Membership', 'register,signup,join,create account', 10),
('How can I get my membership card?',
'Your membership card is automatically generated when you are registered in the system. You can view and download it from your member portal dashboard.',
'Membership', 'membership card,download card,get card', 10),
('How do I check in for an event?',
'To check in for an event, go to the event page and look for the "Check In" button. You can also scan the QR code at the event venue for quick check-in.',
'Events', 'check in,event,attendance', 8),
('Where can I find the member directory?',
'The member directory is available in the Members section. You can search for members by name, location, or other criteria.',
'Directory', 'directory,find members,search members', 7),
('How do I update my profile information?',
'Click on your profile icon in the top right corner, select "My Profile", and then click "Edit Profile" to update your information.',
'Profile', 'update profile,edit profile,change information', 9),
('How can I contact the admin?',
'You can contact the admin through the Contact page or by emailing the church office. The contact information is available on the Contact Us page.',
'Support', 'contact,admin,help,support', 6),
('What are the system requirements?',
'The system works on all modern browsers including Chrome, Firefox, Safari, and Edge. Make sure JavaScript is enabled for the best experience.',
'Technical', 'requirements,browser,system', 5),
('How do I reset my password?',
'Click on "Forgot Password" on the login page. Enter your email address and you will receive a password reset link.',
'Account', 'password,reset,forgot,login', 9)
ON DUPLICATE KEY UPDATE question=VALUES(question);
-- Insert system context (pages and features)
INSERT INTO chatbot_context (context_type, context_key, context_title, context_content) VALUES
('page', 'dashboard', 'Dashboard', 'The dashboard provides an overview of your account, recent activities, quick actions, and important notifications. You can access all major features from here.'),
('page', 'membership', 'Membership Management', 'The membership section allows you to view and manage member records, generate membership cards, upload bulk members, and track member statistics.'),
('page', 'events', 'Events Management', 'Manage church events, track attendance, enable check-ins with QR codes, and view event statistics.'),
('page', 'directory', 'Member Directory', 'Search and view member information, filter by location (area, district, assembly), and export directory data.'),
('feature', 'bulk_upload', 'Bulk Member Upload', 'Upload multiple members at once using CSV or Excel files. The system automatically creates member records, membership cards, and login accounts.'),
('feature', 'qr_checkin', 'QR Code Check-in', 'Generate QR codes for events that members can scan to check in quickly. View real-time attendance statistics.'),
('feature', 'email_system', 'Email System', 'Send automated emails for welcome messages, event notifications, and member communications. Configure SMTP settings in the Email Management module.')
ON DUPLICATE KEY UPDATE context_content=VALUES(context_content);
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists