@@ -193,33 +193,114 @@ Notes:
193193Snapshots capture database state for reproducible regression testing. Build a
194194snapshot from schema + migrations + fixtures, then restore it before testing.
195195
196- ** NOTICE** : Snapshot functionality is work in progress.
196+ ### Snapshot-Based Workflow (Recommended)
197+
198+ ``` yaml
199+ # regresql/regress.yaml
200+ pguri : postgres://user:pass@localhost/mydb
201+ snapshot :
202+ schema : db/schema.sql
203+ migrations : db/migrations/pending/
204+ fixtures :
205+ - users
206+ - products
207+ ` ` `
197208
198209` ` ` bash
199- # Capture current database state
200- regresql snapshot capture
210+ regresql snapshot build # Creates snapshots/default.dump
211+ regresql test # Validates hashes, runs tests
212+ ```
201213
202- # Capture schema only (git-friendly SQL format)
203- regresql snapshot capture --schema-only --format plain -o snapshots/schema.sql
214+ ### Schema Sources
204215
205- # Build snapshot from fixtures
206- regresql snapshot build --fixtures users,products,orders
216+ ** Plain SQL file:**
217+ ``` yaml
218+ snapshot :
219+ schema : db/schema.sql
220+ ` ` `
207221
208- # Restore snapshot before testing
209- regresql snapshot restore
222+ **pg_dump custom format:**
223+ ` ` ` yaml
224+ snapshot :
225+ schema : snapshots/schema.dump
226+ ` ` `
227+
228+ **pg_dump directory format:**
229+ ` ` ` yaml
230+ snapshot :
231+ schema : snapshots/schema_dir/
210232` ` `
211233
212- Snapshots are stored using pg_dump and can be configured in ` regresql/regress.yaml ` :
234+ ### Migrations
235+
236+ **SQL files in directory** (sorted lexically, ` *.down.sql` skipped):
237+ ` ` ` yaml
238+ snapshot:
239+ migrations: db/migrations/pending/
240+ ` ` `
241+
242+ **External migration tool:**
243+ ` ` ` yaml
244+ snapshot:
245+ migration_command: goose -dir db/migrations postgres "$PGURI" up
246+ ` ` `
247+
248+ Environment variables `PGURI` and `DATABASE_URL` are set to the temp database URI.
249+
250+ ` migrations` and `migration_command` are mutually exclusive.
251+
252+ # ## Change Detection
253+
254+ On `regresql test`, these are validated against snapshot metadata :
255+ - Schema file hash
256+ - Migrations directory hash (includes filenames and content)
257+ - Migration command string hash
258+
259+ If changed, test fails with instructions to rebuild :
260+
261+ ` ` `
262+ Error: schema has changed since last snapshot build
263+
264+ Schema file: db/schema.sql
265+ Expected: sha256:abc123...
266+ Current: sha256:789xyz...
267+
268+ Run 'regresql snapshot build' to rebuild the snapshot
269+ ` ` `
270+
271+ # ## Snapshot Commands
272+
273+ ` ` ` bash
274+ regresql snapshot build [flags] # Build from schema/migrations/fixtures
275+ regresql snapshot capture [flags] # Capture current database state
276+ regresql snapshot restore [flags] # Restore snapshot to database
277+ regresql snapshot info # Show snapshot metadata and hashes
278+ ` ` `
279+
280+ **Build flags:**
281+ - ` --schema FILE` - Schema file (overrides config)
282+ - ` --migrations DIR` - Migrations directory (overrides config)
283+ - ` --fixtures LIST` - Comma-separated fixture names
284+ - `--output FILE` - Output path (default : snapshots/default.dump)
285+ - `--format FORMAT` - custom, plain, directory (default : custom)
286+ - ` -v, --verbose` - Show detailed progress
287+
288+ **Capture flags:**
289+ - ` --schema-only` - Dump schema without data
290+ - ` --sections` - Capture pre-data, data, post-data as separate SQL files
291+ - ` --format FORMAT` - custom, plain, directory
292+
293+ # ## Configuration
213294
214295` ` ` yaml
215- pguri : " postgres://..."
216296snapshot:
217- path : snapshots/test_data.dump
218- format : custom # custom, plain, or directory
219- fixtures : # for snapshot build command
297+ path: snapshots/default.dump # Output path
298+ format: custom # custom, plain, directory
299+ schema: db/schema.sql # Schema source
300+ migrations: db/migrations/ # OR migration_command
301+ fixtures:
220302 - users
221303 - products
222- - orders
223304` ` `
224305
225306# # Test Fixtures
0 commit comments