Commit graph

29 commits

Author SHA1 Message Date
Johannes Millan
be4b8ba241 fix(migrations): ensure unique IDs and prevent data loss in split operations
When splitting one operation into misc and tasks operations:
- Both operations now get unique ID suffixes (_misc and _tasks)
- Skip logic verifies both conditions before skipping:
  1. tasks config has migrated field (isConfirmBeforeDelete)
  2. misc config has NO migrated fields remaining

This prevents:
- Potential operation ID conflicts in the sync log
- Data loss in partial migration scenarios

Adds test cases for partial migration and correct skip scenarios.
2026-01-20 17:07:23 +01:00
Ivan Kalashnikov
1987292433 refactor: streamline migration logic and enhance field mapping for settings 2026-01-19 14:38:42 +07:00
Ivan Kalashnikov
800ba30f4f refactor: rename misc to tasks settings migration file and object. 2026-01-19 14:30:42 +07:00
Ivan Kalashnikov
356278fc87 feat: enhance migration tests for settings and operations handling 2026-01-19 14:21:09 +07:00
Ivan Kalashnikov
218e74f882 feat: implement migration of settings from misc to tasks with operation handling 2026-01-19 14:19:31 +07:00
Ivan Kalashnikov
263495b8cd feat: update migration functions to support splitting operations into multiple results 2026-01-19 13:58:27 +07:00
Ivan Kalashnikov
b3da4e4850 fix: update CURRENT_SCHEMA_VERSION to 2 for upcoming migration 2026-01-19 13:16:48 +07:00
Ivan Kalashnikov
5002bae1c0 fix: add todo comment to bump CURRENT_SCHEMA_VERSION for upcoming migration 2026-01-19 01:09:00 +07:00
Ivan Kalashnikov
325e24f461 fix: revert CURRENT_SCHEMA_VERSION to 1 2026-01-19 00:03:33 +07:00
Ivan Kalashnikov
6705033d15 feat: implement migration to move settings from MiscConfig to TasksConfig 2026-01-18 23:31:06 +07:00
Ivan Kalashnikov
2473b9698d fix: update migration test to correctly structure migrated state with globalConfig 2026-01-18 23:30:57 +07:00
Ivan Kalashnikov
d6506e95d1 refactor: rename test spec migration in format 'v1 to v2' 2026-01-18 23:18:42 +07:00
Ivan Kalashnikov
651d5dc183 feat: add migration to move settings from MiscConfig to TasksConfig as separate file 2026-01-18 23:08:30 +07:00
Ivan Kalashnikov
f2940fd7ae fix: remove outdated todo comment regarding schema version synchronization 2026-01-18 23:07:12 +07:00
Ivan Kalashnikov
0d6d17c103 fix: correct task confirmation field name in migration test 2026-01-18 23:06:37 +07:00
Ivan Kalashnikov
5f4e1cf24e fix: correct task migration field names and add markdown formatting flag 2026-01-18 21:54:24 +07:00
Ivan Kalashnikov
73c9c05c32 refactor: rename task settings field 2026-01-18 21:53:16 +07:00
Ivan Kalashnikov
a617ff4e29 fix: update MiscConfig to mark isTurnOffMarkdown as deprecated 2026-01-18 21:50:11 +07:00
Ivan Kalashnikov
bd2615e7d7 fix: update migration versions from 16 to 1 and 17 to 2 for consistency 2026-01-18 21:28:43 +07:00
Ivan Kalashnikov
088971d22b refactor: update validateMigrationRegistry test comments for clarity 2026-01-18 21:14:22 +07:00
Ivan Kalashnikov
aedab573a0 test: add migration tests for moving settings from MiscConfig to TasksConfig 2026-01-18 21:10:05 +07:00
Ivan Kalashnikov
92d7d4aafe fix: update CURRENT_SCHEMA_VERSION to 17 for new migrations 2026-01-18 21:08:31 +07:00
Ivan Kalashnikov
b565173664 feat: add migration to move settings from MiscConfig to TasksConfig 2026-01-18 21:08:19 +07:00
Johannes Millan
23579a448a fix(shared-schema): use tsup for dual ESM/CJS build
The previous commit changed module resolution to bundler mode which
fixed Angular tests but broke Node.js ESM imports in super-sync-server.

