@farhan0431/db-snap 0.3.11 → 0.3.14

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.
package/README.md CHANGED
@@ -10,7 +10,10 @@ Supports **SQLite**, **PostgreSQL**, and **MySQL/MariaDB**. The npm package
10
10
  bundles prebuilt binaries for Windows x64, macOS Intel and Apple Silicon, and
11
11
  Linux x64 (glibc and musl) and ARM64 (glibc).
12
12
 
13
- **MySQL/MariaDB restore is available for the original database.** Stop writers and scheduled events first. Restore is not atomic and requires a pinned safety snapshot. Interrupted restores must recover that snapshot before another restore.
13
+ **MySQL/MariaDB restore works on the original database.** Stop application
14
+ connections, writers, and scheduled events first. Restore is non-atomic and
15
+ requires a pinned safety snapshot. Interrupted restores must recover that
16
+ snapshot before another restore; see the recovery steps below.
14
17
 
15
18
  ## Install
16
19
 
@@ -43,7 +46,8 @@ dbsnap list
43
46
  dbsnap restore "before migration" # restores the selected snapshot
44
47
  ```
45
48
 
46
- `dbsnap init` detects `DATABASE_URL` or common SQLite paths. To choose a
49
+ Target resolution is `--db`, then process `DATABASE_URL`, then project `.env`,
50
+ then common SQLite paths. To choose a
47
51
  database explicitly, use `dbsnap init --db ./prisma/dev.db`. Check the target
48
52
  with `dbsnap status` before restoring: a restore changes the live database.
49
53
 
@@ -69,15 +73,32 @@ the following to your project's `.cursor/mcp.json`:
69
73
  Restart your client and ask it to run `dbsnap_status` to confirm the database
70
74
  before making changes. The server also exposes tools to create, list, restore,
71
75
  and prune snapshots. It resolves the project from its working directory, so
72
- start it in the project you want to protect.
76
+ start it in the project you want to protect. The six tools are:
77
+
78
+ | MCP tool | Purpose |
79
+ | --- | --- |
80
+ | `dbsnap_status` | Inspect the target, engine, and snapshot storage. |
81
+ | `dbsnap_create_snapshot` | Save a snapshot, optionally supplying `tag`. |
82
+ | `dbsnap_list_snapshots` | List available restore points. |
83
+ | `dbsnap_diff` | Compare supported snapshots using `from` and `to`. |
84
+ | `dbsnap_restore_snapshot` | Restore a selected `tag_or_id`, or the newest snapshot. |
85
+ | `dbsnap_prune` | Prune with a positive integer `keep`; pinned snapshots survive. |
73
86
 
74
87
  Restore and prune are disabled by default in MCP. To enable them for a server
75
88
  session, start it with `dbsnap mcp --allow-destructive`. Each operation requires
76
89
  approval through an MCP client supporting elicitation; otherwise use the CLI.
77
90
 
91
+ To configure an explicitly enabled session, change the server arguments to
92
+ `["mcp", "--allow-destructive"]`. Enabling the session does not approve individual
93
+ operations. Your MCP client must still present and return the confirmation for
94
+ each restore or prune.
95
+
78
96
  `dbsnap init` also writes `.agents/skills/dbsnap/SKILL.md` in the project.
79
97
  Whether that skill is loaded automatically depends on the AI client; the skill
80
98
  file and the MCP server are separate integrations.
99
+ Initialization preserves an existing skill file instead of overwriting local
100
+ customizations. Updating the installed binary does not refresh that existing
101
+ file; review it against the repository's current skill when upgrading.
81
102
 
82
103
  ## Commands
83
104
 
@@ -90,14 +111,66 @@ file and the MCP server are separate integrations.
90
111
  | `dbsnap restore [tag-or-id]` | Restore a snapshot; omit the selector for the latest. |
91
112
  | `dbsnap rollback` | Restore the latest snapshot. |
92
113
  | `dbsnap prune --keep 5` | Remove older snapshots and retain the newest five. |
93
- | `dbsnap diff before after` | Compare SQLite snapshot schemas and table row counts. |
114
+ | `dbsnap diff before after` | Compare SQLite, PostgreSQL clone, or MySQL/MariaDB dump snapshot schemas and row counts. |
94
115
  | `dbsnap pin <tag-or-id>` | Protect a snapshot from pruning; use `unpin` to remove protection. |
116
+ | `dbsnap unpin <tag-or-id>` | Remove protection after reviewing the snapshot. |
117
+ | `dbsnap prune --all` | Delete all unpinned snapshots. |
118
+ | `dbsnap save tag --method dump` | Create a portable PostgreSQL dump snapshot. |
95
119
 
96
- `dbsnap list --json` and `dbsnap status --json` provide machine-readable
97
- output. SQLite `diff` does not compare individual row contents; PostgreSQL and
98
- MySQL/MariaDB snapshot diffs are not currently supported.
120
+ `dbsnap list --json` and `dbsnap status --json` provide machine-readable output.
99
121
  Pinned snapshots survive `prune`, including `--all`.
100
122
 
123
+ Use the recorded ID when undoing a specific change. Duplicate tags may be
124
+ ambiguous. `rollback` and `restore` without a selector choose the newest
125
+ snapshot, which can be an automatic safety snapshot from a previous restore.
126
+
127
+ ## Snapshot diff
128
+
129
+ ```bash
130
+ dbsnap save before
131
+ # Make your development changes.
132
+ dbsnap save after
133
+ dbsnap diff before after
134
+ ```
135
+
136
+ Diff compares **snapshots**, not the current live database. SQLite compares
137
+ schema objects and row counts. PostgreSQL clone diff compares table/view
138
+ definitions and row counts. MySQL/MariaDB diff reads verified standard dumps
139
+ offline, including multiline `INSERT` data, and compares table definitions
140
+ and row counts. It does not replay SQL into the target.
141
+
142
+ Equal row counts do not mean equal data. Individual row contents are not
143
+ compared. PostgreSQL diff excludes indexes, constraints, routines and triggers;
144
+ MySQL/MariaDB diff excludes views, routines, triggers and events. Unsupported
145
+ INSERT formats produce an error. PostgreSQL dump archives are not supported.
146
+
147
+ ## Recovering an interrupted MySQL/MariaDB restore
148
+
149
+ A fresh restore creates, syncs and catalogs a pinned safety snapshot before
150
+ cleanup. It preserves the database itself and replaces objects inside it.
151
+ `--no-safety-snapshot` is rejected for fresh MySQL/MariaDB restores.
152
+
153
+ If restore fails after the recovery journal is written:
154
+
155
+ 1. Keep application writers/connections and scheduled events stopped.
156
+ 2. Fix the reported disk-space, connection or privilege problem. Local free
157
+ space checks do not measure the database server's storage.
158
+ 3. Read the recovery ID in the error or `.dbsnap/mysql-restore.json`, then run:
159
+
160
+ ```bash
161
+ dbsnap restore RECOVERY_ID
162
+ ```
163
+
164
+ The journal stores the recovery ID as a JSON string. Other restore IDs and
165
+ unpinning are refused while recovery is pending. Recovery uses the existing
166
+ pinned snapshot; it does not snapshot the partially restored target.
167
+ If the journal is malformed or the recovery copy is missing/corrupt, preserve
168
+ the files and investigate. Do not delete the journal to bypass recovery.
169
+
170
+ After success, safety snapshots remain pinned until you review and explicitly
171
+ unpin them. Restore remains non-atomic and requires trusted dumps; preflight
172
+ checks do not prevent another application from reconnecting during replay.
173
+
101
174
  ## Database requirements
102
175
 
103
176
  | Database | Snapshot method | Requirements |
@@ -110,6 +183,9 @@ PostgreSQL server-side clones are stored on the database server. Use dump mode
110
183
  when the snapshot needs to survive removal of that server's data volume.
111
184
  For dump save and restore, install `pg_dump` and `pg_restore` matching the
112
185
  PostgreSQL server's major version. Mismatched tools are rejected before restore.
186
+ The SQLite database file must already exist. MySQL/MariaDB snapshots retain
187
+ routines, triggers and events, although diff does not compare those objects.
188
+ Snapshot runtime and connection disruption depend on the engine and data size.
113
189
 
114
190
  ## Safety
115
191
 
@@ -118,11 +194,16 @@ PostgreSQL server's major version. Mismatched tools are rejected before restore.
118
194
  - Project binding checks that the current target matches the recorded database.
119
195
  - Restore checks SQLite chunks and dump artifacts before applying them and, by default,
120
196
  creates a safety snapshot first. If that snapshot cannot be created, restore
121
- stops; the CLI has an explicit option to skip it.
197
+ stops. Only SQLite/PostgreSQL allow explicit opt-out; fresh MySQL/MariaDB
198
+ restores require a pinned safety snapshot.
122
199
  - A PostgreSQL server-side clone has a metadata fingerprint, not a content
123
200
  checksum. dbsnap checks that the clone exists before restore.
124
201
  - PostgreSQL restore is not atomic; an interruption can require manual
125
202
  recovery. Clone and staged dump restores journal their cutover.
203
+ - MySQL restore is in-place and non-atomic. Stop writers/events first. Visible
204
+ target connections and enabled events cause refusal before cleanup; this is
205
+ not a fence against future connections. Keep the pinned snapshot and recovery
206
+ journal if replay fails, including when server storage is full.
126
207
  - PostgreSQL network connections require verified TLS. Set `DBSNAP_PG_CA_CERT`
127
208
  to a trusted CA PEM file if needed; use `DBSNAP_PG_TLS=verify-full` to require
128
209
  TLS on loopback connections as well.
@@ -134,6 +215,8 @@ data you cannot afford to lose.
134
215
 
135
216
  - [Repository and full documentation](https://github.com/farhan0431/db-snap)
136
217
  - [MCP installation guide](https://github.com/farhan0431/db-snap/blob/main/INSTALL.md)
218
+ - [Testing and audit coverage](https://github.com/farhan0431/db-snap/blob/main/docs/TESTING.md)
219
+ - [MySQL recovery](https://github.com/farhan0431/db-snap/blob/main/docs/MYSQL-RESTORE.md)
137
220
  - [Report an issue](https://github.com/farhan0431/db-snap/issues)
138
221
 
139
222
  MIT license.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@farhan0431/db-snap",
3
- "version": "0.3.11",
4
- "description": "Instant physical database time-machine and MCP server for AI coding agents — git commit/checkout for your local database, powered by Rust.",
3
+ "version": "0.3.14",
4
+ "description": "Development database snapshots and MCP server for SQLite, PostgreSQL, and MySQL/MariaDB.",
5
5
  "license": "MIT",
6
6
  "bin": {
7
7
  "dbsnap": "bin/dbsnap.js"