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.
This commit is contained in:
Johannes Millan 2025-12-06 11:21:16 +01:00
parent dcdba9e4e5
commit 8dc8207da2
15 changed files with 977 additions and 183 deletions

View file

@ -23,7 +23,8 @@
"typeRoots": ["node_modules/@types"],
"lib": ["es2022", "dom"],
"paths": {
"@super-productivity/plugin-api": ["packages/plugin-api/src/index.ts"]
"@super-productivity/plugin-api": ["packages/plugin-api/src/index.ts"],
"@sp/shared-schema": ["packages/shared-schema/src/index.ts"]
},
"plugins": [
{