full upgrade to dev

This commit is contained in:
2026-01-07 14:30:00 +01:00
parent 4dc727fcd6
commit 26a8610aa7
34 changed files with 6890 additions and 920 deletions

127
prisma/migrations/README.md Normal file
View File

@@ -0,0 +1,127 @@
# Database Migrations
This directory contains SQL migration scripts for manual database updates.
## Running Migrations
### Method 1: Using psql (Recommended)
```bash
# Connect to your database
psql -d portfolio -f prisma/migrations/create_activity_status.sql
# Or with connection string
psql "postgresql://user:password@localhost:5432/portfolio" -f prisma/migrations/create_activity_status.sql
```
### Method 2: Using Docker
```bash
# If your database is in Docker
docker exec -i postgres_container psql -U username -d portfolio < prisma/migrations/create_activity_status.sql
```
### Method 3: Using pgAdmin or Database GUI
1. Open pgAdmin or your database GUI
2. Connect to your `portfolio` database
3. Open Query Tool
4. Copy and paste the contents of `create_activity_status.sql`
5. Execute the query
## Verifying Migration
After running the migration, verify it was successful:
```bash
# Check if table exists
psql -d portfolio -c "\dt activity_status"
# View table structure
psql -d portfolio -c "\d activity_status"
# Check if default row was inserted
psql -d portfolio -c "SELECT * FROM activity_status;"
```
Expected output:
```
id | activity_type | ... | updated_at
----+---------------+-----+---------------------------
1 | | ... | 2024-01-15 10:30:00+00
```
## Migration: create_activity_status.sql
**Purpose**: Creates the `activity_status` table for n8n activity feed integration.
**What it does**:
- Creates `activity_status` table with all necessary columns
- Inserts a default row with `id = 1`
- Sets up automatic `updated_at` timestamp trigger
- Adds table comment for documentation
**Required by**:
- `/api/n8n/status` endpoint
- `ActivityFeed` component
- n8n workflows for status updates
**Safe to run multiple times**: Yes (uses `IF NOT EXISTS` and `ON CONFLICT`)
## Troubleshooting
### "relation already exists"
Table already exists - migration is already applied. Safe to ignore.
### "permission denied"
Your database user needs CREATE TABLE permissions:
```sql
GRANT CREATE ON DATABASE portfolio TO your_user;
```
### "database does not exist"
Create the database first:
```bash
createdb portfolio
# Or
psql -c "CREATE DATABASE portfolio;"
```
### "connection refused"
Ensure PostgreSQL is running:
```bash
# Check status
pg_isready
# Start PostgreSQL (macOS)
brew services start postgresql
# Start PostgreSQL (Linux)
sudo systemctl start postgresql
```
## Rolling Back
To remove the activity_status table:
```sql
DROP TRIGGER IF EXISTS activity_status_updated_at ON activity_status;
DROP FUNCTION IF EXISTS update_activity_status_updated_at();
DROP TABLE IF EXISTS activity_status;
```
Save this as `rollback_activity_status.sql` and run if needed.
## Future Migrations
When adding new migrations:
1. Create a new `.sql` file with descriptive name
2. Use timestamps in filename: `YYYYMMDD_description.sql`
3. Document what it does in this README
4. Test on local database first
5. Mark as safe/unsafe for production
---
**Last Updated**: 2024-01-15
**Status**: Required for n8n integration

View File

@@ -0,0 +1,49 @@
-- Create activity_status table for n8n integration
CREATE TABLE IF NOT EXISTS activity_status (
id INTEGER PRIMARY KEY DEFAULT 1,
activity_type VARCHAR(50),
activity_details VARCHAR(255),
activity_project VARCHAR(255),
activity_language VARCHAR(50),
activity_repo VARCHAR(500),
music_playing BOOLEAN DEFAULT FALSE,
music_track VARCHAR(255),
music_artist VARCHAR(255),
music_album VARCHAR(255),
music_platform VARCHAR(50),
music_progress INTEGER,
music_album_art VARCHAR(500),
watching_title VARCHAR(255),
watching_platform VARCHAR(50),
watching_type VARCHAR(50),
gaming_game VARCHAR(255),
gaming_platform VARCHAR(50),
gaming_status VARCHAR(50),
status_mood VARCHAR(50),
status_message VARCHAR(500),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Insert default row
INSERT INTO activity_status (id, updated_at)
VALUES (1, NOW())
ON CONFLICT (id) DO NOTHING;
-- Create function to automatically update updated_at
CREATE OR REPLACE FUNCTION update_activity_status_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Create trigger for automatic timestamp updates
DROP TRIGGER IF EXISTS activity_status_updated_at ON activity_status;
CREATE TRIGGER activity_status_updated_at
BEFORE UPDATE ON activity_status
FOR EACH ROW
EXECUTE FUNCTION update_activity_status_updated_at();
-- Add helpful comment
COMMENT ON TABLE activity_status IS 'Stores real-time activity status from n8n workflows (coding, music, gaming, etc.)';

73
prisma/migrations/quick-fix.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/bash
# Quick Fix Script for Portfolio Database
# This script creates the activity_status table needed for n8n integration
set -e
echo "🔧 Portfolio Database Quick Fix"
echo "================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if .env.local exists
if [ ! -f .env.local ]; then
echo -e "${RED}❌ Error: .env.local not found${NC}"
echo "Please create .env.local with DATABASE_URL"
exit 1
fi
# Load DATABASE_URL from .env.local
export $(grep -v '^#' .env.local | xargs)
if [ -z "$DATABASE_URL" ]; then
echo -e "${RED}❌ Error: DATABASE_URL not found in .env.local${NC}"
exit 1
fi
echo -e "${GREEN}✓ Found DATABASE_URL${NC}"
echo ""
# Extract database name from DATABASE_URL
DB_NAME=$(echo $DATABASE_URL | sed -n 's/.*\/\([^?]*\).*/\1/p')
echo "📦 Database: $DB_NAME"
echo ""
# Run the migration
echo "🚀 Creating activity_status table..."
echo ""
psql "$DATABASE_URL" -f prisma/migrations/create_activity_status.sql
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}✅ SUCCESS! Migration completed${NC}"
echo ""
echo "Verifying table..."
psql "$DATABASE_URL" -c "\d activity_status" | head -20
echo ""
echo "Checking default row..."
psql "$DATABASE_URL" -c "SELECT id, updated_at FROM activity_status LIMIT 1;"
echo ""
echo -e "${GREEN}🎉 All done! Your database is ready.${NC}"
echo ""
echo "Next steps:"
echo " 1. Restart your Next.js dev server: npm run dev"
echo " 2. Visit http://localhost:3000"
echo " 3. The activity feed should now work without errors"
else
echo ""
echo -e "${RED}❌ Migration failed${NC}"
echo ""
echo "Troubleshooting:"
echo " 1. Ensure PostgreSQL is running: pg_isready"
echo " 2. Check your DATABASE_URL in .env.local"
echo " 3. Verify database exists: psql -l | grep $DB_NAME"
echo " 4. Try manual migration: psql $DB_NAME -f prisma/migrations/create_activity_status.sql"
exit 1
fi