This guide will help you set up PostgreSQL for the Classless AI Tutor application.
- PostgreSQL installed on your system
- Node.js and npm installed
- Git (if cloning the repository)
- Download from postgresql.org
- Run the installer and follow the setup wizard
- Remember the password you set for the
postgresuser
# Using Homebrew
brew install postgresql
brew services start postgresql
# Or using Postgres.app
# Download from https://postgresapp.com/sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresqlConnect to PostgreSQL as the superuser:
# On Windows (if installed with default settings)
psql -U postgres
# On macOS/Linux
sudo -u postgres psqlCreate the database and user:
-- Create database
CREATE DATABASE classless_db;
-- Create user (optional - you can use postgres user)
CREATE USER classless_user WITH PASSWORD 'your_secure_password';
-- Grant privileges
GRANT ALL PRIVILEGES ON DATABASE classless_db TO classless_user;
-- Exit psql
\q# Install PostgreSQL dependencies
npm install
# Or if using yarn
yarn installCreate a .env.local file in the project root:
# Database Configuration
DATABASE_URL=postgresql://classless_user:your_secure_password@localhost:5432/classless_db
DB_HOST=localhost
DB_PORT=5432
DB_NAME=classless_db
DB_USER=classless_user
DB_PASSWORD=your_secure_password
# Existing API Keys (keep your existing ones)
OPENAI_API_KEY=your_openai_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here
PINECONE_API_KEY=your_pinecone_api_key_hereRun the database setup script:
npm run db:setupThis will:
- Create all necessary tables
- Insert default subjects
- Set up indexes for performance
- Verify the setup
npm run db:testnpm run devThe application creates the following tables:
- users - User accounts (students, teachers, admins)
- subjects - Available subjects for quizzes
- questions - User-submitted questions
- answers - AI and teacher answers
- replies - Discussion replies
- quiz_attendance - Quiz participation tracking
- learning_sessions - User learning sessions
- scholarships - Available scholarships
- learning_stations - Physical learning centers
- interaction_logs - User interaction history
- notifications - System notifications
-
Check PostgreSQL is running:
# Windows services.msc # Look for PostgreSQL service # macOS brew services list | grep postgres # Linux sudo systemctl status postgresql
-
Verify credentials in
.env.local -
Check firewall settings (if connecting from remote)
-- Grant additional permissions if needed
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO classless_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO classless_user;-- Drop and recreate database (WARNING: This deletes all data)
DROP DATABASE classless_db;
CREATE DATABASE classless_db;
GRANT ALL PRIVILEGES ON DATABASE classless_db TO classless_user;Then run npm run db:setup again.
- Use connection pooling (already configured)
- Set up SSL for production
- Configure backups
- Monitor performance
- Use environment-specific configurations
If you encounter issues:
- Check the console logs for error messages
- Verify your PostgreSQL installation
- Ensure all environment variables are set correctly
- Check the database connection using
npm run db:test
The application will now use PostgreSQL instead of the mock database, providing persistent storage for all user data, quiz progress, and other information.