Implements persistent flag tracking to ensure default client and project are only created on fresh installations and never recreated after user deletion during updates or restarts. - Added initial_data_seeded flag to InstallationConfig - Updated all 3 database initialization scripts to check flag - Added 3 unit tests (all passing) - Created comprehensive documentation Fixes issue where defaults were recreated after deletion during updates.
6.0 KiB
Default Data Seeding Fix - Changelog
Version 3.2.3 - Bug Fix
Issue
Problem: Default client and project ("Default Client" and "General") were being re-created after deletion during updates from version 3.2.2 to 3.2.3.
Reported By: User feedback
Root Cause: Database initialization scripts were checking if specific default entities existed by name and would recreate them if not found, regardless of whether this was a fresh installation or an existing database where the user had intentionally deleted them.
Solution
Implemented a persistent flag-based tracking system to ensure default data is only seeded on fresh database installations:
-
Added Tracking to InstallationConfig (
app/utils/installation.py):- New method:
is_initial_data_seeded()- checks if initial data has been created - New method:
mark_initial_data_seeded()- marks that initial data has been created - Flag persists in
data/installation.json
- New method:
-
Updated Database Initialization Scripts:
docker/init-database.py- Flask-based initializationdocker/init-database-enhanced.py- Enhanced SQL-based initializationdocker/init-database-sql.py- SQL script-based initialization
-
New Behavior:
- On fresh installation (no projects exist): Creates default client and project, sets flag
- On existing database (projects exist): Sets flag without creating defaults
- On already-seeded database (flag is true): Skips default data creation entirely
Changes Made
Files Modified
-
app/utils/installation.py
- Added
is_initial_data_seeded()method - Added
mark_initial_data_seeded()method - Both methods read/write to
data/installation.json
- Added
-
docker/init-database.py
- Import
InstallationConfig - Check flag before creating default project/client
- Mark flag after seeding
- Import
-
docker/init-database-enhanced.py
- Import
InstallationConfigwith proper path handling - Check project count and flag before seeding
- Mark flag after seeding
- Import
-
docker/init-database-sql.py
- Import
InstallationConfigwith proper path handling - Separate default data SQL from base SQL
- Conditional execution based on flag and project count
- Import
-
tests/test_installation_config.py
- Added
test_initial_data_seeding_tracking() - Added
test_initial_data_seeding_persistence() - Added
test_initial_data_seeding_default_value()
- Added
-
docs/DEFAULT_DATA_SEEDING.md (New)
- Complete documentation of the new behavior
- Troubleshooting guide
- Migration notes
- Reset instructions
Testing
Unit Tests Added
pytest tests/test_installation_config.py::TestInstallationConfig::test_initial_data_seeding_tracking -v
pytest tests/test_installation_config.py::TestInstallationConfig::test_initial_data_seeding_persistence -v
pytest tests/test_installation_config.py::TestInstallationConfig::test_initial_data_seeding_default_value -v
Manual Testing Scenarios
-
Fresh Installation:
- ✅ Default client and project created
- ✅ Flag set in installation.json
-
Upgrade from v3.2.2 (with defaults deleted):
- ✅ Defaults NOT recreated
- ✅ Flag set on first startup
-
Restart After Deletion:
- ✅ Deleted defaults remain deleted
- ✅ No re-creation on restart
Backward Compatibility
- Existing Installations: Flag is automatically set on first startup after upgrade
- No Manual Intervention: System detects existing projects and sets flag appropriately
- No Breaking Changes: All existing functionality preserved
Configuration File
The flag is stored in data/installation.json:
{
"telemetry_salt": "...",
"installation_id": "...",
"setup_complete": true,
"initial_data_seeded": true,
"initial_data_seeded_at": "2025-10-23 12:34:56.789"
}
Migration Path
From v3.2.2 to v3.2.3+
- User upgrades container to v3.2.3
- On first startup, initialization script runs
- Script detects existing projects (if any)
- Sets
initial_data_seeded = truein installation.json - Skips default data creation
- User's previously deleted defaults remain deleted
Fresh Installation
- New installation starts
- No projects exist in database
- Default client and project created
- Flag set to
true - User can delete defaults if desired
- Defaults will never be recreated
Documentation
- DEFAULT_DATA_SEEDING.md: Complete guide to the new behavior
- DEPLOYMENT_GUIDE.md: Updated with migration notes
- Code Comments: Added inline documentation in all modified files
Benefits
- ✅ User Control: Users can delete default entities without them being recreated
- ✅ Predictable Behavior: Once deleted, defaults stay deleted
- ✅ Update Safety: Updates don't re-inject previously deleted data
- ✅ Migration Safety: Database migrations respect user's data choices
- ✅ Backward Compatible: No manual intervention needed during upgrade
Breaking Changes
None - This is a pure bug fix with full backward compatibility.
Known Limitations
None identified.
Future Improvements
Potential enhancements for future releases:
- Admin UI to reset/recreate default data if needed
- Option to customize default data during initial setup
- Multiple default project templates
Support
For issues or questions:
- See documentation:
docs/DEFAULT_DATA_SEEDING.md - Check troubleshooting section
- Report bugs via GitHub issues
Summary
This fix ensures that default client and project data respects user preferences and is only created during initial database setup, never to be automatically recreated after deletion. The implementation uses a persistent flag in the installation configuration that tracks whether initial data has been seeded, providing predictable and user-friendly behavior across updates and restarts.
Status: ✅ Complete and Ready for Production
Version: 3.2.3+
Date: October 23, 2025