db-git 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- db_git-0.1.0/.claude/settings.local.json +26 -0
- db_git-0.1.0/.github/dependabot.yml +10 -0
- db_git-0.1.0/.github/workflows/test.yml +81 -0
- db_git-0.1.0/.gitignore +10 -0
- db_git-0.1.0/.pre-commit-config.yaml +30 -0
- db_git-0.1.0/CHANGELOG.md +25 -0
- db_git-0.1.0/LICENSE +21 -0
- db_git-0.1.0/PKG-INFO +363 -0
- db_git-0.1.0/README.md +332 -0
- db_git-0.1.0/noxfile.py +67 -0
- db_git-0.1.0/pyproject.toml +83 -0
- db_git-0.1.0/src/git_db/__init__.py +1 -0
- db_git-0.1.0/src/git_db/backends/__init__.py +173 -0
- db_git-0.1.0/src/git_db/backends/postgresql/__init__.py +0 -0
- db_git-0.1.0/src/git_db/backends/postgresql/backend.py +176 -0
- db_git-0.1.0/src/git_db/backends/postgresql/branch_db.py +203 -0
- db_git-0.1.0/src/git_db/backends/postgresql/connections.py +82 -0
- db_git-0.1.0/src/git_db/backends/postgresql/pgdump.py +212 -0
- db_git-0.1.0/src/git_db/backends/postgresql/template.py +160 -0
- db_git-0.1.0/src/git_db/cli/__init__.py +8 -0
- db_git-0.1.0/src/git_db/cli/_common.py +41 -0
- db_git-0.1.0/src/git_db/cli/_console.py +18 -0
- db_git-0.1.0/src/git_db/cli/_format.py +56 -0
- db_git-0.1.0/src/git_db/cli/_prompts.py +121 -0
- db_git-0.1.0/src/git_db/cli/branch.py +168 -0
- db_git-0.1.0/src/git_db/cli/hook.py +102 -0
- db_git-0.1.0/src/git_db/cli/init.py +267 -0
- db_git-0.1.0/src/git_db/cli/inspect.py +414 -0
- db_git-0.1.0/src/git_db/cli/snapshot.py +115 -0
- db_git-0.1.0/src/git_db/config.py +243 -0
- db_git-0.1.0/src/git_db/db.py +17 -0
- db_git-0.1.0/src/git_db/errors.py +46 -0
- db_git-0.1.0/src/git_db/git.py +349 -0
- db_git-0.1.0/src/git_db/hook_script.py +49 -0
- db_git-0.1.0/src/git_db/state.py +105 -0
- db_git-0.1.0/src/git_db/storage.py +203 -0
- db_git-0.1.0/tests/__init__.py +0 -0
- db_git-0.1.0/tests/_pg_helpers.py +214 -0
- db_git-0.1.0/tests/conftest.py +196 -0
- db_git-0.1.0/tests/e2e/__init__.py +0 -0
- db_git-0.1.0/tests/e2e/_helpers.py +44 -0
- db_git-0.1.0/tests/e2e/conftest.py +28 -0
- db_git-0.1.0/tests/e2e/test_per_branch_pgdump_workflow.py +745 -0
- db_git-0.1.0/tests/e2e/test_per_branch_template_workflow.py +794 -0
- db_git-0.1.0/tests/e2e/test_shared_pgdump_workflow.py +713 -0
- db_git-0.1.0/tests/e2e/test_shared_template_workflow.py +730 -0
- db_git-0.1.0/tests/integration/__init__.py +0 -0
- db_git-0.1.0/tests/integration/conftest.py +113 -0
- db_git-0.1.0/tests/integration/test_branch_db.py +205 -0
- db_git-0.1.0/tests/integration/test_connections.py +191 -0
- db_git-0.1.0/tests/integration/test_pgdump_strategy.py +293 -0
- db_git-0.1.0/tests/integration/test_template_strategy.py +300 -0
- db_git-0.1.0/tests/unit/__init__.py +0 -0
- db_git-0.1.0/tests/unit/test_cli.py +744 -0
- db_git-0.1.0/tests/unit/test_config.py +207 -0
- db_git-0.1.0/tests/unit/test_db.py +23 -0
- db_git-0.1.0/tests/unit/test_git.py +75 -0
- db_git-0.1.0/tests/unit/test_state.py +86 -0
- db_git-0.1.0/tests/unit/test_storage.py +239 -0
- db_git-0.1.0/uv.lock +884 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"WebSearch",
|
|
5
|
+
"mcp__context7__query-docs",
|
|
6
|
+
"Read(//private/tmp/git-hook-test/**)",
|
|
7
|
+
"Bash(chmod +x .git/hooks/post-checkout)",
|
|
8
|
+
"mcp__context7__resolve-library-id",
|
|
9
|
+
"Bash(uv run:*)",
|
|
10
|
+
"WebFetch(domain:raw.githubusercontent.com)",
|
|
11
|
+
"Bash(gh search:*)",
|
|
12
|
+
"WebFetch(domain:pytest-postgresql.readthedocs.io)",
|
|
13
|
+
"WebFetch(domain:github.com)",
|
|
14
|
+
"Bash(gh api *)",
|
|
15
|
+
"Bash(curl -s \"https://api.github.com/repos/dbt-labs/dbt-core/contents/tests/functional\")",
|
|
16
|
+
"Bash(python3 -c \"import json,sys; [print\\(x['name']\\) for x in json.load\\(sys.stdin\\)]\")",
|
|
17
|
+
"Bash(curl -s \"https://api.github.com/repos/dolthub/dolt/contents/integration-tests/bats\")",
|
|
18
|
+
"Bash(python3 -c \"import json,sys; [print\\(x['name']\\) for x in json.load\\(sys.stdin\\) if 'branch' in x.get\\('name',''\\).lower\\(\\) or 'checkout' in x.get\\('name',''\\).lower\\(\\)]\")",
|
|
19
|
+
"Bash(curl -s \"https://api.github.com/repos/dbt-labs/dbt-adapters/contents/dbt-tests-adapter/src/dbt/tests/fixtures\")",
|
|
20
|
+
"Bash(python3 -c \"import json,sys; d=json.load\\(sys.stdin\\); [print\\(x['name']\\) for x in d] if isinstance\\(d,list\\) else print\\(d\\)\")",
|
|
21
|
+
"Bash(curl -s \"https://api.github.com/repos/dbt-labs/dbt-adapters/git/trees/main?recursive=1\")",
|
|
22
|
+
"Bash(python3 -c \"import json,sys; d=json.load\\(sys.stdin\\); [print\\(x['path']\\) for x in d.get\\('tree',[]\\) if 'fixtures' in x['path'] and x['path'].endswith\\('.py'\\)]\")",
|
|
23
|
+
"Bash(python -c \"import typer, click; print\\('typer.Exit MRO:', [c.__name__ for c in typer.Exit.__mro__]\\); print\\('is Exception subclass:', issubclass\\(typer.Exit, Exception\\)\\)\")"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
unit:
|
|
14
|
+
name: unit (${{ matrix.python }})
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
strategy:
|
|
17
|
+
matrix:
|
|
18
|
+
python: ["3.12", "3.13"]
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v6
|
|
21
|
+
- uses: astral-sh/setup-uv@v7
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: true
|
|
24
|
+
- uses: actions/setup-python@v6
|
|
25
|
+
with:
|
|
26
|
+
python-version: ${{ matrix.python }}
|
|
27
|
+
- run: pipx install nox
|
|
28
|
+
- run: nox -s unit -p "${{ matrix.python }}"
|
|
29
|
+
|
|
30
|
+
integration:
|
|
31
|
+
name: integration (py${{ matrix.python }}, pg${{ matrix.postgres }})
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
strategy:
|
|
34
|
+
fail-fast: false
|
|
35
|
+
matrix:
|
|
36
|
+
python: ["3.12", "3.13"]
|
|
37
|
+
postgres: ["13", "14", "15", "16", "17"]
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v6
|
|
40
|
+
- uses: astral-sh/setup-uv@v7
|
|
41
|
+
with:
|
|
42
|
+
enable-cache: true
|
|
43
|
+
- uses: actions/setup-python@v6
|
|
44
|
+
with:
|
|
45
|
+
python-version: ${{ matrix.python }}
|
|
46
|
+
- name: Install matching postgresql-client
|
|
47
|
+
run: |
|
|
48
|
+
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
|
49
|
+
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pgdg.gpg
|
|
50
|
+
sudo apt-get update
|
|
51
|
+
sudo apt-get install -y postgresql-client-${{ matrix.postgres }}
|
|
52
|
+
- run: pipx install nox
|
|
53
|
+
- run: nox -s "integration-${{ matrix.python }}(pg_image='postgres:${{ matrix.postgres }}')"
|
|
54
|
+
|
|
55
|
+
types:
|
|
56
|
+
name: mypy
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v6
|
|
60
|
+
- uses: astral-sh/setup-uv@v7
|
|
61
|
+
with:
|
|
62
|
+
enable-cache: true
|
|
63
|
+
- uses: actions/setup-python@v6
|
|
64
|
+
with:
|
|
65
|
+
python-version: "3.12"
|
|
66
|
+
- run: pipx install nox
|
|
67
|
+
- run: nox -s types
|
|
68
|
+
|
|
69
|
+
lint:
|
|
70
|
+
name: ruff
|
|
71
|
+
runs-on: ubuntu-latest
|
|
72
|
+
steps:
|
|
73
|
+
- uses: actions/checkout@v6
|
|
74
|
+
- uses: astral-sh/setup-uv@v7
|
|
75
|
+
with:
|
|
76
|
+
enable-cache: true
|
|
77
|
+
- uses: actions/setup-python@v6
|
|
78
|
+
with:
|
|
79
|
+
python-version: "3.12"
|
|
80
|
+
- run: pipx install nox
|
|
81
|
+
- run: nox -s lint
|
db_git-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
default_language_version:
|
|
2
|
+
python: python3.12
|
|
3
|
+
|
|
4
|
+
repos:
|
|
5
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
6
|
+
rev: v6.0.0
|
|
7
|
+
hooks:
|
|
8
|
+
- id: trailing-whitespace
|
|
9
|
+
- id: end-of-file-fixer
|
|
10
|
+
- id: check-yaml
|
|
11
|
+
- id: check-toml
|
|
12
|
+
- id: check-merge-conflict
|
|
13
|
+
- id: check-added-large-files
|
|
14
|
+
|
|
15
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
16
|
+
rev: v0.15.15
|
|
17
|
+
hooks:
|
|
18
|
+
- id: ruff-check
|
|
19
|
+
args: [--fix]
|
|
20
|
+
- id: ruff-format
|
|
21
|
+
|
|
22
|
+
- repo: local
|
|
23
|
+
hooks:
|
|
24
|
+
- id: mypy
|
|
25
|
+
name: mypy
|
|
26
|
+
entry: uv run mypy
|
|
27
|
+
language: system
|
|
28
|
+
types: [python]
|
|
29
|
+
pass_filenames: false
|
|
30
|
+
args: [src/]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-05-22
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Initial `git-db` command-line interface.
|
|
13
|
+
- Git `post-checkout` hook installation, removal, enable, disable, and dispatch
|
|
14
|
+
support.
|
|
15
|
+
- Shared database mode for saving and restoring branch-specific snapshots.
|
|
16
|
+
- Per-branch database mode for creating one database per git branch.
|
|
17
|
+
- PostgreSQL backend with `template` and `pgdump` snapshot strategies.
|
|
18
|
+
- Active connection handling with `terminate` and `fail` policies.
|
|
19
|
+
- Manual commands for `save`, `restore`, `create`, `reset`, `list`, `status`,
|
|
20
|
+
and `prune`.
|
|
21
|
+
- Snapshot metadata and local state storage under `.git/git-db/`.
|
|
22
|
+
- Unit, integration, and end-to-end tests for CLI, storage, git hooks,
|
|
23
|
+
PostgreSQL strategies, and branch database workflows.
|
|
24
|
+
- Nox sessions, Ruff linting/format checks, mypy type checking, pre-commit
|
|
25
|
+
hooks, Dependabot, and GitHub Actions CI.
|
db_git-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hana Belay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
db_git-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: db-git
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Keep your database in sync with your git branches.
|
|
5
|
+
Project-URL: Homepage, https://github.com/earthcomfy/git-db
|
|
6
|
+
Project-URL: Repository, https://github.com/earthcomfy/git-db
|
|
7
|
+
Project-URL: Issues, https://github.com/earthcomfy/git-db/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/earthcomfy/git-db/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Hana Belay
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: branching,cli,database,developer-tools,git,migrations,postgresql,snapshot
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Database
|
|
22
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.12
|
|
26
|
+
Requires-Dist: psycopg[binary]>=3.3.0
|
|
27
|
+
Requires-Dist: rich>=14.0.0
|
|
28
|
+
Requires-Dist: tomlkit>=0.14.0
|
|
29
|
+
Requires-Dist: typer>=0.24.1
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# git-db
|
|
33
|
+
|
|
34
|
+
[](https://github.com/earthcomfy/git-db/actions/workflows/test.yml)
|
|
35
|
+
[](https://pypi.org/project/git-db/)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
|
|
38
|
+
Keep your database in sync with your git branches.
|
|
39
|
+
|
|
40
|
+
`git-db` is a developer tool for projects where database state follows code
|
|
41
|
+
changes: schema migrations, seed data, experimental feature work, and branch
|
|
42
|
+
switching during reviews. It installs a git `post-checkout` hook and keeps your
|
|
43
|
+
local database aligned with the branch you are working on.
|
|
44
|
+
|
|
45
|
+
> Status: PostgreSQL is supported today; support for additional database
|
|
46
|
+
> engines is planned.
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- Automatic database handling on `git checkout`
|
|
51
|
+
- Two workflows:
|
|
52
|
+
- `shared`: one database, saved and restored per branch
|
|
53
|
+
- `per-branch`: one database per branch
|
|
54
|
+
- PostgreSQL support today, with plans for more database backends
|
|
55
|
+
- Two PostgreSQL snapshot strategies:
|
|
56
|
+
- `template`: fast database clones using `CREATE DATABASE ... TEMPLATE`
|
|
57
|
+
- `pgdump`: portable snapshots using `pg_dump` and `pg_restore`
|
|
58
|
+
- Manual `save`, `restore`, `create`, `reset`, `list`, `status`, and `prune`
|
|
59
|
+
commands
|
|
60
|
+
- Safe hook behavior: checkout is never blocked by git-db failures
|
|
61
|
+
- Rich terminal output and local state stored under `.git/git-db/`
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uv tool install git-db # or pip install git-db
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Run this from inside a git repository:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git-db init --database-url postgresql://postgres:postgres@localhost:5432/myapp
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Interactive init will ask:
|
|
76
|
+
|
|
77
|
+
- Whether to use `shared` or `per-branch` mode
|
|
78
|
+
- Whether to use `template` or `pgdump` strategy
|
|
79
|
+
- What to do when active connections block database operations
|
|
80
|
+
- Whether to install the git `post-checkout` hook
|
|
81
|
+
|
|
82
|
+
After setup, switch branches normally:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
git checkout feature/auth
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
In `shared` mode, git-db saves the previous branch database and restores the
|
|
89
|
+
new branch snapshot if one exists.
|
|
90
|
+
|
|
91
|
+
In `per-branch` mode, git-db creates or selects a database named from the
|
|
92
|
+
current branch, for example:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
myapp__feature__auth
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Because the database name changes per branch, your application server also
|
|
99
|
+
needs to connect to the branch database. For example, when working on
|
|
100
|
+
`feature/auth`, point your app's `DATABASE_URL` at `myapp__feature__auth`.
|
|
101
|
+
|
|
102
|
+
## Choosing a Mode
|
|
103
|
+
|
|
104
|
+
### Shared Mode
|
|
105
|
+
|
|
106
|
+
Shared mode keeps one database name from `DATABASE_URL`.
|
|
107
|
+
|
|
108
|
+
Use this when:
|
|
109
|
+
|
|
110
|
+
- You want one familiar local database name
|
|
111
|
+
- You want branch-specific snapshots
|
|
112
|
+
- You are comfortable with git-db dropping and restoring that local database
|
|
113
|
+
during branch switches
|
|
114
|
+
|
|
115
|
+
### Per-Branch Mode
|
|
116
|
+
|
|
117
|
+
Per-branch mode creates a separate database for each branch. The configured
|
|
118
|
+
default branch keeps the original database name and acts as the seed database.
|
|
119
|
+
|
|
120
|
+
Use this when:
|
|
121
|
+
|
|
122
|
+
- You want branch databases to persist independently
|
|
123
|
+
- You prefer creating new databases over repeatedly restoring one shared
|
|
124
|
+
database
|
|
125
|
+
|
|
126
|
+
## Choosing a Strategy
|
|
127
|
+
|
|
128
|
+
### template
|
|
129
|
+
|
|
130
|
+
The `template` strategy uses PostgreSQL database cloning:
|
|
131
|
+
|
|
132
|
+
```sql
|
|
133
|
+
CREATE DATABASE target TEMPLATE source;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It is usually fast, but requires sufficient PostgreSQL privileges and can be
|
|
137
|
+
blocked by active connections to the source or target database.
|
|
138
|
+
|
|
139
|
+
### pgdump
|
|
140
|
+
|
|
141
|
+
The `pgdump` strategy uses `pg_dump` and `pg_restore`.
|
|
142
|
+
|
|
143
|
+
It is slower than `template`, but can be a better fit when template cloning is
|
|
144
|
+
not available. It requires PostgreSQL client tools to be installed locally.
|
|
145
|
+
|
|
146
|
+
## Commands
|
|
147
|
+
|
|
148
|
+
### Initialize
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
git-db init --database-url postgresql://user:password@localhost:5432/myapp
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Useful options:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
git-db init \
|
|
158
|
+
--database-url postgresql://user:password@localhost:5432/myapp \
|
|
159
|
+
--mode per-branch \
|
|
160
|
+
--strategy template \
|
|
161
|
+
--on-active-connections terminate
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Skip hook installation:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
git-db init --database-url postgresql://localhost/myapp --no-hook
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Inspect State
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
git-db status
|
|
174
|
+
git-db list
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Shared Mode Commands
|
|
178
|
+
|
|
179
|
+
Save the current branch database:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
git-db save
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Restore the current branch database:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
git-db restore
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Save or restore a specific branch:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
git-db save main
|
|
195
|
+
git-db restore feature/auth
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Per-Branch Commands
|
|
199
|
+
|
|
200
|
+
Create a branch database before checking out the branch:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
git-db create feature/auth
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Drop and recreate a branch database from the seed database:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
git-db reset feature/auth
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The default branch database cannot be reset because it is the seed for other
|
|
213
|
+
branch databases.
|
|
214
|
+
|
|
215
|
+
### Prune Deleted Branches
|
|
216
|
+
|
|
217
|
+
Preview stale snapshots or branch databases:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
git-db prune --dry-run
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Remove stale snapshots or branch databases:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
git-db prune --yes
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Hook Management
|
|
230
|
+
|
|
231
|
+
Install or reinstall the checkout hook:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
git-db hook install
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Remove the checkout hook:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
git-db hook remove
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Temporarily disable git-db without removing the hook:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
git-db disable
|
|
247
|
+
git-db enable
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
You can also skip hook behavior for a single checkout:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
GIT_DB_SKIP=1 git checkout other-branch
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Configuration
|
|
257
|
+
|
|
258
|
+
`git-db init` writes `.git-db.toml` at the repository root.
|
|
259
|
+
|
|
260
|
+
Example:
|
|
261
|
+
|
|
262
|
+
```toml
|
|
263
|
+
database_url = "postgresql://postgres:postgres@localhost:5432/myapp"
|
|
264
|
+
mode = "per-branch"
|
|
265
|
+
default_branch = "main"
|
|
266
|
+
strategy = "template"
|
|
267
|
+
on_active_connections = "terminate"
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Supported configuration keys:
|
|
271
|
+
|
|
272
|
+
| Key | Description | Default |
|
|
273
|
+
| --- | --- | --- |
|
|
274
|
+
| `database_url` | Database connection URL | required |
|
|
275
|
+
| `mode` | `shared` or `per-branch` | `shared` |
|
|
276
|
+
| `default_branch` | Seed branch for per-branch mode | `main` |
|
|
277
|
+
| `strategy` | `template` or `pgdump` | required |
|
|
278
|
+
| `on_active_connections` | `terminate` or `fail` | `terminate` |
|
|
279
|
+
| `snapshot_dir` | Shared-mode snapshot metadata/dump directory | `.git/git-db/snapshots` |
|
|
280
|
+
| `max_snapshots` | Snapshot count kept by prune logic | `20` |
|
|
281
|
+
| `force_terminate_timeout_ms` | Active connection termination timeout | `5000` |
|
|
282
|
+
|
|
283
|
+
Configuration precedence:
|
|
284
|
+
|
|
285
|
+
1. Built-in defaults
|
|
286
|
+
2. `.git-db.toml`
|
|
287
|
+
3. Environment variables
|
|
288
|
+
4. CLI options
|
|
289
|
+
|
|
290
|
+
Environment variables:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
DATABASE_URL
|
|
294
|
+
GIT_DB_DATABASE_URL
|
|
295
|
+
GIT_DB_MODE
|
|
296
|
+
GIT_DB_STRATEGY
|
|
297
|
+
GIT_DB_ON_ACTIVE_CONNECTIONS
|
|
298
|
+
GIT_DB_SNAPSHOT_DIR
|
|
299
|
+
GIT_DB_MAX_SNAPSHOTS
|
|
300
|
+
GIT_DB_FORCE_TERMINATE_TIMEOUT_MS
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
`GIT_DB_DATABASE_URL` takes precedence over `DATABASE_URL`.
|
|
304
|
+
|
|
305
|
+
### Active connections block an operation
|
|
306
|
+
|
|
307
|
+
Stop your development server, database console, migration watcher, or GUI
|
|
308
|
+
client, then retry.
|
|
309
|
+
|
|
310
|
+
Alternatively, configure:
|
|
311
|
+
|
|
312
|
+
```toml
|
|
313
|
+
on_active_connections = "terminate"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Your PostgreSQL user may need superuser privileges or membership in
|
|
317
|
+
`pg_signal_backend` to terminate sessions owned by other users.
|
|
318
|
+
|
|
319
|
+
### Temporarily skip git-db
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
git-db disable
|
|
323
|
+
git checkout some-branch
|
|
324
|
+
git-db enable
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Or for one command:
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
GIT_DB_SKIP=1 git checkout some-branch
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Show full tracebacks
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
GIT_DB_DEBUG=1 git-db status
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Development
|
|
340
|
+
|
|
341
|
+
Install dependencies:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
uv sync --group dev
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Run checks:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
uv run ruff check .
|
|
351
|
+
uv run mypy src tests
|
|
352
|
+
uv run pytest tests/unit
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Run the full nox suite:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
nox
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## License
|
|
362
|
+
|
|
363
|
+
MIT
|