Files
formbricks-formbricks/apps/web/modules
Johannes 239f2595ba feat: add ability to copy surveys with all response data
Implements a comprehensive solution for copying surveys to different projects
with all associated response data, including file uploads, contacts, tags,
quotas, and display records.

Key Features:
- UI toggle to choose between 'Survey Only' or 'Survey + Responses' copy modes
- Intelligent file URL rewriting for uploaded files across environments
- Contact mapping/creation in target environment
- Tag find-or-create logic to preserve response tagging
- Quota and display record copying
- Batch processing (100 responses at a time) for performance
- Graceful error handling with detailed logging

Implementation Details:

UI Changes:
- Added OptionsSwitch component to copy-survey-form.tsx
- Visual toggle with icons for copy mode selection
- Descriptive text explaining each mode
- Integrated with React Hook Form validation

Backend Service (copy-survey-responses.ts):
- extractFileUrlsFromResponseData(): Recursively finds storage URLs
- downloadAndReuploadFile(): Rewrites file URLs for target environment
- rewriteFileUrlsInData(): Updates all file references in response data
- mapOrCreateContact(): Handles contact migration
- mapOrCreateTags(): Ensures tags exist in target environment
- copyResponsesForSurvey(): Main orchestration with batching

Core Updates:
- Updated copySurveyToOtherEnvironment() to optionally copy responses
- Extended action schema to accept copyResponses parameter
- Added comprehensive error handling and logging

Technical Approach:
- Preserves original createdAt timestamps for historical accuracy
- Generates new IDs to prevent conflicts
- Maintains data integrity with proper foreign key mapping
- Handles partial failures gracefully (survey copy succeeds even if some responses fail)

Edge Cases Handled:
- File uploads with environment-specific URLs
- Environment-specific contacts
- Tag name matching across environments
- Quota link preservation
- Display record migration
- Large response datasets via batching

Performance Considerations:
- Batch processing prevents memory issues
- Per-response error handling prevents cascade failures
- Efficient database queries with proper includes

Future Enhancements:
- Progress tracking UI for large datasets
- Background job queue for 10,000+ responses
- Selective response copying (date ranges, filters)

Related to customer request for copying survey data between projects.
2025-10-10 00:00:11 +02:00
..
2025-10-09 09:45:08 +00:00
2025-09-12 08:17:33 +00:00
2025-10-09 09:45:08 +00:00