3.0 KiB
3.0 KiB
Database Migrations
This directory contains SQL migration scripts for manual database updates.
Running Migrations
Method 1: Using psql (Recommended)
# 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
# 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
- Open pgAdmin or your database GUI
- Connect to your
portfoliodatabase - Open Query Tool
- Copy and paste the contents of
create_activity_status.sql - Execute the query
Verifying Migration
After running the migration, verify it was successful:
# 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_statustable with all necessary columns - Inserts a default row with
id = 1 - Sets up automatic
updated_attimestamp trigger - Adds table comment for documentation
Required by:
/api/n8n/statusendpointActivityFeedcomponent- 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:
GRANT CREATE ON DATABASE portfolio TO your_user;
"database does not exist"
Create the database first:
createdb portfolio
# Or
psql -c "CREATE DATABASE portfolio;"
"connection refused"
Ensure PostgreSQL is running:
# 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:
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:
- Create a new
.sqlfile with descriptive name - Use timestamps in filename:
YYYYMMDD_description.sql - Document what it does in this README
- Test on local database first
- Mark as safe/unsafe for production
Last Updated: 2024-01-15 Status: Required for n8n integration