Switch to tsup bundler that outputs both ESM (.mjs) and CJS (.js) formats,
with proper exports field to support both environments:
- CJS for super-sync-server (Node.js commonjs)
- ESM for Angular/webpack bundler imports
2026-01-11 14:05:23 +01:00
Johannes Millan
bc869d359f fix(shared-schema): fix module resolution for bundler compatibility
- Change shared-schema tsconfig to use bundler moduleResolution
- Remove .js extensions from imports (incompatible with bundler mode)
- Fix tsconfig.spec.json to include both package path mappings

The shared-schema package was using NodeNext module resolution which
requires .js extensions in imports. Since the main Angular project
uses bundler resolution and imports directly from source files,
this caused webpack to fail finding the modules during tests.
2026-01-11 13:20:16 +01:00
Johannes Millan
cbeecfd39a fix(sync): multi-tab vector clock staleness + shared code extraction
Bug fix:
- Fix vector clock cache staleness in multi-tab scenarios by clearing
  cache when acquiring operation write lock. Each browser tab has its
  own in-memory cache, so Tab B's cache could be stale if Tab A wrote
  while Tab B was waiting for the lock.

Shared code extraction (client/server consistency):
- Extract vector clock comparison to @sp/shared-schema
  - Client wraps shared impl with null handling
  - Server imports directly from shared
- Extract entity types to @sp/shared-schema
  - Single source of truth for ENTITY_TYPES array
  - Removes duplicated "must match" comments

Files:
- packages/shared-schema/src/vector-clock.ts (new)
- packages/shared-schema/src/entity-types.ts (new)
- src/app/op-log/store/operation-log-store.service.ts (cache clear)
- src/app/op-log/capture/operation-log.effects.ts (call cache clear)
2026-01-03 18:05:11 +01:00
Johannes Millan
a0965fee60 docs(sync): improve OperationLike interface documentation
Explain why OperationLike uses primitives instead of the main app's
Operation type: package isolation, portability, and stability.
2025-12-12 20:48:12 +01:00
Johannes Millan
615188bf88 fix: address code review findings from last 24 hours
1. Fix race condition in replaceToken (auth.ts)
   - Wrap UPDATE and SELECT in transaction for atomicity

2. Fix mutex memory leak in operation-log-hydrator
   - Add explicit error logging before rethrowing in repair promise

3. Improve global mutable state handling (is-related-model-data-valid.ts)
   - Reset lastValidityError at start of each validation
   - Add documentation warning about the pattern

4. Fix version tracking bug in shared-schema migration
   - Update version inside try block so migratedToVersion reflects
     where we actually stopped, even if operation was dropped

5. Remove unused import validateMigrationRegistry (sync.service.ts)

6. Add array payload rejection test (validate-operation-payload.spec.ts)

7. Add lock service contention tests (lock.service.spec.ts)
   - Tests for corrupted lock formats (no timestamp, NaN, empty string)

Also includes shared-schema ESM configuration:
- Add "type": "module" to package.json for ESM output
- Change module/moduleResolution to NodeNext in tsconfig.json
- Add .js extensions to all relative imports (required by Node.js ESM)
2025-12-12 20:47:47 +01:00
Johannes Millan
8dc8207da2 feat(sync): add shared schema versioning package for frontend/backend
Create @sp/shared-schema package with pure TypeScript migration functions
that work in both Angular frontend and Node.js backend environments.

Package contents:
- schema-version.ts: Version constants (CURRENT=1, MAX_SKIP=3)
- migration.types.ts: OperationLike, SchemaMigration interfaces
- migrate.ts: Pure functions (migrateState, migrateOperation, etc.)
- migrations/index.ts: Empty migrations array (ready for first migration)
- 22 unit tests covering all migration scenarios

Backend changes:
- Add snapshot_schema_version column to user_sync_state table
- Migrate snapshots during generateSnapshot if outdated
- Migrate operations during replayOpsToState if outdated
- Drop operations that return null from migration (removed features)

Frontend changes:
- Refactor SchemaMigrationService to use @sp/shared-schema
- Re-export constants for backwards compatibility
- All 20 existing tests pass

This enables coordinated schema migrations across client and server,
ensuring old snapshots and operations can be upgraded when the state
structure changes.

Rollout strategy: Deploy backend first, then frontend.
2025-12-12 20:47:44 +01:00