stackConsult commited on
Commit
cc10b69
·
verified ·
1 Parent(s): 3a67095

Add comprehensive schema versioning and rollback documentation

Browse files

Complete schema version control system documentation including:

- Schema v1.0 definition with all required fields
- Detailed version history tracking
- Git-based rollback procedures (soft, hard, file-specific)
- Commit tracking system (request_id, commit_hash)
- Build-specific rollback for dev/staging/production
- Pre/post validation procedures
- Error recovery protocols
- Schema change tracking format
- Testing checklist
- Quick reference commands

This documentation ensures reliable version control, data integrity, and seamless rollback capability for all future schema modifications across different build environments.

Files changed (1) hide show
  1. SCHEMA_VERSIONING.md +402 -0
SCHEMA_VERSIONING.md ADDED
@@ -0,0 +1,402 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Schema Versioning and Rollback Documentation
2
+
3
+ ## Overview
4
+
5
+ This document establishes the schema versioning strategy and rollback procedures for the activity logging system. It ensures data integrity, backward compatibility, and reliable version control for production deployments.
6
+
7
+ ---
8
+
9
+ ## Current Schema Version: 1.0
10
+
11
+ ### Schema Definition (v1.0)
12
+
13
+ **File:** `activity_log.csv`
14
+ **Created:** 2025-11-05T10:51:00Z
15
+ **Commit Hash:** 3a67095
16
+
17
+ #### Required Fields
18
+
19
+ | Field | Type | Description | Validation |
20
+ |-------|------|-------------|------------|
21
+ | `timestamp` | ISO 8601 String | UTC timestamp of activity | Must be valid ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ) |
22
+ | `agent_id` | String | Identifier of the agent performing activity | Non-empty string |
23
+ | `activity_type` | Enum | Type of activity performed | Must be one of: `init`, `validate`, `ingest`, `update`, `delete`, `query`, `commit`, `rollback` |
24
+ | `entity_id` | String | Identifier of entity being acted upon | Non-empty string |
25
+ | `status` | Enum | Outcome status of activity | Must be one of: `created`, `success`, `failed`, `in_progress`, `warning`, `error` |
26
+ | `notes` | String | Human-readable description | Non-empty string |
27
+ | `context` | String | Additional context or metadata | Non-empty string |
28
+
29
+ #### CSV Format
30
+ ```csv
31
+ timestamp,agent_id,activity_type,entity_id,status,notes,context
32
+ 2025-11-05T10:51:00Z,comet_assistant,init,activity_log_schema,created,"Canonical CSV schema for activity tracking established","Step 1: Schema and CSV Foundation - initial setup"
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Version History
38
+
39
+ ### Version 1.0 (Current)
40
+ **Date:** 2025-11-05
41
+ **Commit:** 3a67095
42
+ **Status:** Active
43
+
44
+ **Changes:**
45
+ - Initial schema establishment
46
+ - 7 required fields defined
47
+ - Atomic ingestion function implemented
48
+ - Schema validation with error handling
49
+ - Request ID and commit hash tracking
50
+
51
+ **Files:**
52
+ - `activity_log.csv` - Data storage
53
+ - `activity_ingestion.py` - Ingestion function with validation
54
+ - `SCHEMA_VERSIONING.md` - This documentation
55
+
56
+ **Migration:** N/A (initial version)
57
+
58
+ ---
59
+
60
+ ## Rollback Procedures
61
+
62
+ ### Git-Based Rollback
63
+
64
+ All schema changes and data are tracked via Git commits. To roll back to a previous version:
65
+
66
+ #### 1. Identify Target Commit
67
+
68
+ ```bash
69
+ # View commit history
70
+ git log --oneline activity_log.csv activity_ingestion.py
71
+
72
+ # Example output:
73
+ # 3a67095 Implement atomic activity ingestion with schema validation
74
+ # b1a2c3d Initial activity_log.csv setup
75
+ ```
76
+
77
+ #### 2. Rollback Commands
78
+
79
+ **Option A: Soft Rollback (Review changes before commit)**
80
+ ```bash
81
+ # Reset to previous commit (keeps changes in working directory)
82
+ git checkout <commit-hash> -- activity_log.csv activity_ingestion.py
83
+ git commit -m "Rollback to schema version X.X (commit <commit-hash>)"
84
+ ```
85
+
86
+ **Option B: Hard Rollback (Direct revert)**
87
+ ```bash
88
+ # Revert to specific commit
89
+ git revert <commit-hash>
90
+ ```
91
+
92
+ **Option C: File-Specific Rollback**
93
+ ```bash
94
+ # Rollback only the CSV data file
95
+ git checkout <commit-hash> -- activity_log.csv
96
+ git commit -m "Rollback activity_log.csv to <commit-hash>"
97
+ ```
98
+
99
+ #### 3. Verify Rollback
100
+
101
+ ```bash
102
+ # Check current schema version
103
+ grep "SCHEMA_VERSION" activity_ingestion.py
104
+
105
+ # Validate CSV structure
106
+ head -n 5 activity_log.csv
107
+
108
+ # Run validation tests
109
+ python activity_ingestion.py
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Schema Change Tracking
115
+
116
+ ### Change Log Format
117
+
118
+ Every schema modification MUST be logged using this structure:
119
+
120
+ ```markdown
121
+ ### Version X.Y (Status: Active/Deprecated)
122
+ **Date:** YYYY-MM-DD
123
+ **Commit:** <git-commit-hash>
124
+ **Status:** Active | Deprecated | Archived
125
+
126
+ **Changes:**
127
+ - [ADD] New field: `field_name` (type, description)
128
+ - [MODIFY] Changed field: `field_name` (old -> new behavior)
129
+ - [REMOVE] Deprecated field: `field_name` (reason)
130
+ - [BREAKING] Breaking change description
131
+
132
+ **Migration:**
133
+ - Step 1: Migration instructions
134
+ - Step 2: Validation procedures
135
+
136
+ **Rollback Instructions:**
137
+ - Specific rollback notes if different from standard procedure
138
+ ```
139
+
140
+ ### Schema Version Numbering
141
+
142
+ - **Major Version (X.0):** Breaking changes, incompatible with previous versions
143
+ - **Minor Version (X.Y):** New fields added, backward compatible
144
+ - **Patch Version (X.Y.Z):** Bug fixes, validation updates, no schema changes
145
+
146
+ ---
147
+
148
+ ## Commit Tracking System
149
+
150
+ ### Request ID Format
151
+
152
+ Every ingestion operation generates a unique request ID:
153
+
154
+ ```
155
+ req_<16-char-hex>
156
+
157
+ Example: req_a1b2c3d4e5f67890
158
+ ```
159
+
160
+ ### Commit Hash Generation
161
+
162
+ Pseudo-commit hashes track each row insertion:
163
+
164
+ ```python
165
+ commit_hash = SHA256(request_id + timestamp + agent_id + activity_type)[:16]
166
+ ```
167
+
168
+ Example: `3f8d2a1bc5e97604`
169
+
170
+ ### Operation Log
171
+
172
+ All operations are logged to `activity_ingestion.log`:
173
+
174
+ ```json
175
+ {
176
+ "timestamp": "2025-11-05T10:51:00Z",
177
+ "request_id": "req_a1b2c3d4e5f67890",
178
+ "operation": "ingest",
179
+ "status": "success",
180
+ "agent_id": "comet_assistant",
181
+ "activity_type": "validate",
182
+ "error": ""
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Build-Specific Rollback for Different Environments
189
+
190
+ ### Development Build
191
+
192
+ ```bash
193
+ # Tag development schema
194
+ git tag -a dev-schema-v1.0 -m "Development schema version 1.0"
195
+
196
+ # Rollback to dev version
197
+ git checkout dev-schema-v1.0 -- activity_log.csv activity_ingestion.py
198
+ ```
199
+
200
+ ### Staging Build
201
+
202
+ ```bash
203
+ # Tag staging schema
204
+ git tag -a staging-schema-v1.0 -m "Staging schema version 1.0"
205
+
206
+ # Rollback to staging version
207
+ git checkout staging-schema-v1.0 -- activity_log.csv activity_ingestion.py
208
+ ```
209
+
210
+ ### Production Build
211
+
212
+ ```bash
213
+ # Tag production schema (immutable)
214
+ git tag -a prod-schema-v1.0 -m "Production schema version 1.0" -s
215
+
216
+ # Rollback to production version
217
+ git checkout prod-schema-v1.0 -- activity_log.csv activity_ingestion.py
218
+
219
+ # Verify integrity
220
+ git verify-tag prod-schema-v1.0
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Validation Procedures
226
+
227
+ ### Pre-Commit Validation
228
+
229
+ Before committing any schema changes:
230
+
231
+ 1. **Run Schema Validation Tests**
232
+ ```bash
233
+ python activity_ingestion.py
234
+ ```
235
+
236
+ 2. **Check CSV Integrity**
237
+ ```bash
238
+ # Verify header
239
+ head -n 1 activity_log.csv
240
+
241
+ # Count rows
242
+ wc -l activity_log.csv
243
+
244
+ # Check for malformed rows
245
+ awk -F',' 'NF!=7 {print NR, $0}' activity_log.csv
246
+ ```
247
+
248
+ 3. **Validate Timestamp Format**
249
+ ```bash
250
+ # Extract and validate timestamps
251
+ cut -d',' -f1 activity_log.csv | tail -n +2 | while read ts; do
252
+ date -d "$ts" > /dev/null 2>&1 || echo "Invalid: $ts"
253
+ done
254
+ ```
255
+
256
+ ### Post-Rollback Validation
257
+
258
+ After performing a rollback:
259
+
260
+ 1. Verify schema version matches expected version
261
+ 2. Run full test suite: `python activity_ingestion.py`
262
+ 3. Check operation logs for errors
263
+ 4. Validate data integrity with sample queries
264
+ 5. Document rollback in change log
265
+
266
+ ---
267
+
268
+ ## Error Recovery
269
+
270
+ ### Corrupted CSV File
271
+
272
+ ```bash
273
+ # Restore from last good commit
274
+ git checkout HEAD~1 -- activity_log.csv
275
+
276
+ # Or restore from specific commit
277
+ git checkout <commit-hash> -- activity_log.csv
278
+
279
+ # Verify restoration
280
+ python activity_ingestion.py
281
+ ```
282
+
283
+ ### Failed Schema Migration
284
+
285
+ ```bash
286
+ # Immediate rollback
287
+ git reset --hard HEAD~1
288
+
289
+ # Or targeted rollback
290
+ git checkout HEAD~1 -- activity_ingestion.py SCHEMA_VERSIONING.md
291
+
292
+ # Document failure
293
+ echo "Migration failed: <reason>" >> SCHEMA_VERSIONING.md
294
+ git commit -m "Rollback failed migration - <reason>"
295
+ ```
296
+
297
+ ### Atomic Operation Failure
298
+
299
+ The `atomic_append_activity()` function handles failures automatically:
300
+
301
+ - **Schema Validation Error:** Returns error, no file modification
302
+ - **Write Lock Error:** Returns error, temp file cleaned up
303
+ - **Partial Write:** Temp file discarded, original file unchanged
304
+
305
+ All errors logged to `activity_ingestion.log` with request_id for tracing.
306
+
307
+ ---
308
+
309
+ ## Best Practices
310
+
311
+ ### Schema Changes
312
+
313
+ 1. **Always increment version number** when modifying schema
314
+ 2. **Document all changes** in this file before committing
315
+ 3. **Create migration scripts** for breaking changes
316
+ 4. **Test thoroughly** in development before staging/production
317
+ 5. **Tag releases** with semantic versioning
318
+
319
+ ### Commit Messages
320
+
321
+ ```
322
+ [Schema v1.1] Add new field: priority_level
323
+
324
+ - Added 'priority_level' field (enum: low, medium, high)
325
+ - Updated validation function
326
+ - Backward compatible with v1.0
327
+ - Migration: existing records default to 'medium'
328
+ ```
329
+
330
+ ### Data Backup
331
+
332
+ ```bash
333
+ # Before major changes, create backup
334
+ cp activity_log.csv activity_log_backup_$(date +%Y%m%d).csv
335
+
336
+ # Commit backup to repo
337
+ git add activity_log_backup_*.csv
338
+ git commit -m "Backup before schema v1.1 migration"
339
+ ```
340
+
341
+ ---
342
+
343
+ ## Testing Checklist
344
+
345
+ Before deploying any schema changes:
346
+
347
+ - [ ] Schema version updated in code
348
+ - [ ] Validation rules updated
349
+ - [ ] Test suite passes all cases
350
+ - [ ] Documentation updated
351
+ - [ ] Migration script created (if needed)
352
+ - [ ] Rollback procedure documented
353
+ - [ ] Staging deployment successful
354
+ - [ ] Production backup created
355
+ - [ ] Git tag created
356
+
357
+ ---
358
+
359
+ ## Contact & Support
360
+
361
+ For schema change requests or rollback assistance:
362
+
363
+ - **Repository:** huggingface.co/spaces/StrategyStack/README
364
+ - **Schema Owner:** comet_assistant
365
+ - **Last Updated:** 2025-11-05
366
+
367
+ ---
368
+
369
+ ## Appendix: Quick Reference
370
+
371
+ ### Current Version Info
372
+ ```bash
373
+ # Check schema version
374
+ grep SCHEMA_VERSION activity_ingestion.py
375
+
376
+ # View recent commits
377
+ git log -5 --oneline
378
+
379
+ # List all schema tags
380
+ git tag -l '*schema*'
381
+ ```
382
+
383
+ ### Emergency Rollback (One-Liner)
384
+ ```bash
385
+ # Rollback everything to previous commit
386
+ git reset --hard HEAD~1 && python activity_ingestion.py
387
+ ```
388
+
389
+ ### Validate Current State
390
+ ```bash
391
+ # Full validation
392
+ python activity_ingestion.py && \
393
+ awk -F',' 'NF!=7 {print "ERROR: Line", NR}' activity_log.csv && \
394
+ echo "Validation complete"
395
+ ```
396
+
397
+ ---
398
+
399
+ **Document Version:** 1.0
400
+ **Last Modified:** 2025-11-05
401
+ **Schema Version:** 1.0
402
+ **Status:** Active