forked from trent_larson/crowd-funder-for-time-pwa
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:
60
README.md
60
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.
|
||||
|
||||
146
docs/database-clearing.md
Normal file
146
docs/database-clearing.md
Normal 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
|
||||
@@ -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
|
||||
164
scripts/clear-database.sh
Executable file
164
scripts/clear-database.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user