@@ -69,6 +69,31 @@ There are several benefits over [using sqlite3 .dump directly](https://garrit.xy
6969
7070Git will automatically convert SQLite files to SQL text for storage and back to binary when checked out.
7171
72+ # # Quick Start: Schema/Data Separation
73+
74+ For cleaner diffs that only show data changes, use the schema/data separation feature:
75+
76+ 1. ** Configure Git filters for data-only mode** :
77+ ` ` ` bash
78+ echo ' *.db filter=gitsqlite-data' >> .gitattributes
79+ git config filter.gitsqlite-data.clean " gitsqlite -data-only -schema-output .gitsqliteschema clean"
80+ git config filter.gitsqlite-data.smudge " gitsqlite -schema-file .gitsqliteschema smudge"
81+ ` ` `
82+
83+ 2. ** Add schema file to Git** :
84+ ` ` ` bash
85+ git add .gitsqliteschema
86+ git commit -m " Add database schema"
87+ ` ` `
88+
89+ 3. ** Version your database** :
90+ ` ` ` bash
91+ git add mydb.db
92+ git commit -m " Add database data"
93+ ` ` `
94+
95+ Git will now store only data changes in the database file, while schema is managed separately. This results in much cleaner diffs that only show INSERT operations.
96+
7297# # Quick Start Git Diff
7398
7499To enable SQL-based diffs for SQLite databases in Git, add the following to your repository' s `.gitattributes` and configure your Git diff driver: (It doesn' t matter if it is stored as binary or via smudge/clean.)
@@ -210,6 +235,25 @@ See [CLI Parameters](#cli-parameters) for all available options.
210235 gitsqlite -help
211236 ` ` `
212237
238+ # ## Schema/Data Separation Options
239+ ** ` -data-only` ** - For clean/diff: output only data (INSERT statements), no schema
240+ ` ` ` bash
241+ gitsqlite -data-only clean < database.db > data.sql
242+ gitsqlite -data-only diff database.db > data.sql
243+ ` ` `
244+
245+ ** ` -schema-output < file> ` ** - Save schema to this file during clean/diff (default: do not save schema separately)
246+ ` ` ` bash
247+ gitsqlite -schema-output .gitsqliteschema clean < database.db > data.sql
248+ gitsqlite -schema-output schema.sql diff database.db > data.sql
249+ ` ` `
250+
251+ ** ` -schema-file < file> ` ** - For smudge: read schema from this file instead of stdin (default: " .gitsqliteschema" )
252+ ` ` ` bash
253+ gitsqlite -schema-file .gitsqliteschema smudge < data.sql > database.db
254+ gitsqlite -schema-file custom_schema.sql smudge < data.sql > database.db
255+ ` ` `
256+
213257# # Examples
214258
215259# ## Quick Start Example
@@ -257,6 +301,47 @@ gitsqlite smudge < sample.sql > restored.db
257301sqlite3 restored.db " SELECT * FROM users;"
258302` ` `
259303
304+ # ## Schema/Data Separation Workflow
305+
306+ The schema/data separation feature allows you to store database schema and data separately for cleaner Git workflows and easier diff viewing.
307+
308+ 1. ** Separate schema and data during clean:**
309+ ` ` ` bash
310+ # Extract data-only (INSERT statements) and save schema to separate file
311+ gitsqlite -data-only -schema-output .gitsqliteschema clean < database.db > data.sql
312+ ` ` `
313+
314+ 2. ** View the separated files:**
315+ ` ` ` bash
316+ # Schema file contains CREATE TABLE statements
317+ cat .gitsqliteschema
318+ # PRAGMA foreign_keys=OFF;
319+ # BEGIN TRANSACTION;
320+ # CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT);
321+ # COMMIT;
322+
323+ # Data file contains INSERT statements
324+ cat data.sql
325+ # PRAGMA foreign_keys=OFF;
326+ # BEGIN TRANSACTION;
327+ # INSERT INTO users VALUES(1,'John Doe','john@example.com');
328+ # INSERT INTO users VALUES(2,'Jane Smith','jane@example.com');
329+ # COMMIT;
330+ ` ` `
331+
332+ 3. ** Restore database from separated files:**
333+ ` ` ` bash
334+ # Combine schema and data back into database
335+ gitsqlite -schema-file .gitsqliteschema smudge < data.sql > restored.db
336+ ` ` `
337+
338+ 4. ** Benefit: Cleaner diffs that show only data changes:**
339+ ` ` ` bash
340+ # After modifying data, diff will only show INSERT/UPDATE/DELETE changes
341+ gitsqlite -data-only clean < modified.db > modified_data.sql
342+ diff data.sql modified_data.sql
343+ ` ` `
344+
260345# ## Advanced Usage Examples
261346
262347** With custom SQLite path:**
0 commit comments