Skip to content

Commit e6414bd

Browse files
authored
Enhanced Historical Functionality for All Storage Types and Complex Multi-Branch Testing (#81)
1 parent 3002324 commit e6414bd

7 files changed

Lines changed: 2419 additions & 134 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,11 @@ The following features are for Prolly tree library for Version 0.2.1:
226226
- [X] add usage examples for git-prolly use cases
227227
- [X] add usage examples for AI agent memory use cases
228228
- [X] support rocksdb as storage backend
229+
- [X] add agent memory system api support
230+
231+
The following features are for Prolly tree library for future versions:
229232
- [ ] support IPDL as storage backend
230-
- [X] generic storage backend support for VersionedKvStore
233+
231234

232235
## Contributing
233236

doc/git.md renamed to docs/git.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,118 @@ git-prolly show HEAD --keys-only
320320
# user:456
321321
```
322322

323+
#### `git-prolly history <key>`
324+
Show commit history for a specific key, tracking all changes made to that key over time.
325+
326+
**Usage:**
327+
```bash
328+
git-prolly history <key> [--format=<format>] [--limit=<number>]
329+
```
330+
331+
**Options:**
332+
- `--format=compact`: Show concise one-line format (default)
333+
- `--format=detailed`: Show detailed commit information
334+
- `--format=json`: Output in JSON format
335+
- `--limit=<number>`: Maximum number of commits to show
336+
337+
**Examples:**
338+
```bash
339+
# Basic history
340+
git-prolly history user:123
341+
# Output: History for key 'user:123':
342+
# 2024-01-15 10:30:00 f1e2d3c4 Update user profile
343+
# 2024-01-15 09:15:00 a1b2c3d4 Add new user
344+
345+
# Detailed history
346+
git-prolly history user:123 --format=detailed
347+
# Output: Detailed History for key 'user:123':
348+
# ═══════════════════════════════════════
349+
# Commit: f1e2d3c4b5a6789012345678901234567890abcd
350+
# Date: 2024-01-15 10:30:00 UTC
351+
# Author: Developer
352+
# Message: Update user profile
353+
#
354+
# Commit: a1b2c3d4e5f6789012345678901234567890abcd
355+
# Date: 2024-01-15 09:15:00 UTC
356+
# Author: Developer
357+
# Message: Add new user
358+
359+
# Limited results
360+
git-prolly history user:123 --limit=5
361+
# Output: History for key 'user:123' (showing 5 most recent):
362+
# 2024-01-15 10:30:00 f1e2d3c4 Update user profile
363+
# 2024-01-15 09:15:00 a1b2c3d4 Add new user
364+
365+
# JSON output
366+
git-prolly history user:123 --format=json
367+
# Output: {
368+
# "key": "user:123",
369+
# "history": [
370+
# {
371+
# "commit": "f1e2d3c4b5a6789012345678901234567890abcd",
372+
# "timestamp": 1705315800,
373+
# "author": "Developer",
374+
# "message": "Update user profile"
375+
# }
376+
# ]
377+
# }
378+
```
379+
380+
#### `git-prolly keys-at <reference>`
381+
Show all keys that existed at a specific commit or branch reference.
382+
383+
**Usage:**
384+
```bash
385+
git-prolly keys-at <reference> [--values] [--format=<format>]
386+
```
387+
388+
**Options:**
389+
- `--values`: Show values as well as keys
390+
- `--format=list`: Show as a simple list (default)
391+
- `--format=json`: Output in JSON format
392+
393+
**Examples:**
394+
```bash
395+
# List keys at HEAD
396+
git-prolly keys-at HEAD
397+
# Output: Keys at HEAD:
398+
# config:theme
399+
# user:123
400+
# user:456
401+
402+
# List keys with values
403+
git-prolly keys-at HEAD --values
404+
# Output: Keys at HEAD:
405+
# config:theme = "dark"
406+
# user:123 = "John Doe"
407+
# user:456 = "Jane Smith"
408+
409+
# Keys at specific commit
410+
git-prolly keys-at a1b2c3d4
411+
# Output: Keys at a1b2c3d4:
412+
# config:theme
413+
# user:123
414+
415+
# Keys at branch
416+
git-prolly keys-at feature/new-users
417+
# Output: Keys at feature/new-users:
418+
# config:theme
419+
# user:123
420+
# user:456
421+
# user:789
422+
423+
# JSON output with values
424+
git-prolly keys-at HEAD --values --format=json
425+
# Output: {
426+
# "reference": "HEAD",
427+
# "keys": [
428+
# {"key": "config:theme", "value": "dark"},
429+
# {"key": "user:123", "value": "John Doe"},
430+
# {"key": "user:456", "value": "Jane Smith"}
431+
# ]
432+
# }
433+
```
434+
323435
### Advanced Operations
324436

325437
#### `git-prolly revert <commit>`

doc/sql.md renamed to docs/sql.md

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Options:
6060
-o, --format <FORMAT> Output format (table, json, csv)
6161
-i, --interactive Start interactive SQL shell
6262
--verbose Show detailed error messages
63+
-b, --branch <BRANCH> Execute against specific branch or commit (SELECT queries only, requires clean status)
6364
-h, --help Print help
6465
```
6566

@@ -109,6 +110,38 @@ In interactive mode:
109110
- Type `help` for available commands
110111
- Type `exit` or `quit` to leave the shell
111112

113+
### 4. Historical Data Querying
114+
115+
Query data from specific branches or commits using the `-b` parameter:
116+
117+
```bash
118+
# Query data from main branch
119+
git prolly sql -b main "SELECT * FROM users"
120+
121+
# Query data from a specific commit
122+
git prolly sql -b a1b2c3d4 "SELECT COUNT(*) FROM products"
123+
124+
# Query data from a feature branch
125+
git prolly sql -b feature/new-schema "SELECT * FROM categories"
126+
```
127+
128+
**Important Requirements:**
129+
- Only `SELECT` statements are allowed when using `-b` parameter
130+
- Your working directory must have clean status (no uncommitted staging changes)
131+
- The branch/commit will be temporarily checked out and restored after execution
132+
133+
**Example with staging changes:**
134+
```bash
135+
# This will be blocked if you have uncommitted changes
136+
git prolly set user:123 "John Doe" # Creates staging changes
137+
git prolly sql -b main "SELECT * FROM users"
138+
# Error: Cannot use -b/--branch parameter with uncommitted staging changes
139+
140+
# Commit your changes first
141+
git prolly commit -m "Add new user"
142+
git prolly sql -b main "SELECT * FROM users" # Now works
143+
```
144+
112145
## SQL Operations
113146

114147
### Supported SQL Features
@@ -329,9 +362,66 @@ prolly-sql> exit
329362
Goodbye!
330363
```
331364

365+
### Interactive Mode with Historical Data
366+
367+
Use interactive mode to explore historical data:
368+
369+
```bash
370+
# Start interactive mode against a specific branch
371+
git prolly sql -b feature/analytics -i
372+
```
373+
374+
```
375+
🌟 ProllyTree SQL Interactive Shell
376+
====================================
377+
Executing against branch/commit: feature/analytics
378+
⚠️ Only SELECT statements are allowed in this mode
379+
Type 'exit' or 'quit' to exit
380+
Type 'help' for available commands
381+
382+
prolly-sql> SELECT COUNT(*) FROM new_analytics_table;
383+
│ COUNT(*) │
384+
├──────────┤
385+
│ I64(150) │
386+
387+
prolly-sql> SELECT * FROM products WHERE price > 1000;
388+
│ id │ name │ price │
389+
├────────┼─────────────────────┼───────────┤
390+
│ I64(1) │ Str("Gaming PC") │ I64(1500) │
391+
│ I64(2) │ Str("MacBook Pro") │ I64(2000) │
392+
393+
prolly-sql> INSERT INTO products VALUES (3, 'iPad', 800);
394+
Error: Only SELECT statements are allowed when using -b/--branch parameter
395+
Historical commits/branches are read-only for data integrity
396+
397+
prolly-sql> exit
398+
Goodbye!
399+
Restored to original branch: main
400+
```
401+
332402
## Advanced Examples
333403

334-
### 1. Complex Data Analysis
404+
### 1. Historical Data Analysis
405+
406+
Compare data across different points in time:
407+
408+
```bash
409+
# Query current data
410+
git prolly sql "SELECT COUNT(*) as current_users FROM users"
411+
412+
# Query data from last week's commit
413+
git prolly sql -b 7d1a2b3c "SELECT COUNT(*) as users_last_week FROM users"
414+
415+
# Compare product prices between branches
416+
git prolly sql -b main "SELECT name, price FROM products WHERE category = 'Electronics'"
417+
git prolly sql -b feature/price-update "SELECT name, price FROM products WHERE category = 'Electronics'"
418+
419+
# Analyze data growth over time
420+
git prolly sql -b v1.0 "SELECT COUNT(*) as v1_orders FROM orders"
421+
git prolly sql -b v2.0 "SELECT COUNT(*) as v2_orders FROM orders"
422+
```
423+
424+
### 2. Complex Data Analysis
335425

336426
```sql
337427
-- Create sales data
@@ -461,10 +551,34 @@ git checkout main
461551
# The new tables don't exist on main branch
462552
git prolly sql "SELECT * FROM categories" # Error: table not found
463553

554+
# Query the new schema without switching branches
555+
git prolly sql -b feature/new-schema "SELECT * FROM categories"
556+
464557
# Merge when ready
465558
git merge feature/new-schema
466559
```
467560

561+
### Cross-Branch Data Comparison
562+
563+
Compare data between branches without switching contexts:
564+
565+
```bash
566+
# Compare user counts between branches
567+
echo "Main branch users:"
568+
git prolly sql -b main "SELECT COUNT(*) FROM users"
569+
570+
echo "Feature branch users:"
571+
git prolly sql -b feature/user-management "SELECT COUNT(*) FROM users"
572+
573+
# Generate reports from different branches
574+
git prolly sql -b production -o json "SELECT * FROM daily_metrics WHERE date = '2024-01-15'" > prod_metrics.json
575+
git prolly sql -b staging -o json "SELECT * FROM daily_metrics WHERE date = '2024-01-15'" > staging_metrics.json
576+
577+
# Compare table schemas between versions
578+
git prolly sql -b v1.0 "SELECT name FROM sqlite_master WHERE type='table'"
579+
git prolly sql -b v2.0 "SELECT name FROM sqlite_master WHERE type='table'"
580+
```
581+
468582
## Best Practices
469583

470584
### 1. Schema Design
@@ -497,6 +611,23 @@ git checkout -b migration-test
497611
# If successful, merge to main
498612
```
499613

614+
### 5. Historical Data Querying
615+
616+
- **Commit changes before using `-b`**: Always commit your staging changes before querying historical data
617+
- **Use for read-only analysis**: The `-b` parameter is perfect for generating reports without affecting current work
618+
- **Branch-specific schemas**: Use `-b` to query data from branches with different table structures
619+
- **Performance**: Historical queries access committed data, so they may be slower than current branch queries
620+
621+
```bash
622+
# Good practice: commit first
623+
git prolly commit -m "Save current work"
624+
git prolly sql -b production "SELECT * FROM metrics"
625+
626+
# Avoid: Don't leave uncommitted changes
627+
git prolly set user:new "data" # Uncommitted change
628+
git prolly sql -b main "SELECT * FROM users" # Will be blocked
629+
```
630+
500631
## Troubleshooting
501632

502633
### Common Issues
@@ -515,6 +646,21 @@ git checkout -b migration-test
515646
- Check SQL syntax - the parser is strict about formatting
516647
- Ensure column names match exactly (case-sensitive)
517648

649+
4. **"Cannot use -b/--branch parameter with uncommitted staging changes"**
650+
- Check staging status with `git prolly status`
651+
- Commit your changes first: `git prolly commit -m "Save changes"`
652+
- Or discard changes if not needed
653+
654+
5. **"Only SELECT statements are allowed when using -b/--branch parameter"**
655+
- Historical data is read-only for safety
656+
- Use regular `git prolly sql` (without `-b`) for data modifications
657+
- Switch to the target branch if you need to make changes there
658+
659+
6. **"Failed to checkout branch/commit"**
660+
- Verify the branch/commit exists: `git branch -a` or `git log --oneline`
661+
- Check branch name spelling (case-sensitive)
662+
- Ensure you have access to the specified commit
663+
518664
### Performance Tips
519665

520666
1. **Large Result Sets**: Use LIMIT to restrict output
File renamed without changes.

0 commit comments

Comments
 (0)