feat: implement script-based database clearing for development

- Add interactive clear-database.sh script with platform detection
- Support Electron SQLite database clearing (Linux/macOS/Windows)
- Provide web browser clearing instructions (custom profiles + DevTools)
- Remove complex programmatic database clearing from platform services
- Update documentation with comprehensive clearing guide
- Add safety features: interactive guidance, platform-specific paths
- Simplify approach: avoid browser storage complications and race conditions

Enables reliable database clearing for development without complex code.
This commit is contained in:
Matthew Raymer
2025-07-11 08:04:28 +00:00
parent 09a791622c
commit abd8f7a5dd
4 changed files with 372 additions and 2 deletions

146
docs/database-clearing.md Normal file
View File

@@ -0,0 +1,146 @@
# Database Clearing for Development
**Author**: Matthew Raymer
**Date**: 2025-07-11
**Status**: **ACTIVE** - Production Ready
## Overview
TimeSafari provides a simple script-based approach to clear the database for development purposes. This avoids the complexity of programmatic database clearing and provides reliable, platform-specific solutions.
## Quick Start
```bash
# Run the interactive database clearing script
./scripts/clear-database.sh
# Then restart your development server
npm run build:electron:dev # For Electron
npm run build:web:dev # For Web
```
## Platform-Specific Approaches
### Electron (Desktop App)
The script automatically detects your platform and clears the SQLite database files:
- **Linux**: `~/.config/TimeSafari/`
- **macOS**: `~/Library/Application Support/TimeSafari/`
- **Windows**: `%APPDATA%\TimeSafari`
### Web Browser
For web browsers, the script provides two approaches:
#### 1. Custom Data Directory (Recommended)
Create an isolated browser profile for development:
```bash
# Create isolated profile
mkdir ~/timesafari-dev-data
# Start browser with custom profile
google-chrome --user-data-dir=~/timesafari-dev-data
# Clear when needed
rm -rf ~/timesafari-dev-data
```
#### 2. Manual Browser Clearing
Use browser DevTools to clear IndexedDB:
1. Open Developer Tools (F12)
2. Go to Application/Storage tab
3. Find 'IndexedDB' section
4. Delete 'TimeSafari' database
5. Refresh the page
## Why Script-Based Approach?
### **Simplicity**
- No complex programmatic database clearing
- No browser storage complications
- No race conditions or permission issues
### **Reliability**
- Direct file system access for Electron
- Isolated browser profiles for web
- Clear, predictable behavior
### **Safety**
- Interactive script guides users
- Platform-specific instructions
- Only clears TimeSafari data
## Manual Commands
If you prefer manual commands:
### Electron
```bash
# Linux
rm -rf ~/.config/TimeSafari/*
# macOS
rm -rf ~/Library/Application\ Support/TimeSafari/*
# Windows
rmdir /s /q %APPDATA%\TimeSafari
```
### Web Browser
```bash
# Create and use isolated profile
mkdir ~/timesafari-dev-data
google-chrome --user-data-dir=~/timesafari-dev-data
# Clear when needed
rm -rf ~/timesafari-dev-data
```
## Best Practices
1. **Stop the development server** before clearing
2. **Use isolated browser profiles** for web development
3. **Restart the development server** after clearing
4. **Backup important data** before clearing
5. **Use the script** for consistent behavior
## Troubleshooting
### Script Not Found
```bash
# Make sure script is executable
chmod +x scripts/clear-database.sh
# Run from project root
./scripts/clear-database.sh
```
### Permission Errors
```bash
# Check file permissions
ls -la ~/.config/TimeSafari/
# Use sudo if needed (rare)
sudo rm -rf ~/.config/TimeSafari/*
```
### Browser Profile Issues
```bash
# Ensure browser is completely closed
pkill -f chrome
pkill -f firefox
# Then clear profile
rm -rf ~/timesafari-dev-data
```
---
**Last Updated**: 2025-07-11
**Version**: 1.0.3-beta
**Status**: Production Ready