Skip to content

Conversation

@shubham1g5
Copy link
Contributor

Product Description

https://dimagi.atlassian.net/browse/CI-287

Technical Summary

We were missing a setTransactionSuccessful which was causing the upgrade to not be applied.

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

📝 Walkthrough

Walkthrough

The upgrade path from database version 17 to 18 now explicitly calls db.setTransactionSuccessful() after dropping and recreating the PersonalIdCredential table within a transaction, ensuring the transaction commits on success. A minor whitespace change was made in addTableForNewModel with no functional impact. No public APIs were altered.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant Upgrader as ConnectDatabaseUpgrader
  participant DB as SQLite DB

  App->>Upgrader: onUpgrade(17 -> 18)
  Upgrader->>DB: beginTransaction()
  Upgrader->>DB: DROP TABLE personal_id_credential
  Upgrader->>DB: CREATE TABLE personal_id_credential
  note over Upgrader,DB: New: mark transaction successful
  Upgrader->>DB: setTransactionSuccessful()
  Upgrader->>DB: endTransaction()
  DB-->>Upgrader: Commit applied
  Upgrader-->>App: Upgrade complete
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • OrangeAndGreen
  • Jignesh-dimagi

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR includes a Product Description linking ticket CI-287 and a brief Technical Summary explaining the missing setTransactionSuccessful fix, but it omits required sections from the repository template: Safety Assurance (safety story), Automated test coverage, and a QA Plan, and it does not address the Feature Flag section while leaving QA and Release Note checklist items unchecked. For a database migration-related change the missing safety/testing/QA details are important, so the description is incomplete for merge. Please add a Safety story that describes validation steps and impact on existing data, specify automated test coverage or a plan to add tests for the upgrade path, and provide a QA Plan with manual test steps and a QA ticket. Also indicate any feature-flag applicability and update the checklist and labels (QA Note/Release Note and risk labels) before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Fixes Connect DB upgrade" succinctly and accurately summarizes the primary change in this PR (adding a missing setTransactionSuccessful in ConnectDatabaseUpgrader so the upgrade commits) and is clear and specific enough for teammates scanning history.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fixConnectUpgrade

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/src/org/commcare/models/database/connect/ConnectDatabaseUpgrader.java (1)

639-647: Avoid nested transactions (inline table creation inside the same txn).

addTableForNewModel opens its own transaction; calling it within an outer transaction creates nesting. Inline the table creation to keep a single transaction.

     try {
         // We have not been populating this table yet, so just drop and recreate
         SqlStorage.dropTable(db, PersonalIdCredential.STORAGE_KEY);
-        addTableForNewModel(db, PersonalIdCredential.STORAGE_KEY, new PersonalIdCredential());
+        TableBuilder builder = new TableBuilder(PersonalIdCredential.STORAGE_KEY);
+        builder.addData(new PersonalIdCredential());
+        db.execSQL(builder.getTableCreateString());
         db.setTransactionSuccessful();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f2f892 and 696d79d.

📒 Files selected for processing (1)
  • app/src/org/commcare/models/database/connect/ConnectDatabaseUpgrader.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: shubham1g5
PR: dimagi/commcare-android#0
File: :0-0
Timestamp: 2025-05-08T11:08:18.530Z
Learning: PR #3048 "Phase 4 Connect PR" introduces a substantial feature called "Connect" to the CommCare Android app, which includes messaging, job management, delivery tracking, payment processing, authentication flows, and learning modules. It follows a modern architecture using Navigation Components with three navigation graphs, segregated business logic in Manager classes, and proper database persistence.
🔇 Additional comments (1)
app/src/org/commcare/models/database/connect/ConnectDatabaseUpgrader.java (1)

644-644: Correct fix: transaction now commits for v17→18.

Adding db.setTransactionSuccessful() ensures the upgrade applies. LGTM.

Comment on lines 641 to 646
// We have not been populating this table yet, so just drop and recreate
SqlStorage.dropTable(db, PersonalIdCredential.STORAGE_KEY);
addTableForNewModel(db, PersonalIdCredential.STORAGE_KEY, new PersonalIdCredential());
db.setTransactionSuccessful();
} finally {
db.endTransaction();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

🧩 Analysis chain

Safety/telemetry before destructive drop.

If the “not populated yet” assumption ever breaks in the field, we’ll silently delete data. Log row count before dropping to surface surprises.

     try {
-        // We have not been populating this table yet, so just drop and recreate
+        // We have not been populating this table yet, so just drop and recreate
+        // Telemetry: log if we find unexpected rows before drop
+        SqlStorage<Persistable> picStorage = new SqlStorage<>(
+                PersonalIdCredential.STORAGE_KEY,
+                PersonalIdCredential.class,
+                new ConcreteAndroidDbHelper(c, db));
+        int existing = picStorage.getNumRecords();
+        if (existing > 0) {
+            CrashUtil.log("upgradeSeventeenEighteen: dropping PersonalIdCredential with " + existing + " rows");
+        }
         SqlStorage.dropTable(db, PersonalIdCredential.STORAGE_KEY);
-        addTableForNewModel(db, PersonalIdCredential.STORAGE_KEY, new PersonalIdCredential());
+        TableBuilder builder = new TableBuilder(PersonalIdCredential.STORAGE_KEY);
+        builder.addData(new PersonalIdCredential());
+        db.execSQL(builder.getTableCreateString());
         db.setTransactionSuccessful();

To validate the assumption across the codebase (no writes before v18), run:


🏁 Script executed:

#!/bin/bash
# Find any writes/usages of PersonalIdCredential
rg -nP -C3 --type=java '\bPersonalIdCredential\b'
rg -nP -C2 --type=java 'SqlStorage<\s*PersonalIdCredential\s*>'
rg -nP -C3 --type=java '\.write\s*\(' | rg -nP -C0 'PersonalIdCredential|STORAGE_KEY'

Length of output: 8968


Do not unconditionally drop PersonalIdCredential — log/count and preserve/migrate if populated.

ConnectAppDatabaseUtil.storeCredentialDataInTable writes to this table, so the “not populated yet” assumption can be false. Before calling SqlStorage.dropTable(...), run a COUNT(*) on PersonalIdCredential.STORAGE_KEY and log via CrashUtil; if count > 0, preserve or migrate the data (or fail the upgrade and surface telemetry) instead of silently dropping it.

Relevant locations: app/src/org/commcare/connect/database/ConnectAppDatabaseUtil.java (storeCredentialDataInTable) and app/src/org/commcare/models/database/connect/DatabaseConnectOpenHelper.java (table creation).

@shubham1g5 shubham1g5 merged commit 3fb0042 into commcare_2.59 Sep 17, 2025
1 of 2 checks passed
@shubham1g5 shubham1g5 deleted the fixConnectUpgrade branch September 17, 2025 17:12
This was referenced Sep 26, 2025
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