===============================================================================
AUTO-DEPLOY SETUP - Fix Database Disconnection After Git Pull
===============================================================================

PROBLEM YOU'RE EXPERIENCING:
- Git auto-pulls new code to production
- Database stops connecting
- You have to manually run deploy.sh to fix it

SOLUTION:
Automatic service restart after every git pull!

===============================================================================
INSTALLATION (Run Once on Production Server)
===============================================================================

SSH into your production server and navigate to Connect-5 directory, then run:

bash setup-auto-deploy.sh

That's it! The script will:
✅ Install a git post-merge hook
✅ Detect your service manager (PM2/systemd/manual)
✅ Configure automatic restart after git pull

===============================================================================
HOW IT WORKS
===============================================================================

After installation, every time git pulls new code:

1. Git auto-pull happens (your existing automation)
2. Git triggers the post-merge hook automatically
3. Hook checks if package.json changed → runs npm install if needed
4. Hook restarts the Node.js service automatically
5. Database reconnects immediately
6. No manual intervention needed!

===============================================================================
WHAT'S INCLUDED
===============================================================================

📁 git-hooks/post-merge
   - The hook script that runs after git pull
   - Handles: npm install + service restart
   - Works with: PM2, systemd, or manual process restart

📜 setup-auto-deploy.sh
   - One-time setup script
   - Copies hook to .git/hooks/
   - Makes it executable
   - Tests which service manager you're using

===============================================================================
QUICK SETUP (Copy/Paste This)
===============================================================================

On your production server:

cd /path/to/Connect-5
bash setup-auto-deploy.sh

Answer "y" when asked to test the hook.

===============================================================================
VERIFICATION
===============================================================================

After setup, test it:

1. Make a small change to README.md on your local machine
2. Git push from local
3. Wait for server to auto-pull (your existing setup)
4. SSH into server and check:
   
   # Check if service restarted
   pm2 logs connect5
   # OR
   sudo systemctl status connect5
   # OR
   tail -f server.log

5. You should see:
   "🔄 Git Pull Detected - Running Auto-Deploy"
   "✅ Auto-Deploy Complete!"

===============================================================================
NO MORE MANUAL DEPLOYS!
===============================================================================

Before: Git pulls → Database disconnects → You run deploy.sh manually
After:  Git pulls → Hook runs → Service restarts → Database reconnects ✅

You'll never need to run deploy.sh manually again for database connection issues!

===============================================================================
ROLLBACK (If Needed)
===============================================================================

To disable auto-deploy:

rm .git/hooks/post-merge

To re-enable:

bash setup-auto-deploy.sh

===============================================================================
