Skip to content

fix: optimistic locking for docs editor (prevent edit conflicts)#22

Merged
AngryJay91 merged 2 commits intomainfrom
fix/issue-15-edit-conflict
Mar 31, 2026
Merged

fix: optimistic locking for docs editor (prevent edit conflicts)#22
AngryJay91 merged 2 commits intomainfrom
fix/issue-15-edit-conflict

Conversation

@AngryJay91
Copy link
Copy Markdown
Owner

Summary

Closes #15

Adds version-based optimistic locking to the docs editor to prevent silent data loss when multiple users edit the same document simultaneously.

Changes

scaffold/pm-api/sql/009-doc-versioning.sql (new)

  • Adds version INTEGER DEFAULT 1 column to the docs table

scaffold/pm-api/src/routes/v2-docs.ts

  • GET /:id: now returns version field in doc response
  • PUT /:id: accepts optional version in request body
    • New doc (INSERT): sets version = 1
    • Existing doc (UPDATE): checks WHERE version = ?, increments on success
    • Returns 409 Conflict with code: 'VERSION_CONFLICT' if version mismatch
    • Legacy clients (no version sent): graceful degradation, skips conflict check

scaffold/spec-site/src/pages/DocsEditor.vue

  • Reads version from GET response and stores locally
  • Sends version with every PUT save request
  • On 409: shows amber warning banner ("Someone else edited this document...")
  • On success: updates local version from server response

Behavior

User A loads doc (version=3)
User B loads doc (version=3) 
User B saves → version becomes 4
User A saves with version=3 → WHERE version=3 matches 0 rows → 409
User A sees: "Someone else edited this document while you were working..."

- Migration 009: ADD COLUMN version INTEGER DEFAULT 1 to docs table
- PUT /api/v2/docs/:id: checks client version against DB, returns 409 if mismatch
- GET /api/v2/docs/:id: returns version field in response
- DocsEditor.vue: sends version on save, shows conflict warning on 409

Closes #15
@AngryJay91 AngryJay91 merged commit 89c0298 into main Mar 31, 2026
2 checks passed
@AngryJay91 AngryJay91 deleted the fix/issue-15-edit-conflict branch March 31, 2026 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2-3: Docs 실시간 편집 충돌 방어

1 participant