diff --git a/README.md b/README.md index 490de47a..de9c63ca 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,63 @@ Gifts make the world go 'round! * Time Safari logo assisted by [DALL-E in ChatGPT](https://chat.openai.com/g/g-2fkFE8rbu-dall-e) * [DiceBear](https://www.dicebear.com/licenses/) and [Avataaars](https://www.dicebear.com/styles/avataaars/#details) for human-looking identicons * Some gratitude prompts thanks to [Develop Good Habits](https://www.developgoodhabits.com/gratitude-journal-prompts/) + +## Development Database Clearing + +TimeSafari provides a simple script-based approach to clear the database for development purposes. + +### Quick Usage +```bash +# Run the 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 +``` + +### What It Does + +#### **Electron (Desktop App)** +- Automatically finds and clears the SQLite database files +- Works on Linux, macOS, and Windows +- Clears all data and forces fresh migrations on next startup + +#### **Web Browser** +- Provides instructions for using custom browser data directories +- Shows manual clearing via browser DevTools +- Ensures reliable database clearing without browser complications + +### Safety Features +- โœ… **Interactive Script**: Guides you through the process +- โœ… **Platform Detection**: Automatically detects your OS +- โœ… **Clear Instructions**: Step-by-step guidance for each platform +- โœ… **Safe Paths**: Only clears TimeSafari-specific data + +### Manual Commands (if needed) + +#### **Electron Database Location** +```bash +# Linux +rm -rf ~/.config/TimeSafari/* + +# macOS +rm -rf ~/Library/Application\ Support/TimeSafari/* + +# Windows +rmdir /s /q %APPDATA%\TimeSafari +``` + +#### **Web Browser (Custom Data Directory)** +```bash +# Create isolated browser 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 +``` + +See the script for complete platform-specific instructions. diff --git a/docs/database-clearing.md b/docs/database-clearing.md new file mode 100644 index 00000000..42c34797 --- /dev/null +++ b/docs/database-clearing.md @@ -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 \ No newline at end of file diff --git a/electron/README-BUILDING.md b/electron/README-BUILDING.md index a470f666..baf3bd17 100644 --- a/electron/README-BUILDING.md +++ b/electron/README-BUILDING.md @@ -1,7 +1,7 @@ # TimeSafari Electron Build Guide **Author**: Matthew Raymer -**Date**: 2025-01-10 +**Date**: 2025-07-11 **Status**: **ACTIVE** - Production Ready ## Overview @@ -267,6 +267,6 @@ electron/ --- -**Last Updated**: 2025-01-10 +**Last Updated**: 2025-07-11 **Version**: 1.0.3-beta **Status**: Production Ready \ No newline at end of file diff --git a/scripts/clear-database.sh b/scripts/clear-database.sh new file mode 100755 index 00000000..580b8651 --- /dev/null +++ b/scripts/clear-database.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +# TimeSafari Database Clearing Script +# Author: Matthew Raymer +# Date: 2025-07-11 + +set -e + +echo "=== TimeSafari Database Clearing Script ===" +echo "" + +# Detect platform +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + PLATFORM="linux" +elif [[ "$OSTYPE" == "darwin"* ]]; then + PLATFORM="macos" +elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then + PLATFORM="windows" +else + PLATFORM="unknown" +fi + +echo "Detected platform: $PLATFORM" +echo "" + +# Function to clear Electron database +clear_electron_database() { + echo "๐Ÿงน Clearing Electron Database..." + + local db_path="" + case $PLATFORM in + "linux") + db_path="$HOME/Databases/TimeSafari" + ;; + "macos") + db_path="$HOME/Library/Application Support/TimeSafari" + ;; + "windows") + db_path="$APPDATA/TimeSafari" + ;; + *) + echo "โŒ Unknown platform: $PLATFORM" + exit 1 + ;; + esac + + if [[ -d "$db_path" ]]; then + echo "Found database at: $db_path" + echo "Removing database files..." + rm -rf "$db_path"/* + echo "โœ… Electron database cleared successfully!" + else + echo "โ„น๏ธ No database found at: $db_path" + echo " (This is normal if you haven't run the app yet)" + fi +} + +# Function to show web browser instructions +show_web_instructions() { + echo "๐ŸŒ Web Browser Database Clearing Instructions:" + echo "" + echo "For reliable database clearing in web browsers, use a custom data directory:" + echo "" + + case $PLATFORM in + "linux") + echo "๐Ÿ“ Create custom data directory:" + echo " mkdir -p ~/timesafari-dev-data" + echo "" + echo "๐Ÿš€ Start browser with custom data directory:" + echo " # Chrome/Chromium:" + echo " google-chrome --user-data-dir=~/timesafari-dev-data" + echo " # Firefox:" + echo " firefox --profile ~/timesafari-dev-data" + echo "" + echo "๐Ÿงน Clear database:" + echo " rm -rf ~/timesafari-dev-data" + ;; + "macos") + echo "๐Ÿ“ Create custom data directory:" + echo " mkdir -p ~/timesafari-dev-data" + echo "" + echo "๐Ÿš€ Start browser with custom data directory:" + echo " # Chrome:" + echo " /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --user-data-dir=~/timesafari-dev-data" + echo " # Firefox:" + echo " /Applications/Firefox.app/Contents/MacOS/firefox --profile ~/timesafari-dev-data" + echo "" + echo "๐Ÿงน Clear database:" + echo " rm -rf ~/timesafari-dev-data" + ;; + "windows") + echo "๐Ÿ“ Create custom data directory:" + echo " mkdir %USERPROFILE%\\timesafari-dev-data" + echo "" + echo "๐Ÿš€ Start browser with custom data directory:" + echo " # Chrome:" + echo " \"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\" --user-data-dir=%USERPROFILE%\\timesafari-dev-data" + echo " # Firefox:" + echo " \"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" --profile %USERPROFILE%\\timesafari-dev-data" + echo "" + echo "๐Ÿงน Clear database:" + echo " rmdir /s /q %USERPROFILE%\\timesafari-dev-data" + ;; + esac +} + +# Function to show manual browser clearing +show_manual_browser_clearing() { + echo "๐Ÿ”ง Manual Browser Database Clearing:" + echo "" + echo "If you prefer to use your regular browser profile:" + echo "" + echo "1. Open browser Developer Tools (F12)" + echo "2. Go to Application/Storage tab" + echo "3. Find 'IndexedDB' section" + echo "4. Delete 'TimeSafari' database" + echo "5. Refresh the page" + echo "" + echo "โš ๏ธ Note: This only clears the current site's data." + echo " For complete clearing, use the custom data directory method above." +} + +# Main script logic +echo "Choose your platform:" +echo "1. Electron (Desktop App)" +echo "2. Web Browser - Custom Data Directory" +echo "3. Web Browser - Manual Clearing" +echo "4. Show all options" +echo "" + +read -p "Enter your choice (1-4): " choice + +case $choice in + 1) + clear_electron_database + ;; + 2) + show_web_instructions + ;; + 3) + show_manual_browser_clearing + ;; + 4) + echo "=== All Database Clearing Options ===" + echo "" + clear_electron_database + echo "" + show_web_instructions + echo "" + show_manual_browser_clearing + ;; + *) + echo "โŒ Invalid choice. Please run the script again." + exit 1 + ;; +esac + +echo "" +echo "โœ… Database clearing instructions completed!" +echo "" +echo "๐Ÿ’ก Tip: After clearing the database, restart your development server:" +echo " npm run build:electron:dev # For Electron" +echo " npm run build:web:dev # For Web" \ No newline at end of file