Rustelo/info/sqlite_setup.md
Jesús Pérex 2f0f807331 feat: add dark mode functionality and improve navigation system
- Add complete dark mode system with theme context and toggle
- Implement dark mode toggle component in navigation menu
- Add client-side routing with SSR-safe signal handling
- Fix language selector styling for better dark mode compatibility
- Add documentation system with mdBook integration
- Improve navigation menu with proper external/internal link handling
- Add comprehensive project documentation and configuration
- Enhance theme system with localStorage persistence
- Fix arena panic issues during server-side rendering
- Add proper TypeScript configuration and build optimizations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 20:53:20 +01:00

4.8 KiB

SQLite Setup Guide

This guide explains how to configure the application to use SQLite instead of PostgreSQL for development.

Important Notes

⚠️ The current authentication system requires PostgreSQL. If you need to use SQLite, you'll need to disable auth features or use PostgreSQL for production.

Option 1: SQLite with Disabled Auth Features

Step 1: Modify Cargo.toml Features

Edit server/Cargo.toml to disable auth features:

[features]
default = ["content-db", "crypto", "email", "metrics", "examples"]
# Remove "auth" from the default features

Step 2: Update Database Configuration

Create or modify config.dev.toml:

[database]
url = "sqlite:data/development.db"
max_connections = 1
min_connections = 1
connect_timeout = 30
idle_timeout = 600
max_lifetime = 1800

Step 3: Create Database Directory

mkdir -p data

Step 4: Run Without Auth Features

cargo run --bin server --no-default-features --features "content-db,crypto,email,metrics"

Using Docker

# Start PostgreSQL in Docker
docker run -d \
  --name rustelo-postgres \
  -e POSTGRES_DB=rustelo_dev \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=password \
  -p 5432:5432 \
  postgres:15

# Wait for PostgreSQL to start
sleep 5

# Test connection
psql -h localhost -U postgres -d rustelo_dev -c "SELECT 1;"

Using Homebrew (macOS)

# Install PostgreSQL
brew install postgresql@15

# Start PostgreSQL service
brew services start postgresql@15

# Create database
createdb rustelo_dev

# Test connection
psql rustelo_dev -c "SELECT 1;"

Using Package Manager (Linux)

# Ubuntu/Debian
sudo apt update
sudo apt install postgresql postgresql-contrib

# CentOS/RHEL
sudo yum install postgresql-server postgresql-contrib

# Start service
sudo systemctl start postgresql
sudo systemctl enable postgresql

# Create database
sudo -u postgres createdb rustelo_dev

# Test connection
sudo -u postgres psql rustelo_dev -c "SELECT 1;"

Option 3: Cloud PostgreSQL

Supabase (Free Tier)

  1. Go to supabase.com
  2. Create a new project
  3. Copy the connection string
  4. Update config.dev.toml:
[database]
url = "postgresql://postgres.xxx:[PASSWORD]@xxx.supabase.co:5432/postgres"

Railway (Free Tier)

  1. Go to railway.app
  2. Create a new PostgreSQL database
  3. Copy the connection string
  4. Update your configuration

Testing SQLite Configuration

If you want to test SQLite-only features:

# Create a test configuration
cat > config.sqlite.toml << 'EOF'
root_path = "."

[server]
protocol = "http"
host = "127.0.0.1"
port = 3030
environment = "development"
log_level = "debug"

[database]
url = "sqlite:data/test.db"
max_connections = 1
min_connections = 1
connect_timeout = 30
idle_timeout = 600
max_lifetime = 1800

[app]
name = "My Rust App"
version = "0.1.0"
debug = true
enable_metrics = false
enable_health_check = true
enable_compression = true
max_request_size = 10485760

[logging]
format = "pretty"
level = "debug"
file_path = "logs/app.log"
max_file_size = 10485760
max_files = 5
enable_console = true
enable_file = false
EOF

# Test with SQLite config
CONFIG_FILE=config.sqlite.toml cargo run --bin server --no-default-features --features "content-db"

Migration Notes

From PostgreSQL to SQLite

  1. Export your PostgreSQL data
  2. Convert schema to SQLite-compatible format
  3. Update connection strings
  4. Test thoroughly

From SQLite to PostgreSQL

  1. Use tools like sqlite3 to dump data
  2. Convert to PostgreSQL format
  3. Update connection strings
  4. Run migrations

Troubleshooting

Common Issues

  1. "Failed to connect to database"

    • Check if PostgreSQL is running
    • Verify connection string
    • Check firewall settings
  2. "Auth features require PostgreSQL"

    • Use PostgreSQL or disable auth features
    • See Option 1 above
  3. "Directory not found" (SQLite)

    • Create the data directory: mkdir -p data
    • Check file permissions

Debug Commands

# Check PostgreSQL status
pg_isready -h localhost -p 5432

# Test SQLite file creation
sqlite3 data/test.db "CREATE TABLE test (id INTEGER); DROP TABLE test;"

# Check configuration loading
RUST_LOG=debug cargo run --bin test_config

Performance Considerations

  • SQLite: Best for development, single-user apps
  • PostgreSQL: Better for production, multi-user apps
  • Connection pooling: PostgreSQL handles concurrent connections better

Security Notes

  • Change default passwords in production
  • Use environment variables for sensitive data
  • Enable SSL/TLS for production databases
  • Regular backups are essential

For more help, see the main README.md or create an issue in the repository.