Files
portfolio/prisma/migrations/README.md
2026-01-07 14:30:00 +01:00

127 lines
3.0 KiB
Markdown

# 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