refactor: implement configurable directory structure with XDG support

Separate configuration from data storage and make paths configurable
via environment variables and command-line flags. This improves
Unix/Linux compliance and supports both development and production
deployments.

Key changes:
- Separate config dir (opal.yml) from data dir (database, logs)
- Support XDG Base Directory specification
- Add --config-dir and --data-dir flags
- Environment variables: OPAL_CONFIG_DIR, OPAL_DATA_DIR, OPAL_DB_PATH
- Smart fallback: /etc/opal, /var/lib/opal -> ~/.config/opal, ~/.local/share/opal
- Server mode validates required OAuth/JWT environment variables
- Update naming from 'jade' to 'opal' throughout
- Update systemd service name to 'opal.service'
- Add migration guide in README

Default paths:
- Config: /etc/opal (fallback: ~/.config/opal)
- Data: /var/lib/opal (fallback: ~/.local/share/opal)

Files modified:
- internal/engine/config.go: New directory resolution logic
- internal/engine/database.go: Auto-create data directory
- cmd/root.go: Add global flags for directory overrides
- cmd/server.go: Add configuration validation
- cmd/sync.go, internal/sync/*: Use new path helper functions
- tests: Update to use directory overrides
- docs: Update deployment guide and README
This commit is contained in:
2026-01-06 20:46:29 +01:00
parent 7ea78d3b54
commit 5d01c9f564
12 changed files with 333 additions and 54 deletions
+50 -1
View File
@@ -32,7 +32,56 @@ A task can be recurring. Then we have a template task and instances of that task
A recurring task is given a status of recurring which hides it from view. The recurring task you create is called the template task, from which recurring tasks instances are created. So the template remains hidden, and the recurring instances that spawn from it are the tasks that you will see and complete.
## Storage
SQLite database stored in `~/.config/jade/opal.db`
**Configuration:** `~/.config/opal/opal.yml` (or `$XDG_CONFIG_HOME/opal/opal.yml`)
**Database:** `~/.local/share/opal/opal.db` (or `$XDG_DATA_HOME/opal/opal.db`)
### Customizing Storage Locations
Override default locations using environment variables or command-line flags:
**Environment Variables:**
- `OPAL_CONFIG_DIR` - Override config directory location
- `OPAL_DATA_DIR` - Override data directory location
- `OPAL_DB_PATH` - Override database file path specifically
- `XDG_CONFIG_HOME` - Standard XDG config directory (defaults to `~/.config`)
- `XDG_DATA_HOME` - Standard XDG data directory (defaults to `~/.local/share`)
**Command-Line Flags:**
```bash
opal --config-dir /custom/config --data-dir /custom/data list
```
**Production Server Setup:**
```bash
# Use system-wide paths for production
OPAL_CONFIG_DIR=/etc/opal OPAL_DATA_DIR=/var/lib/opal opal server start
```
### Migrating from Old Paths
If you previously used `~/.config/jade/`, you can migrate your data:
```bash
# Backup first (recommended)
cp -r ~/.config/jade ~/.config/jade.backup
# Create new directories
mkdir -p ~/.config/opal ~/.local/share/opal
# Copy config
cp ~/.config/jade/opal.yml ~/.config/opal/
# Move database and sync data
mv ~/.config/jade/opal.db ~/.local/share/opal/
mv ~/.config/jade/sync_*.* ~/.local/share/opal/ 2>/dev/null || true
# Test that everything works
opal list
# Remove old directory after confirming it works
rm -rf ~/.config/jade
```
## Server & Sync