Skip to content

Add migrations for beneficiary residence columns and diagnostic devic… - #144

Merged
vanitha1822 merged 3 commits into
PSMRI:mainfrom
sehjotsinghunthinkable:migration/add-diagnostic-changes
Jul 29, 2026
Merged

Add migrations for beneficiary residence columns and diagnostic devic…#144
vanitha1822 merged 3 commits into
PSMRI:mainfrom
sehjotsinghunthinkable:migration/add-diagnostic-changes

Conversation

@sehjotsinghunthinkable

@sehjotsinghunthinkable sehjotsinghunthinkable commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Add two new Flyway migrations:

  • db_identity V19: Adds placeOfCurrentLiving, otherPlaceOfCurrentLiving,
    and institutionName columns to i_beneficiarydetails and
    i_beneficiarydetails_rmnch to capture a beneficiary's current place
    of residence. Idempotent — checks INFORMATION_SCHEMA before altering
    so it is safe to re-run.

  • db_iemr V96: Creates the schema for diagnostic device integration —
    tb_diagnostic_order (orders sent to external diagnostic providers),
    tb_diagnostic_result (results per order), tb_diagnostic_document
    (reports/files linked to a result), and
    tb_diagnostic_provider_token (auth tokens for provider APIs). Uses
    CREATE TABLE IF NOT EXISTS, so re-running is safe; future schema
    changes should ship as separate ALTER migrations.

Summary by CodeRabbit

  • New Features

    • Added database support for additional place-of-current-living fields (including alternative and institution name) and expanded household address/registration details.
    • Introduced diagnostic device integration tables for diagnostic orders, results, related documents, and provider tokens (with soft-delete and uniqueness constraints).
  • Bug Fixes

    • Improved migration safety with fully idempotent, re-runnable schema updates.
    • Ensured isGpsUnavailable is normalized consistently across affected tables when present.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df287c6f-019d-4986-92c3-39e52493c3a3

📥 Commits

Reviewing files that changed from the base of the PR and between 81f40a1 and 678d800.

📒 Files selected for processing (2)
  • src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql
  • src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql
  • src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql

📝 Walkthrough

Walkthrough

Adds idempotent db_identity changes for beneficiary, household, and GPS fields, and introduces db_iemr tables for diagnostic orders, results, documents, and provider tokens.

Changes

Beneficiary identity schema

Layer / File(s) Summary
Identity and household column additions
src/main/resources/dbidentity/V19_Non_Household_Add_Column.sql
Idempotently adds living-location fields to both beneficiary detail tables and household registration fields to i_householddetails.
GPS availability normalization
src/main/resources/dbidentity/V19_Non_Household_Add_Column.sql
Conditionally normalizes isGpsUnavailable to nullable TINYINT(1) with default 0 in three tables.

Diagnostic device integration schema

Layer / File(s) Summary
Diagnostic order table
src/main/resources/dbiemr/V96_Device_Integration.sql
Selects db_iemr and creates tb_diagnostic_order with order metadata, soft deletion, and uniqueness constraints.
Diagnostic records and provider tokens
src/main/resources/dbiemr/V96_Device_Integration.sql
Creates order-linked result and document tables, plus provider-token storage with uniqueness and expiration fields.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • PSMRI/AMRIT-DB#135: Adds related isGpsUnavailable changes to overlapping db_identity tables.

Suggested reviewers: vishwab1, paras-dba

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects both main changes: beneficiary residence columns and diagnostic device integration migrations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql`:
- Around line 16-27: The migration’s six column-exists no-op branches use
double-quoted strings, which are invalid as SQL literals under ANSI_QUOTES. In
src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql,
update the fallback SELECT expressions in the dynamic SQL blocks at lines 16-27,
30-41, 44-55, 62-73, 76-87, and 90-101 to use single-quoted message literals,
preserving the existing ALTER TABLE branches.

In `@src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql`:
- Around line 25-58: Remove IF NOT EXISTS from the CREATE TABLE statements for
tb_diagnostic_order
(src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql#L25-L58),
tb_diagnostic_result (`#L64-L82`), tb_diagnostic_document (`#L88-L112`), and
tb_diagnostic_provider_token (`#L118-L128`), so V96 fails when any pre-existing
table has an incompatible schema.
- Line 122: Update the token storage associated with token_value so provider
bearer tokens are never persisted as plaintext. Use the existing secrets-manager
integration or encrypt the value with an application-managed/KMS-backed key
before database persistence, ensuring the database stores only ciphertext and
access is restricted appropriately.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 34bcf09a-1a58-4867-9fde-30bbf2130937

📥 Commits

Reviewing files that changed from the base of the PR and between cff8328 and 7f81c0f.

📒 Files selected for processing (2)
  • src/main/resources/db/migration/dbidentity/V19_Non_Household_Add_Column.sql
  • src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql

Comment thread src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql
Comment thread src/main/resources/db/migration/dbiemr/V96_Device_Integration.sql
@drtechie

Copy link
Copy Markdown
Member
  1. Please check the Code Rabbit comments.
  2. Since these migrations were executed manually DB service will fail. You will have to write code in such a way that ALTER TABLE happens only if column doesn't exist. Check how its done in other migrations.

@drtechie
drtechie requested review from paras-dba and vishwab1 July 28, 2026 07:12
@drtechie

Copy link
Copy Markdown
Member

Some of these create table definition do not contain sync related column.
Also I don't see syncFailureReason column.
These TB/Trunat results should be part of the sync from local to central and hence must have right columns. Also this must be present in the list of tables to be synced from local to central.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
40.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@vishwab1
vishwab1 requested a review from vanitha1822 July 29, 2026 08:54
@vanitha1822
vanitha1822 merged commit 2c1cba0 into PSMRI:main Jul 29, 2026
2 of 3 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.

4 participants