milestone 2 complete
This commit is contained in:
@ -108,7 +108,7 @@ func (r *OnyxRepository) Init(path string) error {
|
||||
// Initialize workstreams.json
|
||||
workstreamsPath := filepath.Join(onyxPath, "workstreams.json")
|
||||
if _, err := os.Stat(workstreamsPath); os.IsNotExist(err) {
|
||||
initialContent := []byte("{\"workstreams\":[]}\n")
|
||||
initialContent := []byte("{\"workstreams\":{}}\n")
|
||||
if err := os.WriteFile(workstreamsPath, initialContent, 0644); err != nil {
|
||||
return fmt.Errorf("failed to create workstreams.json: %w", err)
|
||||
}
|
||||
|
@ -155,6 +155,25 @@ func (t *Transaction) Rollback(entryID uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Commit captures the final state and writes to oplog
|
||||
func (t *Transaction) Commit(operation, description string) error {
|
||||
// Capture state_after
|
||||
stateAfter, err := t.stateCapture.CaptureState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to capture state: %w", err)
|
||||
}
|
||||
|
||||
// Create oplog entry
|
||||
entry := models.NewOplogEntry(0, operation, description, nil, stateAfter)
|
||||
|
||||
// Write to oplog
|
||||
if err := t.oplogWriter.AppendEntry(entry); err != nil {
|
||||
return fmt.Errorf("failed to write to oplog: %w", err)
|
||||
}
|
||||
|
||||
return t.Close()
|
||||
}
|
||||
|
||||
// Helper function to execute a transaction on a repository
|
||||
func ExecuteWithTransaction(repo *OnyxRepository, operation, description string, fn func() error) error {
|
||||
txn, err := NewTransaction(repo)
|
||||
|
Reference in New Issue
Block a user