The clean command allows you to clear all data from the Neo4j database, providing a fresh start for testing or removing old data.
python palefire-cli.py cleanThis will:
- Show current database statistics (nodes and relationships)
- Prompt for confirmation
- Delete all nodes and relationships
- Show cleanup results
python palefire-cli.py clean --confirmpython palefire-cli.py clean --nodes-onlyThis deletes only nodes and relationships while preserving:
- Database indexes
- Constraints
- Schema definitions
| Option | Description |
|---|---|
--confirm |
Skip confirmation prompt and clean immediately |
--nodes-only |
Delete only nodes (keep database structure) |
$ python palefire-cli.py clean
================================================================================
🗑️ DATABASE CLEANUP
================================================================================
Current database contents:
Nodes: 1523
Relationships: 4567
⚠️ WARNING: This will permanently delete all data!
Mode: Complete cleanup (all nodes, relationships, and data)
Are you sure you want to continue? (yes/no): yes
🔄 Cleaning database...
================================================================================
✅ DATABASE CLEANED SUCCESSFULLY
================================================================================
Deleted:
Nodes: 1523
Relationships: 4567
The database is now empty and ready for new data.
================================================================================# For scripts or automation
python palefire-cli.py clean --confirm$ python palefire-cli.py clean
⚠️ WARNING: This will permanently delete all data!
Are you sure you want to continue? (yes/no): no
❌ Cleanup cancelled.# Clean database
python palefire-cli.py clean --confirm
# Ingest fresh data
python palefire-cli.py ingest --file new_data.json
# Query the new data
python palefire-cli.py query "Your question?"# Clean before each test run
python palefire-cli.py clean --confirm
python palefire-cli.py ingest --demo
# Run tests...# Remove old data
python palefire-cli.py clean --confirm
# Import new data format
python palefire-cli.py ingest --file new_format.json# Clean corrupted database
python palefire-cli.py clean --confirm
# Re-ingest from backup
python palefire-cli.py ingest --file backup.json# Clear everything and start over
python palefire-cli.py clean --confirm
python palefire-cli.py ingest --file episodes.jsonBy default, the command asks for confirmation:
Are you sure you want to continue? (yes/no):
Only "yes" or "y" will proceed with cleanup.
Shows what will be deleted:
Current database contents:
Nodes: 1523
Relationships: 4567
After cleanup, verifies the database is empty:
Deleted:
Nodes: 1523
Relationships: 4567
If the database is already empty:
✅ Database is already empty!
Deletes:
- ✅ All nodes
- ✅ All relationships
- ✅ All node properties
- ✅ All relationship properties
Preserves:
- ✅ Database structure
- ✅ Indexes
- ✅ Constraints
Same as standard cleanup (currently identical behavior).
# Export current data before cleaning
python palefire-cli.py query "..." --export backup.json
# Then clean
python palefire-cli.py clean# Good: Requires confirmation
python palefire-cli.py clean
# Risky: No confirmation
python palefire-cli.py clean --confirm# Clean database
python palefire-cli.py clean --confirm
# Verify it's empty (should return no results)
python palefire-cli.py query "test"# Add to your scripts
echo "Cleaning database at $(date)" >> cleanup.log
python palefire-cli.py clean --confirm
echo "Cleanup completed at $(date)" >> cleanup.logSymptoms:
❌ Error cleaning database: ...
Solutions:
- Check Neo4j is running
- Verify connection credentials
- Check database permissions
- Look for locked nodes
Symptoms:
⚠️ CLEANUP INCOMPLETE
Remaining nodes: 5
Solutions:
- Run cleanup again
- Check for constraint violations
- Manually delete remaining nodes:
MATCH (n) DETACH DELETE n
Symptoms:
Error: Permission denied
Solutions:
- Check Neo4j user permissions
- Ensure user has DELETE privileges
- Use admin credentials
#!/bin/bash
# cleanup_and_reingest.sh
echo "Starting cleanup process..."
# Clean database
python palefire-cli.py clean --confirm
if [ $? -eq 0 ]; then
echo "Cleanup successful, starting ingestion..."
python palefire-cli.py ingest --file data.json
else
echo "Cleanup failed, aborting."
exit 1
fiimport subprocess
import sys
def clean_if_needed():
"""Clean database if it has more than 10000 nodes."""
# Check node count
result = subprocess.run(
['python', 'palefire-cli.py', 'query', 'MATCH (n) RETURN count(n)'],
capture_output=True
)
# If too many nodes, clean
if node_count > 10000:
subprocess.run(['python', 'palefire-cli.py', 'clean', '--confirm'])#!/bin/bash
# safe_clean.sh
# Create backup
BACKUP_FILE="backup_$(date +%Y%m%d_%H%M%S).json"
python palefire-cli.py query "..." --export "$BACKUP_FILE"
# Clean database
python palefire-cli.py clean --confirm
echo "Backup saved to: $BACKUP_FILE"- name: Clean Test Database
run: |
python palefire-cli.py clean --confirm
python palefire-cli.py ingest --file test_data.jsonstage('Clean Database') {
steps {
sh 'python palefire-cli.py clean --confirm'
sh 'python palefire-cli.py ingest --file ${TEST_DATA}'
}
}# Clean database on container start
CMD ["sh", "-c", "python palefire-cli.py clean --confirm && python palefire-cli.py ingest --demo"]A: No, cleanup is permanent. Always backup first!
A: No, it only affects the configured Neo4j database.
A: Depends on database size:
- Small (< 1000 nodes): < 1 second
- Medium (1000-10000 nodes): 1-5 seconds
- Large (> 10000 nodes): 5-30 seconds
A: No, the clean command removes all nodes. For selective deletion, use Cypher queries directly.
A: They are preserved by default. Use --nodes-only to ensure this.
- CLI Guide - Complete CLI documentation
- Quick Reference - Quick command reference
- Configuration - Configuration options
Database Cleanup v1.0 - Clean Slate, Fresh Start! 🗑️