Production Data Deletion Feature
Feature and scripts to safely delete all data in the production environment.
⚠️ Important Warning
This feature completely deletes all data in the production environment. Deleted data cannot be restored.
- All Firebase Firestore collections
- All Firebase Auth users
- All Firebase Storage files
Please ensure you create a backup before execution.
Feature Overview
1. Firebase Functions API Endpoint
Endpoint: /api/deleteAllProductionData
API endpoint to delete production data.
Authentication
- Admin Token:
ADMIN_DELETE_ALL_DATA_2024 - Confirmation Code:
DELETE_ALL_PRODUCTION_DATA_CONFIRM
Request Example
bash
curl -X POST https://us-central1-outliner-d57b0.cloudfunctions.net/deleteAllProductionData \
-H "Content-Type: application/json" \
-d '{
"adminToken": "ADMIN_DELETE_ALL_DATA_2024",
"confirmationCode": "DELETE_ALL_PRODUCTION_DATA_CONFIRM"
}'Response Example
json
{
"success": true,
"message": "Production data deletion completed",
"results": {
"firestore": {
"success": true,
"error": null,
"deletedCollections": [
{ "name": "users", "count": 150 },
{ "name": "containers", "count": 300 },
{ "name": "projects", "count": 75 }
]
},
"auth": {
"success": true,
"error": null,
"deletedUsers": 150
},
"storage": {
"success": true,
"error": null,
"deletedFiles": 500
}
},
"timestamp": "2024-08-04T12:00:00.000Z"
}2. Management Scripts
Unified Management Script (Recommended)
bash
# Show help
node scripts/production-data-manager.js help
# Check environment
node scripts/production-data-manager.js check
# Backup data
node scripts/production-data-manager.js backup
# Delete data (with confirmation)
node scripts/production-data-manager.js delete --confirm
# Delete data (force execution)
node scripts/production-data-manager.js delete --confirm --force
# Full workflow (Check -> Backup -> Delete)
node scripts/production-data-manager.js full --confirmIndividual Scripts
bash
# Check environment
node scripts/check-production-environment.js
# Backup data
node scripts/backup-production-data.js
# Delete data
node scripts/delete-production-data.js --confirmSafety Features
1. Environment Check
- Automatic determination of production environment
- Detection of emulator environment
- Connection check for Firebase Functions/Hosting
2. Backup Feature
Backs up the following data before deletion:
- Firestore: Documents of all collections
- Firebase Auth: All user information
- Firebase Storage: File list (metadata)
Backups are saved in backups/production-backup-{timestamp}/.
3. Confirmation Feature
- Authentication with Admin Token
- Double confirmation with Confirmation Code
- Executable only in production environment
- Interactive confirmation prompts
Usage Instructions
Recommended Procedure (Using Unified Script)
Check Environment
bashnode scripts/production-data-manager.js checkCreate Backup
bashnode scripts/production-data-manager.js backupDelete Data
bashnode scripts/production-data-manager.js delete --confirm
One-Step Execution
bash
# Execute all steps at once (Check -> Backup -> Delete)
node scripts/production-data-manager.js full --confirmError Handling
Common Errors
401 Unauthorized
- Incorrect Admin Token
- Solution: Use the correct token
400 Invalid confirmation code
- Incorrect Confirmation Code
- Solution: Use the correct confirmation code
400 This endpoint only works in production environment
- Attempting to run in a test environment
- Solution: Run in the production environment
Checking Logs
Check Firebase Functions logs:
bash
firebase functions:log --project outliner-d57b0Testing
Verification in test environment:
bash
cd scripts
npm test -- tests/production-data-deletion.spec.js tests/environment-check.spec.jsSecurity Considerations
- Auth Token: Treat the Admin Token as confidential information
- Access Control: Executable only in production environment
- Logging: All operations are logged
- Backup: Always create a backup before deletion
Recovery Procedure
If data is accidentally deleted:
Restore from Backup
- Check the latest backup in the
backups/directory - Manually restore data from the Firebase Console
- Check the latest backup in the
Rebuild Firebase Project
- Create a new Firebase project if necessary
- Restore data using the backup data
Related Files
functions/index.js- API endpoint implementationscripts/production-data-manager.js- Unified management scriptscripts/delete-production-data.js- Data deletion scriptscripts/backup-production-data.js- Backup scriptscripts/check-production-environment.js- Environment check scriptscripts/tests/- Test files
Notes
- Use this feature only in emergencies or when terminating the project
- Deleted data cannot be restored
- Ensure you have approval from relevant parties before execution
- Do not forget to create a backup