Skip to content

Conversation

@bgoncal
Copy link
Member

@bgoncal bgoncal commented Jan 28, 2026

Refactors area, entity, and device registry persistence methods to delete all existing records for a server before inserting fresh data, instead of performing upserts and differential deletes. This simplifies the logic and ensures data consistency by always replacing old data in a single transaction.

Summary

Screenshots

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

Refactors area, entity, and device registry persistence methods to delete all existing records for a server before inserting fresh data, instead of performing upserts and differential deletes. This simplifies the logic and ensures data consistency by always replacing old data in a single transaction.
@bgoncal bgoncal self-assigned this Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 10:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the database persistence strategy for areas, entities, and device registries by replacing the complex upsert-and-differential-delete approach with a simpler delete-all-then-insert pattern. This change simplifies the code while maintaining data consistency through GRDB's transaction guarantees.

Changes:

  • Replaced upsert operations (save(db, onConflict: .replace)) with insert operations (insert(db))
  • Removed logic for fetching existing IDs and computing differential deletes
  • Updated method documentation to reflect the new approach
  • Applied the pattern consistently across four database persistence methods

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@f57b549). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ources/Shared/Environment/AppDatabaseUpdater.swift 0.00% 20 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4267   +/-   ##
=======================================
  Coverage        ?   43.22%           
=======================================
  Files           ?      261           
  Lines           ?    15065           
  Branches        ?        0           
=======================================
  Hits            ?     6512           
  Misses          ?     8553           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bgoncal bgoncal merged commit d03515f into main Jan 28, 2026
14 of 15 checks passed
@bgoncal bgoncal deleted the fix-database branch January 28, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants