Skip to content

Data Refactor Phase 1: Add accountId to transactions with automatic migration#61

Merged
jwaspin merged 2 commits intomainfrom
copilot/fix-16763697-596c-430d-b61e-46cc3642f666
Oct 6, 2025
Merged

Data Refactor Phase 1: Add accountId to transactions with automatic migration#61
jwaspin merged 2 commits intomainfrom
copilot/fix-16763697-596c-430d-b61e-46cc3642f666

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 6, 2025

Summary

This PR implements Phase 1 of the data refactor by adding an accountId field to all transaction objects and providing automatic migration for existing data. This prepares the codebase for a future unified transaction store by ensuring every transaction knows which account it belongs to.

Changes

Transaction Schema & Data Model

  • Added required accountId field to the transaction schema validation
  • Updated generateTransaction() to accept and include accountId in all new transactions
  • Enhanced transaction actions (createNewTransaction, createRepeatTransaction) to pass accountId when creating transactions
  • Added ACCOUNT_ID constant to TransactionFields enum

Redux State Management

  • Modified account reducers to ensure accountId is set when transactions are added or updated
  • Transactions are now guaranteed to have accountId when stored in account arrays

Automatic Migration

Implemented an idempotent migration in store.js that:

  • Automatically detects transactions missing accountId on app load
  • Backfills accountId from the parent account for existing transactions
  • Reports migration progress to the console with per-account and total counts
  • Immediately persists migrated data to localStorage
  • Only runs when needed - skips transactions that already have accountId

Example migration output:

Migration: Added accountId to 2 transactions in account "Test Checking"
Migration: Added accountId to 1 transactions in account "Test Savings"  
Migration: Successfully updated 3 transactions across 2 accounts

Testing

Migration Testing

  • Simulated old data without accountId - migration successfully backfilled the field
  • Reloaded application multiple times - migration correctly identified already-migrated data (idempotent)
  • Verified migrated data persists correctly to localStorage

New Transaction Testing

  • Created new transactions through UI - verified accountId is automatically included
  • Tested repeated transaction creation - all generated transactions include accountId

Build & Lint

  • ✅ All linting passes
  • ✅ Production build completes successfully
  • ✅ No runtime errors

Acceptance Criteria

All acceptance criteria from the issue have been met:

  • ✅ Each transaction object includes a valid accountId
  • ✅ Existing transactions are updated with their respective accountId
  • ✅ New transactions persist with accountId automatically
  • ✅ Migration is idempotent and safe to re-run
  • ✅ Migration reports the number of transactions updated per account

Screenshots

Application running with version 1.9.0-rc.1 showing migrated data:

Dashboard

Impact

This change is backwards compatible and non-breaking:

  • Existing users' data is automatically migrated on first load
  • The migration is transparent and requires no user action
  • All application functionality continues to work as before
  • Prepares the foundation for Phase 2: creating a unified transaction store

Related Issues

Closes #[issue-number]
Depends on #50 (Data Refactor Phase 0: Rename Redux slices to legacy)

Original prompt

This section details on the original issue you should resolve

<issue_title>Data Refactor Phase 1: Add accountId to transactions</issue_title>
<issue_description>Summary

Prepare for a unified transaction store by adding an accountId field to all transaction objects and backfilling existing data.

Goals
• Add accountId to the transaction type.
• Backfill existing persisted data so every transaction includes the correct accountId.
• Ensure new transactions are saved with accountId.
• Implement a one-time migration that updates all existing data in place.

Acceptance Criteria
• Each transaction object includes a valid accountId.
• Existing transactions are updated with their respective accountId.
• New transactions persist with accountId automatically.
• Migration is idempotent and safe to re-run.
• Migration reports the number of transactions updated per account.</issue_description>

Comments on the Issue (you are @copilot in this section)

@jwaspin #50 Is a prerequisite
Fixes #46

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: jwaspin <6432180+jwaspin@users.noreply.github.com>
Copilot AI changed the title [WIP] Data Refactor Phase 1: Add accountId to transactions Data Refactor Phase 1: Add accountId to transactions with automatic migration Oct 6, 2025
Copilot AI requested a review from jwaspin October 6, 2025 01:06
@jwaspin jwaspin marked this pull request as ready for review October 6, 2025 01:20
@jwaspin jwaspin merged commit 276a6e8 into main Oct 6, 2025
1 check passed
@jwaspin jwaspin deleted the copilot/fix-16763697-596c-430d-b61e-46cc3642f666 branch October 6, 2025 01:20
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.

Data Refactor Phase 1: Add accountId to transactions

2 participants