@developer-ayushanand/dbgit 0.1.0-beta.1

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.
Files changed (66) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +33 -0
  2. package/.github/PULL_REQUEST_TEMPLATE.md +20 -0
  3. package/.github-issue-bug.md +57 -0
  4. package/.github-workflows-ci.yml +41 -0
  5. package/CODE_OF_CONDUCT.md +45 -0
  6. package/CONTRIBUTING.md +29 -0
  7. package/LICENSE +21 -0
  8. package/README.md +115 -0
  9. package/SECURITY.md +15 -0
  10. package/dbgit-0.1.0-beta.1.tgz +0 -0
  11. package/dist/cli.d.ts +2 -0
  12. package/dist/cli.js +173 -0
  13. package/dist/commands/branch.d.ts +3 -0
  14. package/dist/commands/branch.js +34 -0
  15. package/dist/commands/checkout.d.ts +1 -0
  16. package/dist/commands/checkout.js +59 -0
  17. package/dist/commands/commit.d.ts +3 -0
  18. package/dist/commands/commit.js +86 -0
  19. package/dist/commands/diff.d.ts +1 -0
  20. package/dist/commands/diff.js +91 -0
  21. package/dist/commands/doctor.d.ts +1 -0
  22. package/dist/commands/doctor.js +115 -0
  23. package/dist/commands/init.d.ts +4 -0
  24. package/dist/commands/init.js +84 -0
  25. package/dist/commands/log.d.ts +1 -0
  26. package/dist/commands/log.js +18 -0
  27. package/dist/commands/merge.d.ts +1 -0
  28. package/dist/commands/merge.js +101 -0
  29. package/dist/commands/purge.d.ts +1 -0
  30. package/dist/commands/purge.js +85 -0
  31. package/dist/commands/restore-backup.d.ts +1 -0
  32. package/dist/commands/restore-backup.js +14 -0
  33. package/dist/commands/restore.d.ts +1 -0
  34. package/dist/commands/restore.js +33 -0
  35. package/dist/commands/rollback.d.ts +6 -0
  36. package/dist/commands/rollback.js +187 -0
  37. package/dist/core/backup.d.ts +5 -0
  38. package/dist/core/backup.js +40 -0
  39. package/dist/core/connector.d.ts +13 -0
  40. package/dist/core/connector.js +39 -0
  41. package/dist/core/dependencyGraph.d.ts +5 -0
  42. package/dist/core/dependencyGraph.js +87 -0
  43. package/dist/core/differ.d.ts +3 -0
  44. package/dist/core/differ.js +218 -0
  45. package/dist/core/generator.d.ts +3 -0
  46. package/dist/core/generator.js +104 -0
  47. package/dist/core/ignore.d.ts +3 -0
  48. package/dist/core/ignore.js +20 -0
  49. package/dist/core/schemaLock.d.ts +3 -0
  50. package/dist/core/schemaLock.js +18 -0
  51. package/dist/core/snapshot.d.ts +4 -0
  52. package/dist/core/snapshot.js +121 -0
  53. package/dist/core/store.d.ts +19 -0
  54. package/dist/core/store.js +102 -0
  55. package/dist/core/transaction.d.ts +2 -0
  56. package/dist/core/transaction.js +17 -0
  57. package/dist/core/validator.d.ts +4 -0
  58. package/dist/core/validator.js +18 -0
  59. package/dist/types/changes.d.ts +27 -0
  60. package/dist/types/changes.js +14 -0
  61. package/dist/types/commits.d.ts +21 -0
  62. package/dist/types/commits.js +1 -0
  63. package/dist/types/schema.d.ts +40 -0
  64. package/dist/types/schema.js +1 -0
  65. package/package.json +38 -0
  66. package/tsconfig.json +16 -0
