Skip to content

Commit 11483e4

Browse files
Merge pull request #39 from DylanDevelops/ravel/better-development-environment
refactor: Optional development environment separate from production database for testing purposes
2 parents a9c8924 + cb347d2 commit 11483e4

2 files changed

Lines changed: 63 additions & 7 deletions

File tree

CONTRIBUTING.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,48 @@ go build -o tmpo .
3737
./tmpo --help
3838
```
3939

40+
### Development Mode
41+
42+
To prevent corrupting your real tmpo data during development, use the `TMPO_DEV` environment variable:
43+
44+
```bash
45+
# Enable development mode (uses ~/.tmpo-dev/ instead of ~/.tmpo/)
46+
export TMPO_DEV=1
47+
48+
# Now all commands use the development database
49+
./tmpo start "Testing new feature"
50+
./tmpo status
51+
./tmpo stop
52+
```
53+
54+
**Database Locations:**
55+
56+
- **Production mode** (default): `~/.tmpo/tmpo.db`
57+
- **Development mode** (`TMPO_DEV=1`): `~/.tmpo-dev/tmpo.db`
58+
59+
> [!NOTE]
60+
> The `export TMPO_DEV=1` command only applies to your **current terminal session**. When you close the terminal, it resets to production mode. This is intentional for safety - you must explicitly enable dev mode each time.
61+
62+
**Making it persistent (optional):**
63+
64+
If you prefer to always use dev mode, add it to your shell profile:
65+
66+
```bash
67+
# For zsh (macOS default)
68+
echo 'export TMPO_DEV=1' >> ~/.zshrc
69+
70+
# For bash
71+
echo 'export TMPO_DEV=1' >> ~/.bashrc
72+
```
73+
74+
Then restart your terminal or run `source ~/.zshrc` (or `source ~/.bashrc`).
75+
76+
**Benefits of development mode:**
77+
78+
- Your real time tracking data stays safe
79+
- You can test database changes without risk
80+
- You can easily clean up test data (`rm -rf ~/.tmpo-dev/`)
81+
4082
### Building with Version Information
4183

4284
To build with version information injected (useful for testing version display):
@@ -120,16 +162,22 @@ tmpo/
120162
All user data is stored locally in:
121163

122164
```
123-
~/.tmpo/
124-
└── tmpo.db # SQLite database
165+
~/.tmpo/ # Production (default)
166+
└── tmpo.db
167+
168+
~/.tmpo-dev/ # Development (when TMPO_DEV=1)
169+
└── tmpo.db
125170
```
126171

127172
The database schema includes:
128173

129-
- Time entries (start/end times, project, description)
174+
- Time entries (start/end times, project, description, hourly rate)
130175
- Project metadata (derived from entries)
131176
- Automatic indexing for fast queries
132177

178+
> [!NOTE]
179+
> See [Development Mode](#development-mode) for information on using the development database during local development.
180+
133181
### How Project Detection Works
134182

135183
When a user runs `tmpo start`, the project name is detected in this priority order:

internal/storage/db.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ type Database struct {
2424

2525
// Initialize ensures the on-disk storage for the application exists, opens the
2626
// SQLite database, and returns a Database wrapper.
27-
//
27+
//
2828
// Specifically, Initialize:
2929
// - determines the current user's home directory,
30-
// - creates the directory "$HOME/.tmpo" if it does not already exist,
31-
// - opens (or creates) the SQLite database file "$HOME/.tmpo/tmpo.db",
30+
// - checks the TMPO_DEV environment variable:
31+
// - if TMPO_DEV is "1" or "true", uses "$HOME/.tmpo-dev" (development mode),
32+
// - otherwise uses "$HOME/.tmpo" (production mode, the default),
33+
// - creates the appropriate directory if it does not already exist,
34+
// - opens (or creates) the SQLite database file "tmpo.db" in that directory,
3235
// - ensures the time_entries table exists with the schema:
3336
// id INTEGER PRIMARY KEY AUTOINCREMENT,
3437
// project_name TEXT NOT NULL,
@@ -42,12 +45,17 @@ type Database struct {
4245
// responsible for closing the database when finished.
4346
func Initialize() (*Database, error) {
4447
homeDir, err := os.UserHomeDir()
45-
48+
4649
if err != nil {
4750
return nil, fmt.Errorf("failed to get home directory: %w", err)
4851
}
4952

53+
// Switch out directory depending on build environment
5054
tmpoDir := filepath.Join(homeDir, ".tmpo")
55+
if devMode := os.Getenv("TMPO_DEV"); devMode == "1" || devMode == "true" {
56+
tmpoDir = filepath.Join(homeDir, ".tmpo-dev")
57+
}
58+
5159
if err := os.MkdirAll(tmpoDir, 0755); err != nil {
5260
return nil, fmt.Errorf("failed to create .tmpo directory: %w", err)
5361
}

0 commit comments

Comments
 (0)