Templates Migration Guide
Documentation for Sessions
Property Templates Migration Guide
Overview
This guide explains how to migrate property_templates from space-specific databases to the global gograb-core database.
Problem
Previously, property templates were incorrectly stored in space-specific databases:
- ❌
space_chrome-space-1_79fe44376823.property_templates - ❌
space_test-space_abc123.property_templates
They should be stored globally in:
- ✅
gograb-core.core_property_templates
Solution
We've created a safe, automated migration process that:
- Scans all space databases for property_templates
- Copies templates to gograb-core (deduplicating by ID)
- Preserves original data (no destructive operations)
- Updates the PropertiesService to use gograb-core going forward
Migration Steps
Step 1: Dry Run (Recommended)
First, perform a dry run to see what will be migrated without modifying any data:
# Using curl
curl -X POST "http://localhost:3000/api/spaces/any-space-id/properties/migrate-templates-to-core?dryRun=true"
# Or using httpie
http POST "http://localhost:3000/api/spaces/any-space-id/properties/migrate-templates-to-core?dryRun=true"
Note: The spaceId parameter doesn't matter for this endpoint - it scans all spaces.
Expected Output:
{
"success": true,
"data": {
"success": true,
"spacesScanned": 5,
"templatesFound": 30,
"templatesMigrated": 25,
"templatesDeduplicated": 5,
"errors": [],
"details": [
{
"spaceId": "679fe44376823",
"spaceName": "Chrome Space 1",
"databaseName": "space_chrome-space-1_79fe44376823",
"templatesFound": 10,
"templatesMigrated": 8,
"templates": ["template_sizing_dimensions", "template_spacing", ...]
}
]
}
}
Step 2: Review Results
Check the dry run output for:
- spacesScanned: Number of spaces checked
- templatesFound: Total templates in all space databases
- templatesMigrated: Templates that will be copied to gograb-core
- templatesDeduplicated: Templates already in gograb-core (skipped)
- errors: Any errors encountered (should be empty)
Step 3: Perform Migration
If the dry run looks good, run the actual migration:
# Using curl
curl -X POST "http://localhost:3000/api/spaces/any-space-id/properties/migrate-templates-to-core?dryRun=false"
# Or using httpie
http POST "http://localhost:3000/api/spaces/any-space-id/properties/migrate-templates-to-core?dryRun=false"
Step 4: Verify Migration
Check the gograb-core.core_property_templates collection in MongoDB Compass:
- Open MongoDB Compass
- Connect to your MongoDB instance
- Navigate to
gograb-coredatabase - Open
core_property_templatescollection - Verify all templates are present
Step 5: Test Application
After migration:
- Restart your backend API:
yarn serve:backend - Test creating/editing widgets to ensure templates load correctly
- Check browser console for any errors
- Verify templates appear in the property panel
Step 6: Cleanup (Optional)
After verifying everything works, you can optionally remove the old property_templates collections from space databases.
⚠️ WARNING: This is destructive and cannot be undone! Only do this after thorough testing.
# Clean up a specific space (replace with actual spaceId)
curl -X DELETE "http://localhost:3000/api/spaces/679fe44376823/properties/cleanup-space-templates"
To clean up all spaces, you'll need to call this endpoint for each space ID.
What Changed
Before Migration
- Templates stored per-space:
space_{slug}_{id}.property_templates - Each space had its own copy of templates
- Creating new spaces required seeding templates
After Migration
- Templates stored globally:
gograb-core.core_property_templates - All spaces share the same templates
- New templates automatically available to all spaces
- Reduces database redundancy and storage
Backward Compatibility
The PropertiesService now:
- Reads from gograb-core first (primary)
- Falls back to space database if not found (legacy support)
- Writes to gograb-core for new templates
This ensures no disruption during migration.
Troubleshooting
Templates Not Loading
If templates don't load after migration:
- Check backend logs for errors:
# In the backend terminal
# Look for lines starting with 📋 or ❌
- Verify gograb-core collection exists:
# MongoDB shell
use gograb-core
db.core_property_templates.find().count()
- Check for built-in templates:
# Should show at least 10 built-in templates
db.core_property_templates.find({ "metadata.isBuiltIn": true }).count()
Migration Errors
If you see errors in the migration result:
- Check the
errorsarray in the response - Review backend logs for detailed error messages
- Ensure MongoDB connection is stable
- Verify you have write permissions to gograb-core
Rollback
If something goes wrong:
- The original templates are still in space databases (unmodified)
- To rollback, simply remove the migrations by:
# MongoDB shell
use gograb-core
db.core_property_templates.drop()
- The application will fall back to space-specific templates automatically
Testing Checklist
- Dry run completes successfully
- No errors in dry run results
- Migration completes successfully
- Templates visible in MongoDB Compass (gograb-core.core_property_templates)
- Backend restarts without errors
- Widgets load property templates correctly
- Can create new widgets with templates
- Can edit existing widgets
- AI generation uses templates correctly
Support
If you encounter issues:
- Check backend logs:
apis/backend-api/logs - Review MongoDB logs
- Check the migration service code:
apis/backend-api/src/app/properties/property-templates-migration.service.ts - Review the updated PropertiesService:
apis/backend-api/src/app/properties/properties.service.ts
Files Modified
New Files
apis/backend-api/src/app/properties/property-templates-migration.service.ts- Migration logic
Updated Files
apis/backend-api/src/app/properties/properties.service.ts- Now uses gograb-coreapis/backend-api/src/app/properties/properties.controller.ts- Added migration endpointsapis/backend-api/src/app/properties/properties.module.ts- Added migration service
Architecture After Migration
┌─────────────────────┐
│ gograb-core │
│ ┌───────────────┐ │
│ │ core_property_│ │ ← All templates here
│ │ templates │ │
│ └───────────────┘ │
└─────────────────────┘
↑
│ PropertiesService reads from here
│
┌─────────────────────┐
│ All Spaces │
│ - Chrome Space 1 │
│ - Test Space │
│ - Production Space │
└─────────────────────┘
Next Steps
After successful migration:
- Monitor the system for a few days
- If stable, proceed with cleanup (Step 6)
- Update documentation to reflect new architecture
- Consider adding more global templates to gograb-core
Risk Level: Low (non-destructive, with rollback)