Spaces:
Runtime error
Runtime error
|
Download migrations/README.md from WebashalarForML/scratch_chat: direct link, hf CLI and curl.
- Browser
- Download file 3.87 kB
-
https://huggingface.co/spaces/WebashalarForML/scratch_chat/resolve/main/migrations/README.md
- Command line
-
hf download hf://spaces/WebashalarForML/scratch_chat/migrations/README.md
-
curl -L -o README.md https://huggingface.co/spaces/WebashalarForML/scratch_chat/resolve/main/migrations/README.md
3.87 kB
Database Migrations
This directory contains database migration scripts for the chat agent application.
Overview
The chat agent uses PostgreSQL as the primary database with the following tables:
chat_sessions: Stores user chat sessions with language context and activity trackingmessages: Stores individual chat messages with role, content, and language informationlanguage_contexts: Stores session-specific language settings and prompt templatessupported_languages: Reference table for supported programming languages
Migration Files
001_initial_schema.sql: Initial database schema with all core tablesmigrate.py: Python migration runner script
Usage
Using the Python Migration Script
# Run all pending migrations
python migrations/migrate.py migrate
# Check migration status
python migrations/migrate.py status
# Run migrations for specific environment
python migrations/migrate.py migrate --config production
# Run migrations with custom database URL
python migrations/migrate.py migrate --database-url postgresql://user:pass@localhost/mydb
Using the Database Management CLI
# Initialize database (create tables)
python manage_db.py init
# Reset database (drop and recreate all tables)
python manage_db.py reset
# Get database information
python manage_db.py info
# Get database statistics
python manage_db.py stats
# Create sample data for testing
python manage_db.py sample
# Clean up old sessions
python manage_db.py cleanup
# Check database connection
python manage_db.py check
Manual SQL Execution
You can also run the SQL migration files directly:
# Connect to PostgreSQL and run the migration
psql -d your_database -f migrations/001_initial_schema.sql
Database Schema
chat_sessions
id: UUID primary keyuser_id: UUID of the session ownerlanguage: Current programming language (default: python)last_active: Timestamp of last activitymessage_count: Total messages in sessionis_active: Whether session is activemetadata: Additional session data (JSON)created_at,updated_at: Timestamps
messages
id: UUID primary keysession_id: Reference to chat_sessionsrole: 'user' or 'assistant'content: Message text contentlanguage: Programming language contexttimestamp: When message was createdmetadata: Additional message data (JSON)created_at,updated_at: Timestamps
language_contexts
id: UUID primary keysession_id: Reference to chat_sessions (unique)language: Programming language codeprompt_template: Custom prompt for the languagesyntax_highlighting: Syntax highlighting schemeupdated_at: When context was last modifiedcreated_at: Creation timestamp
supported_languages
code: Language code (primary key)name: Display namesyntax_highlighting: Highlighting schemefile_extensions: Array of file extensionsprompt_template: Default prompt templatecreated_at: Creation timestamp
Environment Variables
Make sure these environment variables are set:
DATABASE_URL=postgresql://username:password@localhost:5432/chat_agent_db
REDIS_URL=redis://localhost:6379/0
Development Setup
- Install PostgreSQL and Redis
- Create a database:
createdb chat_agent_db - Set environment variables in
.envfile - Run migrations:
python manage_db.py init - Optionally create sample data:
python manage_db.py sample
Production Deployment
- Set up PostgreSQL database
- Configure environment variables
- Run migrations:
python migrations/migrate.py migrate --config production - Verify setup:
python manage_db.py check --config production