@@ -0,0 +1,33 @@
1
+ name: Bug Report
2
+ description: File a bug report to help us improve DBGit
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for reporting a bug! Please fill out the information below.
9
+ - type: textarea
10
+ id: description
11
+ attributes:
12
+ label: Description
13
+ description: What happened?
14
+ validations:
15
+ required: true
16
+ - type: textarea
17
+ id: steps
18
+ attributes:
19
+ label: Steps to Reproduce
20
+ description: How can we reproduce this issue?
21
+ placeholder: |
22
+ 1. Run 'dbgit init'
23
+ 2. ALTER TABLE ...
24
+ 3. ...
25
+ validations:
26
+ required: true
27
+ - type: input
28
+ id: version
29
+ attributes:
30
+ label: DBGit Version
31
+ placeholder: 0.1.0-beta.1
32
+ validations:
33
+ required: true
@@ -0,0 +1,20 @@
1
+ # Description
2
+
3
+ Please include a summary of the change and which issue is fixed.
4
+
5
+ ## Type of change
6
+
7
+ - [ ] Bug fix (non-breaking change which fixes an issue)
8
+ - [ ] New feature (non-breaking change which adds functionality)
9
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
10
+ - [ ] Documentation update
11
+
12
+ ## Checklist:
13
+
14
+ - [ ] My code follows the style guidelines of this project
15
+ - [ ] I have performed a self-review of my own code
16
+ - [ ] I have commented my code, particularly in hard-to-understand areas
17
+ - [ ] I have made corresponding changes to the documentation
18
+ - [ ] My changes generate no new warnings
19
+ - [ ] I have added tests that prove my fix is effective or that my feature works
20
+ - [ ] New and existing unit tests pass locally with my changes
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: '[BUG] '
5
+ labels: bug
6
+ assignees: ''
7
+ ---
8
+
9
+ **DBGit version**
10
+ Run `dbgit --version`
11
+
12
+ **PostgreSQL version**
13
+ Run `psql --version`
14
+
15
+ **Node.js version**
16
+ Run `node --version`
17
+
18
+ **Describe the bug**
19
+ A clear and concise description of what the bug is.
20
+
21
+ **To Reproduce**
22
+ Steps to reproduce the behavior:
23
+ 1. Run `dbgit init`
24
+ 2. Run `dbgit commit -m "..."`
25
+ 3. See error
26
+
27
+ **Expected behavior**
28
+ What you expected to happen.
29
+
30
+ **Actual output**
31
+ Paste the full terminal output here.
32
+
33
+ **Additional context**
34
+ Add any other context about the problem here.
35
+ EOF
36
+
37
+ cat > /home/claude/dbgit-launch/.github-issue-feature.md << 'EOF'
38
+ ---
39
+ name: Feature request
40
+ about: Suggest an idea for DBGit
41
+ title: '[FEAT] '
42
+ labels: enhancement
43
+ assignees: ''
44
+ ---
45
+
46
+ **Is your feature request related to a problem?**
47
+ A clear description of the problem.
48
+
49
+ **Describe the solution you'd like**
50
+ What you want DBGit to do.
51
+
52
+ **Describe alternatives you've considered**
53
+ Other approaches you considered.
54
+
55
+ **Would you contribute this?**
56
+ - [ ] Yes, I can open a PR
57
+ - [ ] No, but I'd love to see it
@@ -0,0 +1,41 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ node-version: [18.x, 20.x, 22.x]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Use Node.js ${{ matrix.node-version }}
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version: ${{ matrix.node-version }}
21
+ cache: 'npm'
22
+ - run: npm ci
23
+ - run: npm run build
24
+ - run: npm test
25
+ - run: npm run lint
26
+
27
+ publish:
28
+ needs: test
29
+ runs-on: ubuntu-latest
30
+ if: github.ref == 'refs/heads/main' && startsWith(github.event.head_commit.message, 'release:')
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ - uses: actions/setup-node@v4
34
+ with:
35
+ node-version: '20.x'
36
+ registry-url: 'https://registry.npmjs.org'
37
+ - run: npm ci
38
+ - run: npm run build
39
+ - run: npm publish
40
+ env:
41
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,45 @@
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
44
+
45
+ [homepage]: https://www.contributor-covenant.org
@@ -0,0 +1,29 @@
1
+ # Contributing to DBGit
2
+
3
+ We love your input! We want to make contributing to DBGit as easy and transparent as possible, whether it's:
4
+
5
+ - Reporting a bug
6
+ - Discussing the current state of the code
7
+ - Submitting a fix
8
+ - Proposing new features
9
+ - Becoming a maintainer
10
+
11
+ ## Development Process
12
+
13
+ 1. Fork the repo and create your branch from `main`.
14
+ 2. Install dependencies: `npm install`
15
+ 3. Make your changes.
16
+ 4. Run tests: `npm test`
17
+ 5. Ensure type safety: `npm run typecheck`
18
+ 6. Submit a Pull Request.
19
+
20
+ ## Coding Conventions
21
+
22
+ - Use TypeScript for all new code.
23
+ - Follow the existing architectural patterns (Commands -> Core -> Types).
24
+ - Add tests for any new features or bug fixes.
25
+ - Ensure CLI output remains consistent with the "Prisma + Git" aesthetic.
26
+
27
+ ## License
28
+
29
+ By contributing, you agree that your contributions will be licensed under its MIT License.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DBGit Contributors
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.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # DBGit
2
+
3
+ Git for your database schema.
4
+
5
+ **Branch. Diff. Commit. Rollback.**
6
+ *Without writing migration scripts.*
7
+
8
+ [![npm version](https://img.shields.io/npm/v/dbgit.svg)](https://www.npmjs.com/package/dbgit)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)
11
+
12
+ > ⚠ **BETA SOFTWARE**: DBGit is currently in beta. Always test against staging databases first. DBGit modifies database schemas. Maintain backups before production use.
13
+
14
+ ## What is DBGit?
15
+
16
+ DBGit brings the power of version control to your PostgreSQL database schema. Instead of manually managing migration files, DBGit tracks the *state* of your schema, allowing you to move between versions as easily as you switch branches in Git.
17
+
18
+ **Why doesn't PostgreSQL already have this?**
19
+ DBGit fills the gap between code versioning and database management, solving common pains like accidental `ALTER TABLE` calls, broken migrations, and the "fear of rollback."
20
+
21
+ ## Quick Start
22
+
23
+ 1. **Configure your database connection:**
24
+ ```bash
25
+ export DATABASE_URL=postgres://user:pass@localhost:5432/mydb
26
+ ```
27
+
28
+ 2. **Initialize DBGit:**
29
+ ```bash
30
+ dbgit init
31
+ ```
32
+
33
+ 3. **See what changed (Drift Detection):**
34
+ ```bash
35
+ # Add a column in your DB
36
+ dbgit diff
37
+ ```
38
+
39
+ 4. **Commit your changes:**
40
+ ```bash
41
+ dbgit commit -m "add email column to users"
42
+ ```
43
+
44
+ 5. **Rollback safely:**
45
+ ```bash
46
+ dbgit rollback <commit-hash>
47
+ ```
48
+
49
+ ## Example Session
50
+
51
+ ```bash
52
+ $ dbgit diff
53
+ + column users.email character varying(255)
54
+
55
+ $ dbgit commit -m "add user emails"
56
+ ✓ Commit a9f2d1b saved.
57
+ 12 tables · 84 columns · 15 indexes
58
+ Branch: main
59
+
60
+ $ dbgit rollback a9f2d1b
61
+ ┌ Rollback Risk: HIGH ────────────────┐
62
+ │ │
63
+ │ ⚠ DESTRUCTIVE CHANGES DETECTED │
64
+ │ │
65
+ │ ✗ DROP_COLUMN: users.email │
66
+ │ Impact: 1842 non-null rows │
67
+ │ │
68
+ └─────────────────────────────────────┘
69
+ ? Continue with destructive rollback? (y/N)
70
+ ```
71
+
72
+ ## Architecture
73
+
74
+ DBGit uses a snapshot-based approach to track your schema state.
75
+
76
+ ```mermaid
77
+ graph TD
78
+ A[Live Database] --> B[Snapshot Engine]
79
+ B --> C[Diff Engine]
80
+ C --> D[Commit Store]
81
+ D --> E[Rollback Generator]
82
+ E --> A
83
+ ```
84
+
85
+ ## Safety Model
86
+
87
+ DBGit is built for trust and reliability:
88
+
89
+ - **Transactions**: All operations run inside a `BEGIN/COMMIT` block. Failure triggers a full `ROLLBACK`.
90
+ - **Drift Detection**: DBGit detects if the live database has changed outside of DBGit and aborts dangerous operations for safety.
91
+ - **Impact Analysis**: Destructive operations (`DROP TABLE`, `DROP COLUMN`) show exact row counts and foreign key dependency warnings.
92
+ - **Soft Delete**: Use `--soft-delete` to rename objects (e.g., `_dbgit_deleted_users_1700000000`) instead of dropping them.
93
+ - **Backups**: In `prod` mode, destructive operations require `--safe` which forces a physical backup before proceeding.
94
+
95
+ ## Rollback & Checkout Semantics
96
+
97
+ - **Rollback**: Follows `git revert` semantics. It creates a *new* commit that restores the schema to a previous state, preserving history.
98
+ - **Checkout**: Safely switches branches or HEAD. It **never** modifies the live database schema.
99
+
100
+ ## Known Limitations
101
+
102
+ - **PostgreSQL Only**: Currently supports PostgreSQL (target version 12+).
103
+ - **Rename Detection**: Renames are currently detected as a DROP + ADD.
104
+ - **Public Schema**: Focuses on the `public` schema.
105
+
106
+ ## Roadmap
107
+
108
+ - [ ] Support for multiple schemas
109
+ - [ ] Rename detection improvements
110
+ - [ ] Support for Views and Stored Procedures
111
+ - [ ] CI/CD integration helpers
112
+
113
+ ## License
114
+
115
+ MIT
package/SECURITY.md ADDED
@@ -0,0 +1,15 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Only the latest version of DBGit is currently supported for security updates.
6
+
7
+ | Version | Supported |
8
+ | ------- | ------------------ |
9
+ | 0.1.x | :white_check_mark: |
10
+
11
+ ## Reporting a Vulnerability
12
+
13
+ If you discover a security vulnerability within DBGit, please do not report it via the public issue tracker. Instead, please report it via [Security Advisory on GitHub] or by emailing the maintainers.
14
+
15
+ We take security seriously and will respond to all reports as quickly as possible.
Binary file
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { initCommand } from './commands/init.js';
5
+ import { commitCommand } from './commands/commit.js';
6
+ import { diffCommand } from './commands/diff.js';
7
+ import { logCommand } from './commands/log.js';
8
+ import { rollbackCommand } from './commands/rollback.js';
9
+ import { branchCommand } from './commands/branch.js';
10
+ import { checkoutCommand } from './commands/checkout.js';
11
+ import { restoreCommand } from './commands/restore.js';
12
+ import { mergeCommand } from './commands/merge.js';
13
+ import { doctorCommand } from './commands/doctor.js';
14
+ import { restoreBackupCommand } from './commands/restore-backup.js';
15
+ import { purgeCommand } from './commands/purge.js';
16
+ const program = new Command();
17
+ program
18
+ .name('dbgit')
19
+ .description('Git for your database schema — branch, diff, commit, rollback.')
20
+ .version('0.1.0');
21
+ program
22
+ .command('init')
23
+ .description('Initialize a new DBGit repository')
24
+ .option('--mode <mode>', 'Environment mode (dev|prod)', 'dev')
25
+ .option('--recover', 'Recover state from live database')
26
+ .action(async (options) => {
27
+ try {
28
+ await initCommand(options);
29
+ }
30
+ catch (e) {
31
+ console.error(chalk.red(e.message));
32
+ process.exit(1);
33
+ }
34
+ });
35
+ program
36
+ .command('commit')
37
+ .description('Snapshot the current database schema')
38
+ .requiredOption('-m, --message <message>', 'Commit message')
39
+ .action(async (options) => {
40
+ try {
41
+ await commitCommand(options);
42
+ }
43
+ catch (e) {
44
+ console.error(chalk.red(e.message));
45
+ process.exit(1);
46
+ }
47
+ });
48
+ program
49
+ .command('diff')
50
+ .description('Show changes between last commit and live database')
51
+ .action(async () => {
52
+ try {
53
+ await diffCommand();
54
+ }
55
+ catch (e) {
56
+ console.error(chalk.red(e.message));
57
+ process.exit(1);
58
+ }
59
+ });
60
+ program
61
+ .command('log')
62
+ .description('Show commit logs')
63
+ .action(() => {
64
+ try {
65
+ logCommand();
66
+ }
67
+ catch (e) {
68
+ console.error(chalk.red(e.message));
69
+ process.exit(1);
70
+ }
71
+ });
72
+ program
73
+ .command('rollback <hash>')
74
+ .description('Rollback database schema to a specific commit')
75
+ .option('--safe', 'Create a backup before rolling back')
76
+ .option('--force', 'Force destructive operations (required in prod mode)')
77
+ .option('--dry-run', 'Show SQL statements without executing them')
78
+ .option('--soft-delete', 'Rename dropped objects instead of deleting them')
79
+ .action(async (hash, options) => {
80
+ try {
81
+ await rollbackCommand(hash, options);
82
+ }
83
+ catch (e) {
84
+ console.error(chalk.red(e.message));
85
+ process.exit(1);
86
+ }
87
+ });
88
+ program
89
+ .command('branch [name]')
90
+ .description('List or create branches')
91
+ .option('--list', 'List all branches')
92
+ .action((name, options) => {
93
+ try {
94
+ branchCommand(name, options);
95
+ }
96
+ catch (e) {
97
+ console.error(chalk.red(e.message));
98
+ process.exit(1);
99
+ }
100
+ });
101
+ program
102
+ .command('checkout <ref>')
103
+ .description('Switch branches or restore database to a specific commit')
104
+ .action(async (ref) => {
105
+ try {
106
+ await checkoutCommand(ref);
107
+ }
108
+ catch (e) {
109
+ console.error(chalk.red(e.message));
110
+ process.exit(1);
111
+ }
112
+ });
113
+ program
114
+ .command('restore <hash> <table>')
115
+ .description('Restore a specific table to its state in a previous commit')
116
+ .action(async (hash, table) => {
117
+ try {
118
+ await restoreCommand(hash, table);
119
+ }
120
+ catch (e) {
121
+ console.error(chalk.red(e.message));
122
+ process.exit(1);
123
+ }
124
+ });
125
+ program
126
+ .command('merge <branch>')
127
+ .description('Merge changes from another branch into the current branch')
128
+ .action(async (branch) => {
129
+ try {
130
+ await mergeCommand(branch);
131
+ }
132
+ catch (e) {
133
+ console.error(chalk.red(e.message));
134
+ process.exit(1);
135
+ }
136
+ });
137
+ program
138
+ .command('doctor')
139
+ .description('Check health of DBGit repository and database connection')
140
+ .action(async () => {
141
+ try {
142
+ await doctorCommand();
143
+ }
144
+ catch (e) {
145
+ console.error(chalk.red(e.message));
146
+ process.exit(1);
147
+ }
148
+ });
149
+ program
150
+ .command('restore-backup <hash>')
151
+ .description('Print command to manually restore a backup')
152
+ .action((hash) => {
153
+ try {
154
+ restoreBackupCommand(hash);
155
+ }
156
+ catch (e) {
157
+ console.error(chalk.red(e.message));
158
+ process.exit(1);
159
+ }
160
+ });
161
+ program
162
+ .command('purge')
163
+ .description('Permanently remove soft-deleted objects')
164
+ .action(async () => {
165
+ try {
166
+ await purgeCommand();
167
+ }
168
+ catch (e) {
169
+ console.error(chalk.red(e.message));
170
+ process.exit(1);
171
+ }
172
+ });
173
+ program.parse(process.argv);
@@ -0,0 +1,3 @@
1
+ export declare function branchCommand(name?: string, options?: {
2
+ list?: boolean;
3
+ }): void;
@@ -0,0 +1,34 @@
1
+ import chalk from 'chalk';
2
+ import { listBranches, getHead, saveBranch, loadBranch } from '../core/store.js';
3
+ export function branchCommand(name, options) {
4
+ if (!name || options?.list) {
5
+ const branches = listBranches();
6
+ const head = getHead();
7
+ branches.forEach(b => {
8
+ if (b === head.branch) {
9
+ console.log(chalk.green(`* ${b}`));
10
+ }
11
+ else {
12
+ console.log(chalk.gray(` ${b}`));
13
+ }
14
+ });
15
+ return;
16
+ }
17
+ try {
18
+ loadBranch(name);
19
+ console.error(chalk.red(`Error: Branch '${name}' already exists.`));
20
+ process.exit(1);
21
+ }
22
+ catch (e) {
23
+ // Branch does not exist, good
24
+ }
25
+ const head = getHead();
26
+ const timestamp = new Date().toISOString();
27
+ saveBranch({
28
+ name,
29
+ headCommit: head.commit || '',
30
+ createdAt: timestamp,
31
+ basedOn: head.branch
32
+ });
33
+ console.log(chalk.green(`Branch '${name}' created. Based on ${head.branch || 'detached'}@${head.commit || 'initial'}`));
34
+ }
@@ -0,0 +1 @@
1
+ export declare function checkoutCommand(ref: string): Promise<void>;
@@ -0,0 +1,59 @@
1
+ import chalk from 'chalk';
2
+ import { getHead, loadBranch, loadCommit, setHead, listBranches, isInitialized } from '../core/store.js';
3
+ import { createPool, getConnectionConfig } from '../core/connector.js';
4
+ import { captureSnapshot } from '../core/snapshot.js';
5
+ import { loadIgnoreList } from '../core/ignore.js';
6
+ export async function checkoutCommand(ref) {
7
+ if (!isInitialized()) {
8
+ console.error(chalk.red("Not a DBGit repository. Run 'dbgit init' first."));
9
+ process.exit(1);
10
+ }
11
+ const head = getHead();
12
+ const branches = listBranches();
13
+ const ignoreList = loadIgnoreList();
14
+ const config = getConnectionConfig();
15
+ const pool = createPool(config);
16
+ let targetCommitHash;
17
+ let targetBranchName = null;
18
+ if (branches.includes(ref)) {
19
+ const branch = loadBranch(ref);
20
+ targetCommitHash = branch.headCommit;
21
+ targetBranchName = ref;
22
+ }
23
+ else {
24
+ try {
25
+ const commit = loadCommit(ref);
26
+ targetCommitHash = commit.commitHash;
27
+ }
28
+ catch (e) {
29
+ console.error(chalk.red(`Error: '${ref}' is not a valid branch or commit hash.`));
30
+ await pool.end();
31
+ process.exit(1);
32
+ }
33
+ }
34
+ // Check for drift before switching
35
+ try {
36
+ const liveSnapshot = await captureSnapshot(pool, ignoreList);
37
+ let headSchemaHash = '';
38
+ if (head.commit) {
39
+ const headCommit = loadCommit(head.commit);
40
+ headSchemaHash = headCommit.schemaHash;
41
+ }
42
+ if (headSchemaHash && liveSnapshot.schemaHash !== headSchemaHash) {
43
+ console.warn(chalk.yellow('⚠ Live database contains uncommitted schema changes.'));
44
+ console.warn(chalk.yellow('Checkout only changes DBGit state.'));
45
+ console.warn(chalk.yellow('Database schema remains unchanged.'));
46
+ }
47
+ }
48
+ catch (e) {
49
+ console.warn(chalk.yellow(`⚠ Could not check for schema drift: ${e.message}`));
50
+ }
51
+ setHead({ branch: targetBranchName, commit: targetCommitHash });
52
+ console.log(chalk.green(`✓ Switched to ${targetBranchName ? "branch '" + targetBranchName + "'" : "commit " + targetCommitHash}`));
53
+ if (!targetBranchName) {
54
+ console.log(chalk.yellow(`ℹ HEAD is now detached at ${targetCommitHash}. You are not on a branch.`));
55
+ }
56
+ console.log(chalk.yellow('⚠ Database schema unchanged.'));
57
+ console.log(chalk.gray('Use dbgit rollback to modify database state.'));
58
+ await pool.end();
59
+ }
@@ -0,0 +1,3 @@
1
+ export declare function commitCommand(options: {
2
+ message: string;
3
+ }): Promise<void>;