Skip to content

Commit dbd543e

Browse files
authored
Merge pull request #73 from iamvirul/feature/git-like-versioning
feat(version): Git-like versioning with branch, checkout, and tree (v1.5.0)
2 parents fcd1fa6 + 00224f3 commit dbd543e

27 files changed

Lines changed: 3041 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,6 @@ jobs:
183183
install-mode: goinstall
184184
args: --timeout=5m --out-format=colored-line-number
185185

186-
security:
187-
name: Security Scan
188-
runs-on: ubuntu-latest
189-
190-
steps:
191-
- name: Checkout code
192-
uses: actions/checkout@v4
193-
194-
- name: Set up Go
195-
uses: actions/setup-go@v5
196-
with:
197-
go-version: '1.25.8'
198-
cache-dependency-path: go.sum
199-
200-
- name: Run gosec
201-
uses: securego/gosec@master
202-
with:
203-
args: '-exclude=G304 -exclude-generated -severity medium ./...'
204-
205-
- name: Run govulncheck
206-
run: |
207-
go install golang.org/x/vuln/cmd/govulncheck@latest
208-
govulncheck ./...
209-
210186
build:
211187
name: Build
212188
runs-on: ubuntu-latest

.github/workflows/security.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Security Scan
2+
3+
on:
4+
push:
5+
branches: [ main, development ]
6+
pull_request:
7+
branches: [ main, development ]
8+
9+
jobs:
10+
security:
11+
name: Security Scan
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version: '1.25.8'
22+
cache-dependency-path: go.sum
23+
24+
- name: Run gosec
25+
uses: securego/gosec@master
26+
with:
27+
args: '-exclude=G304 -exclude-generated -severity medium ./...'
28+
29+
- name: Run govulncheck
30+
run: |
31+
go install golang.org/x/vuln/cmd/govulncheck@latest
32+
govulncheck ./...

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
bin/
2-
deepdiffdb
2+
/deepdiffdb
33
diff-output/
44
coverage.out
55
coverage-integration.out
66
coverage.txt
77
*.out
8+
9+
.deepdiffdb/

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- **Git-like branch support for `version`**`version branch`, `version checkout`, `version tree`
12+
- `version branch` — lists all branches with current marker and tip hash; creates a new branch when a name is given; `--from <hash>` to branch from a specific commit
13+
- `version checkout <branch>` — switches HEAD to a symbolic ref pointing to the named branch; new commits advance only the checked-out branch tip
14+
- `version tree` — ASCII commit graph showing all branches with lane columns, `HEAD -> branch` decoration, short hash, date, and message (newest-first)
15+
- HEAD is now stored as a Git-style symbolic ref (`ref: refs/heads/main`) rather than a bare hash; branch tips live in `.deepdiffdb/refs/heads/<name>`
16+
- New `internal/version` files: `branch.go`, `tree.go`
17+
- 39 new unit tests covering store symbolic refs, branch lifecycle, and tree rendering (`tests/version/`)
18+
19+
## [1.5.0] - 2026-03-31
20+
21+
### Added
22+
- **Git-like versioning for DB diffs** (issue #16)
23+
- New `version` command group: `init`, `commit`, `log`, `diff`, `rollback`
24+
- `version init` — creates a `.deepdiffdb/` repository (objects store + HEAD pointer) in the current directory
25+
- `version commit` — runs a full schema+data diff and stores the result as a SHA-256 content-addressable commit; records both schema snapshots so rollback SQL can be generated offline
26+
- `version log` — walks the commit chain from HEAD, showing author, date, and drift markers (`[schema drift]`, `[data changes]`)
27+
- `version diff <hash1> <hash2>` — compares dev schema snapshots of two commits; reports added/removed tables and column/index changes
28+
- `version rollback <hash>` — generates driver-aware rollback SQL by inverting the stored diff; inherits safety defaults from `schema-migrate` (destructive ops commented out); supports `--out <file>` and `--driver` overrides
29+
- Commit objects stored as JSON in `.deepdiffdb/objects/<sha256>.json`
30+
- New `internal/version` package (`model.go`, `store.go`, `rollback.go`)
31+
- **Sample 17: Git-like Versioning** (`samples/17-git-like-versioning/`)
32+
- Two MySQL 8 containers (prod 3320, dev 3321) with a `shop` e-commerce schema
33+
- Three migration scripts simulating a real sprint cycle (V1 baseline → V2 FK+email → V3 reviews table)
34+
- Automated `scripts/demo.sh` end-to-end walkthrough writing rollback SQL to `diff-output/`
35+
1036
## [1.0.0] - 2026-03-22
1137

1238
### Added

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# DeepDiff DB
22

33
[![CI](https://github.com/iamvirul/deepdiff-db/actions/workflows/ci.yml/badge.svg)](https://github.com/iamvirul/deepdiff-db/actions/workflows/ci.yml)
4+
[![Security Scan](https://github.com/iamvirul/deepdiff-db/actions/workflows/security.yml/badge.svg)](https://github.com/iamvirul/deepdiff-db/actions/workflows/security.yml)
45
[![Release](https://img.shields.io/github/v/release/iamvirul/deepdiff-db?color=6366f1)](https://github.com/iamvirul/deepdiff-db/releases/latest)
56
[![codecov](https://codecov.io/gh/iamvirul/deepdiff-db/branch/main/graph/badge.svg?token=Y9IORTUBAH)](https://codecov.io/gh/iamvirul/deepdiff-db)
67
[![Go Report Card](https://goreportcard.com/badge/github.com/iamvirul/deepdiff-db)](https://goreportcard.com/report/github.com/iamvirul/deepdiff-db)
@@ -46,6 +47,7 @@ DeepDiff DB makes the entire process deterministic, reviewable, and safe by:
4647
- **Enhanced error handling** - Rich error messages with actionable suggestions
4748
- **Streaming large datasets** - Keyset-paginated batch hashing keeps memory bounded at any table size
4849
- **Parallel table hashing** - Hash multiple tables concurrently with configurable worker pool
50+
- **Git-like versioning** - Commit diff snapshots, browse history, compare versions, generate rollback SQL
4951

5052
### Safety Features
5153

@@ -479,6 +481,61 @@ Continues from a previous session by loading existing resolutions.
479481
**Output Files:**
480482
- `resolutions.json` - Saved resolution decisions
481483

484+
### version
485+
486+
Git-like versioning for database diffs. Stores schema and data diff snapshots as commits, enabling history browsing, inter-version comparison, and rollback SQL generation — all without a live database connection.
487+
488+
```bash
489+
deepdiffdb version <subcommand> [flags]
490+
```
491+
492+
#### Subcommands
493+
494+
| Subcommand | Description |
495+
|---|---|
496+
| `version init` | Initialise a `.deepdiffdb/` repository in the current directory |
497+
| `version commit` | Run a full diff and store the result as a new commit |
498+
| `version log` | Show the commit history from most recent to oldest |
499+
| `version diff <h1> <h2>` | Compare schema evolution between two commits |
500+
| `version rollback <hash>` | Generate rollback SQL to undo the changes in a commit |
501+
| `version branch [<name>]` | List branches, or create a new one |
502+
| `version checkout <branch>` | Switch to a branch |
503+
| `version tree` | Show ASCII commit graph for all branches |
504+
505+
#### Example Workflow
506+
507+
```bash
508+
# Initialise once per project
509+
deepdiffdb version init
510+
511+
# Commit a baseline snapshot
512+
deepdiffdb version commit --config deepdiffdb.config.yaml --message "V1: baseline" --author "Alice"
513+
514+
# Create a feature branch and switch to it
515+
deepdiffdb version branch feature
516+
deepdiffdb version checkout feature
517+
518+
# After applying schema changes to dev, commit on the feature branch
519+
deepdiffdb version commit --config deepdiffdb.config.yaml --message "V2: add reviews table" --author "Bob"
520+
521+
# Switch back to main and commit a hotfix
522+
deepdiffdb version checkout main
523+
deepdiffdb version commit --config deepdiffdb.config.yaml --message "V2: hotfix index" --author "Alice"
524+
525+
# Browse history with an ASCII branch graph
526+
deepdiffdb version tree
527+
528+
# See what changed between two commits
529+
deepdiffdb version diff <hash_v1> <hash_v2>
530+
531+
# Generate rollback SQL for a commit
532+
deepdiffdb version rollback --out rollback.sql <hash_v2>
533+
```
534+
535+
**Storage:** Commits are stored as zlib-compressed objects in `.deepdiffdb/objects/<2-char>/<62-char>` (Git-style fanout, content-addressable by SHA-256). Branch tips live in `.deepdiffdb/refs/heads/<name>`; HEAD is a symbolic ref (`ref: refs/heads/main`). Add `.deepdiffdb/` to your `.gitignore` or commit it to share history with your team.
536+
537+
**Rollback SQL:** Each commit stores full schema snapshots, so rollback SQL can be generated at any time without a live database. Destructive operations (DROP TABLE, DROP COLUMN) are commented out by default — identical safety behaviour to `schema-migrate`.
538+
482539
## Usage Examples
483540

484541
### Basic Workflow

ROADMAP.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ We release a new version every **Saturday**. Each release includes one or more f
88

99
---
1010

11-
## Current Status: v1.0 — Production Ready 🎉
11+
## Current Status: v1.5.0 — Git-like Versioning 🎉
1212

13-
**Last Release:** 2026-03-22
13+
**Last Release:** 2026-03-31
1414

1515
**Current Features:**
1616
- Schema drift detection and standalone schema migration (`schema-migrate`)
@@ -31,12 +31,24 @@ We release a new version every **Saturday**. Each release includes one or more f
3131
- Parallel table hashing — `--parallel N` / `performance.max_parallel_tables`
3232
- Bounded O(batch_size) memory during hashing regardless of table size
3333
- Per-batch memory telemetry at DEBUG log level (`alloc_mb`, `batch`)
34-
- **NEW:** Oracle Database support — pure Go driver, no Instant Client required
34+
- Oracle Database support — pure Go driver, no Instant Client required
35+
- **NEW:** Git-like versioning — `version init/commit/log/diff/rollback` with SHA-256 content-addressable commit objects and offline rollback SQL generation
3536

3637
---
3738

3839
## Completed Releases
3940

41+
### v1.5.0: Git-like Versioning for DB Diffs (Released 2026-03-31)
42+
43+
**Features Delivered:**
44+
- `version init` — initialises `.deepdiffdb/` repository (objects store + HEAD file) in the working directory
45+
- `version commit` — runs a full schema+data diff and stores a SHA-256 content-addressable commit object capturing both schema snapshots, drift result, and data diff
46+
- `version log` — walks the commit chain from HEAD with author, timestamp, and drift markers
47+
- `version diff <h1> <h2>` — compares dev schema snapshots of two commits and reports schema evolution (added/removed tables, column/index changes)
48+
- `version rollback <hash>` — generates driver-aware rollback SQL offline by inverting the stored diff; same safety defaults as `schema-migrate` (destructive ops commented out by default); `--out` and `--driver` flags
49+
- New `internal/version` package: `model.go`, `store.go`, `rollback.go`
50+
- Sample 17: Git-like Versioning — two MySQL 8 containers, three-sprint demo, automated `demo.sh`
51+
4052
### v0.6: Enhanced Error Handling & Logging (Released 2026-01-06)
4153

4254
**Features Delivered:**
@@ -169,10 +181,13 @@ We release a new version every **Saturday**. Each release includes one or more f
169181

170182
### Phase 2 Features
171183

172-
1. **Git-like Versioning for DB Diffs**
173-
- Store diff history
174-
- Diff between any two versions
175-
- Rollback capabilities
184+
1. ~~**Git-like Versioning for DB Diffs**~~**Released in v1.5.0 (2026-03-31)**
185+
- ~~Store diff history~~`version commit` — SHA-256 content-addressable commit objects in `.deepdiffdb/objects/`
186+
- ~~Diff between any two versions~~`version diff <h1> <h2>` — schema evolution comparison
187+
- ~~Rollback capabilities~~`version rollback <hash>` — driver-aware rollback SQL generation
188+
- `version init` — repository initialisation
189+
- `version log` — full commit history with drift markers
190+
- See [Sample 17](https://github.com/iamvirul/deepdiff-db/tree/main/samples/17-git-like-versioning) for end-to-end demo
176191

177192
2. **CI/CD Integration**
178193
- GitHub Actions plugin

0 commit comments

Comments
 (0)