⚡ Quick Deploy: Database-Driven PDF Templates
Ready in 2 minutes! ✅
🎯 What This Does
Moves your 4 PDF templates from files → database
Why?
- ✅ Update templates without deployments
- ✅ Customize per business
- ✅ Industry standard approach
- ✅ Consistent with email/SMS templates
🚀 3 Commands to Run
1. Run Migration (30 seconds)
cd /Users/luisrangel/devLR/rpa/flowpos-workspace/apps/backend
pnpm run migration:run
Look for:
✅ Added 'pdf' channel
✅ Inserted 4 PDF templates:
📄 Invoice PDF - Standard
📄 Payment Receipt PDF - Standard
📄 Order Confirmation PDF - Standard
📄 General Communication PDF - Flexible
✅ PDF templates migration complete!
2. No Code Changes Needed!
Everything is backwards compatible! Your existing code will work as-is.
3. Test It (30 seconds)
# Use your existing PDF generation endpoint
curl -X POST 'http://localhost:4000/communications/generate-pdf' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{
"templateType": "invoice",
"templateData": {
"invoiceNumber": "TEST-DB-001",
"companyName": "RPA Solution",
"customerName": "Test",
"totalAmount": "$100.00"
}
}'
Check logs for:
[CommunicationPdfService] Loaded system template: invoice
[CommunicationPdfService] PDF generated successfully
✅ Success Indicators
- Migration output shows "✅ Inserted 4 PDF templates"
- Logs show "Loaded system template: invoice"
- PDF generation still works
- PDF opens correctly
- No errors in console
📊 What Changed
| Aspect | Before | After |
|---|---|---|
| Template Storage | Files | Database |
| Updates Require | Deployment | SQL query |
| Per-Business | No | Yes (ready) |
| Caching | No | Yes (5 min) |
| Your Code | Works | Still works! ✅ |
🎨 Future: Update Templates
Without deployment:
-- Update invoice template
UPDATE communication_template
SET body_template = '<html>... new design ...</html>'
WHERE channel = 'pdf'
AND type = 'invoice'
AND business_id IS NULL;
Then:
// Clear cache (add this endpoint later)
POST /admin/templates/clear-cache
🐛 If Something Goes Wrong
Migration Fails?
# Check what happened
cd apps/backend
pnpm run migration:status
# Rollback if needed
pnpm run migration:rollback
PDFs Not Working?
# Check if templates exist
psql -d your_database -c "
SELECT name, type FROM communication_template
WHERE channel = 'pdf';
"
# Should show 4 templates
"No PDF template found" Error?
Re-run migration:
cd apps/backend
pnpm run migration:run
🎉 That's It!
Just run the migration and you're done!
cd apps/backend && pnpm run migration:run
Your PDFs will now come from the database 🗄️📄
Time Required: ~2 minutes
Code Changes: None required
Breaking Changes: None
Risk Level: ⭐ Low (backwards compatible)
Ready? Go! 🚀