Skip to content

chore: [ANDROSDK-2128] Replace Auto-Increment _id Keys with UIDs and Composite Primary Keys#2438

Merged
marcamsn merged 47 commits into
developfrom
ANDROSDK-2128
Jul 22, 2025
Merged

chore: [ANDROSDK-2128] Replace Auto-Increment _id Keys with UIDs and Composite Primary Keys#2438
marcamsn merged 47 commits into
developfrom
ANDROSDK-2128

Conversation

@marcamsn

@marcamsn marcamsn commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Description
This PR removes all legacy _id INTEGER PRIMARY KEY AUTOINCREMENT columns and migrates each table to use meaningful TEXT UIDs or composite unique constraints. It includes migration scripts (v175), refactors SQL definitions, updates model builders and toDomain() mappings, adapts tests, and bumps the database version to 175.

Highlights

  • Migration Script: Drop old _id columns, redefine PKs, update snapshot.sql
  • Code Updates: Remove id(Long) from builders and core interfaces; refactor persistence stores and handlers
  • Store Behavior: Switch from direct insert to updateOrInsert in certain stores (e.g., ForeignKeyViolationStore now backed by an ObjectWithoutUidStore)
  • Ordering: Introduce sortOrder in TrackerVisualizationDimension and VisualizationDimensionItem models to preserve row order lost with autoincrement
  • Indexes: Removes event_data_element and tracked_entity_instance_attribute indexes since they're primary keys now.
  • Tests: Adapt unit & integration tests

Note

⚠️ This is a dangerous migration: row ordering may change, affecting list-return order expectations. Please review this PR with extra care.

marcamsn added 26 commits June 19, 2025 11:50
…DROSDK-2128

# Conflicts:
#	core/src/main/java/org/hisp/dhis/android/persistence/itemfilter/ItemFilterDB.kt
@marcamsn marcamsn requested review from taridepaco and vgarciabnz July 9, 2025 05:51

@vgarciabnz vgarciabnz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have not reviewed the migration yet, I want to do it tomorrow. In the migration, The only thing I would consider is that primary keys that create new UNIQUE constraints might fail during the migration (probably because an existing inconsistent data). I will try to be permissive with those errors and just ignore them.

Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
Comment thread core/src/main/assets/snapshots/snapshot.sql Outdated
@marcamsn

Copy link
Copy Markdown
Contributor Author

@vgarciabnz , about your comment:

I have not reviewed the migration yet, I want to do it tomorrow. In the migration, The only thing I would consider is that primary keys that create new UNIQUE constraints might fail during the migration (probably because an existing inconsistent data). I will try to be permissive with those errors and just ignore them.

Maybe we can just use INSERT OR IGNORE INTO instead of the INSERT INTO to skip any rows that violate our new PK/UNIQUE constraints in 175.sql.

@sonarqubecloud

Copy link
Copy Markdown

@marcamsn marcamsn merged commit 6e4c161 into develop Jul 22, 2025
4 checks passed
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.

3 participants