# Mastodon Upgrade Session - 2026-05-17

## Current Status

### Completed
1. **Removed Twitter/X UI** - Stopped and disabled molttwit-ui (Next.js app)
2. **Restored Standard Mastodon UI** - Nginx routing now points to Mastodon backend
3. **Fixed Asset Loading** - Created symlinks for Vite assets in `/packs/` directory
4. **Updated Molttwit Branding**:
   - Site title: "Molttwit"
   - Description: "A modern social media platform built with Mastodon"
   - Contact email: "info@molttwit.com"
   - Updated 404 and 500 error pages

### Current Configuration
- **URL**: https://molttwit.com
- **Mastodon Version**: v4.5.5
- **Branch**: feature/x-ui-redesign
- **Database**: PostgreSQL 13.23 (port 5432)
- **Services**: mastodon-web, mastodon-streaming, mastodon-sidekiq (running)

### Archived Items
- molttwit-ui (Twitter-style UI): `/home/ashraffarid2010/molttwit-ui.archive.20260517_044054`
- Old nginx config: `/etc/nginx/conf.d/00-molttwit.com.conf.backup-20260517`

### Backup Created
- Database: `/home/ashraffarid2010/backups/mastodon_pre_upgrade_20260517_044500.dump`

## Current Issue: PostgreSQL 14 Required

**Problem**: Latest Mastodon requires PostgreSQL 14+, but:
- PostgreSQL 13.23 is running (port 5432)
- PostgreSQL 14 is installed but **FAILED** due to port conflict

**PostgreSQL 14 Error**:
```
LOG: could not bind IPv4 address "127.0.0.1": Address already in use
HINT: Is another postmaster already running on port 5433?
```

**Port Conflict Details**:
- PostgreSQL 13 is using port 5432 (configured in .env.production)
- PostgreSQL 14 is trying to use port 5433 (default config)
- Both are conflicting with existing socket

## Next Steps to Complete Upgrade

### Option 1: Upgrade with PostgreSQL 13 (Recommended - Less Disruption)
Since v4.5.5 already works with PostgreSQL 13, check if latest main branch actually requires v14:

```bash
cd /home/ashraffarid2010/agentshub.social/live
grep -r "postgres" README.md | grep "14+"
# If it says 14+, we MUST upgrade PostgreSQL first
```

### Option 2: Fix PostgreSQL 14 and Upgrade

1. **Change PostgreSQL 14 port** to avoid conflict:
```bash
# Edit PostgreSQL 14 config to use port 5434
sudo sed -i 's/port = 5433/port = 5434/' /var/lib/pgsql/14/data/postgresql.conf

# Start PostgreSQL 14
sudo systemctl start postgresql-14
```

2. **Migrate database from v13 to v14**:
```bash
# Stop Mastodon services
systemctl stop mastodon-web mastodon-streaming mastodon-sidekiq

# Backup PostgreSQL 13 database
PGPASSWORD=mastodon_db_b3a1513396c45358932410281bf9f887 pg_dump -Fc \
    mastodon_production -h 127.0.0.1 -p 5432 -U mastodon \
    > /home/ashraffarid2010/backups/mastodon_pg13_backup.dump

# Create database in PostgreSQL 14
sudo -u postgres /usr/pgsql-14/bin/psql -p 5434 -c "CREATE DATABASE mastodon_production OWNER mastodon;"

# Restore to PostgreSQL 14
PGPASSWORD=mastodon_db_b3a1513396c45358932410281bf9f887 pg_restore -Fc \
    -h 127.0.0.1 -p 5434 -U mastodon -d mastodon_production \
    /home/ashraffarid2010/backups/mastodon_pg13_backup.dump

# Update .env.production to use port 5434
sed -i 's/DB_PORT=5432/DB_PORT=5434/' /home/ashraffarid2010/agentshub.social/live/.env.production
```

3. **Continue with Mastodon Upgrade**:
```bash
cd /home/ashraffarid2010/agentshub.social/live

# Fetch latest from GitHub
git fetch origin main

# Create upgrade branch
git checkout -b upgrade-to-latest-$(date +%Y%m%d)

# Merge latest main
git merge origin/main -m "Merge latest main from GitHub"

# Install dependencies
bundle install --deployment --without development test

# Run migrations
RAILS_ENV=production bundle exec rails db:migrate

# Recompile assets (will fail without yarn - need to fix yarn first)
# Skip assets for now, use existing symlinks

# Restart services
systemctl restart mastodon-web mastodon-streaming mastodon-sidekiq
```

4. **Reapply Molttwit Branding**:
```bash
RAILS_ENV=production bundle exec rails runner "
Setting.site_title = 'Molttwit'
Setting.site_description = 'A modern social media platform built with Mastodon'
Setting.site_extended_description = 'Welcome to Molttwit! This is a modern social media platform.'
Setting.admin_contact = 'info@molttwit.com'
"

# Recreate asset symlinks
/home/ashraffarid2010/agentshub.social/live/scripts/create-asset-symlinks.sh
```

### Option 3: Stay on v4.5.5 (Simplest)
Current setup is working well. Consider staying on v4.5.5 unless there are specific features needed from newer versions.

## Files Modified

1. `/etc/nginx/conf.d/00-molttwit.com.conf` - Nginx routing to Mastodon
2. `/home/ashraffarid2010/agentshub.social/live/.env.production` - Database config
3. `/home/ashraffarid2010/agentshub.social/live/public/404.html` - Molttwit branding
4. `/home/ashraffarid2010/agentshub.social/live/public/500.html` - Molttwit branding
5. Asset symlinks in `/home/ashraffarid2010/agentshub.social/live/public/packs/`

## Database Credentials (from .env.production)
- DB_HOST: 127.0.0.1
- DB_PORT: 5432
- DB_USER: mastodon
- DB_PASS: mastodon_db_b3a1513396c45358932410281bf9f887
- DB_NAME: mastodon_production

## Service Status
```
● mastodon-web      - Running (port 4004)
● mastodon-streaming - Running (port 4005)
● mastodon-sidekiq  - Running
● molttwit-ui       - Disabled
```

## Verification Commands
```bash
# Check API
curl -s https://molttwit.com/api/v1/instance | jq '.version,.uri,.title'

# Check services
systemctl status mastodon-web mastodon-streaming mastodon-sidekiq

# Check PostgreSQL
systemctl status postgresql-14
psql --version

# Check git status
cd /home/ashraffarid2010/agentshub.social/live
git status
git log -1 --oneline
```

## Continue Session
To continue working on the upgrade, use the command:
```
cd /home/ashraffarid2010/agentshub.social/live
```

Focus on:
1. Fix PostgreSQL 14 port conflict
2. Migrate database to v14
3. Upgrade Mastodon to latest main
4. Reapply branding
5. Recompile assets (need yarn/npm fixed)
