Skip to content

[Sync Framework] Migrate scenario-tracker to sync framework (plain objects → svelte-idb) #28

Description

@Michael-Obele

Overview

Migrate scenario-tracker to the centralized sync framework. This migration tests converting from plain objects (no PersistedState) to svelte-idb, and uses the ManualTrigger with imperative server calls.

Design doc: docs/plans/2026-06-21-sync-framework-design.md

Current state

  • src/routes/apps/(app)/scenario-tracker/+page.svelte — imperative server calls, manual getScenarioData() refresh after each mutation, 15+ individual mutation functions
  • src/routes/apps/(app)/scenario-tracker/stores.svelte.tsplain objects (not PersistedState!) — options, timelineEntries, risks with .current property
  • src/lib/remote/scenario-tracker.remote.tsgetScenarioData (query), 15+ individual command functions (addScenarioOptions, deleteScenarioOption, addScenarioActivity, etc.)

Migration steps

  • Create app DB with createReactiveDB:
    const db = createReactiveDB({
      name: 'scenario-tracker',
      version: 1,
      stores: {
        settings: { keyPath: 'id' },
        options: { keyPath: 'id' },
        activities: { keyPath: 'id' },
        timelineEntries: { keyPath: 'id' },
        risks: { keyPath: 'id' },
      },
    });
  • Replace plain object stores with db.store.liveAll() for each
  • Migrate scenario-tracker.remote.ts:
    • createLoadQuery for getScenarioData (loads all stores)
    • Keep individual mutation commands (addScenarioOptions, etc.) — these are the primary interaction
    • Add createBackupForm + createBackupCommand for full backup
  • Create SyncManager with manual trigger:
    strategy: serverWins,
    trigger: 'manual',
  • Update +page.svelte — use sync.syncOnMount(data), keep imperative mutation calls
  • Convert stores.svelte.tsstates.svelte.ts (rename to match project convention)
  • Run bun check + svelte-autofixer
  • Test imperative mutations + manual sync

What stays app-specific

  • 15+ individual mutation commands (granular CRUD per entity type)
  • Data types (ScenarioSettings, ScenarioOption, ScenarioActivity, ScenarioTimelineEntry, ScenarioRisk)
  • serverWins merge strategy

Prisma models (existing)

  • ScenarioSettings → store settings
  • ScenarioOption → store options
  • ScenarioActivity → store activities (nested in options)
  • ScenarioTimelineEntry → store timelineEntries
  • ScenarioRisk → store risks

Blocked by

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions