Skip to content

Migration/asha supervisor incentive dbiemr#114

Merged
paras-dba merged 2 commits intomainfrom
migration/asha_supervisor_incentive_dbiemr
Mar 27, 2026
Merged

Migration/asha supervisor incentive dbiemr#114
paras-dba merged 2 commits intomainfrom
migration/asha_supervisor_incentive_dbiemr

Conversation

@SauravBizbRolly
Copy link
Copy Markdown
Contributor

@SauravBizbRolly SauravBizbRolly commented Mar 27, 2026

📋 Description

JIRA ID:

Please provide a summary of the change and the motivation behind it. Include relevant context and details.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • New Features

    • Incentive tracking system now includes approval workflow management with verification history, claim status tracking, and activity linking capabilities.
  • Improvements

    • Enhanced audit capabilities with comprehensive timestamp recording for all incentive-related activities and status changes.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

A new Flyway database migration script is added to the dbiemr database that creates an incentive_pending_activity table and conditionally adds approval workflow and claim tracking columns to the existing incentive_activity_record table using dynamic SQL with schema existence checks.

Changes

Cohort / File(s) Summary
Database Migration
src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql
Creates new incentive_pending_activity table with activity/record linkage and audit timestamps. Conditionally adds approval workflow columns (approval_status, verifiedBy_userId, verifiedBy_userName, reason, other_reason, approval_date) and claim tracking columns (is_claimed, claimed_date) to existing incentive_activity_record table using dynamic SQL checks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A new table hops into place,
With columns cascading with grace,
Incentives tracked, approvals aligned,
And claims recorded, refined!
The schema evolves, migration complete—
Another update, ever so neat! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Migration/asha supervisor incentive dbiemr' is partially related to the changeset, referring to a specific aspect of the change (ASHA supervisor incentive migration for dbiemr database), but it lacks clarity and is somewhat generic. Consider making the title more descriptive, such as 'Add incentive pending activity table and update incentive activity record schema for ASHA supervisor' to better convey the specific database schema changes being made.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch migration/asha_supervisor_incentive_dbiemr

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.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@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 (4)
src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql (4)

107-116: Consider backfilling existing NULL values.

This changes the default for new rows but does not update existing rows that may have NULL values for is_default_activity. If existing rows should also have a default value, consider adding an UPDATE statement:

UPDATE `db_iemr`.`incentive_activity_record` 
SET `is_default_activity` = 0 
WHERE `is_default_activity` IS NULL;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`
around lines 107 - 116, The migration changes the default for
is_default_activity but doesn't backfill existing NULLs; after verifying the
column exists (using the existing `@schema`,`@table`,`@col` check/prepare logic around
`@sql`) add and execute an UPDATE to set NULL values to 0 for that column (e.g.,
update `incentive_activity_record` set `is_default_activity` = 0 where
`is_default_activity` IS NULL), ensuring this runs only when the column exists
so existing rows are fixed in the same migration.

19-28: Document the magic number 101 for approval_status.

The default value 101 is not self-documenting. Consider adding a SQL comment explaining what this status code represents (e.g., pending, approved, rejected) for future maintainability.

 -- 1. approval_status
+-- Status codes: 101 = Pending, 102 = Approved, 103 = Rejected (example - adjust as needed)
 SET `@col` = 'approval_status';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`
around lines 19 - 28, The migration adds approval_status with default 101 but
doesn't explain the magic number; update the ALTER TABLE statement that uses
`@col/`@sql to set the column as ADD COLUMN `approval_status` INT DEFAULT 101
COMMENT '101 = <meaning, e.g., PENDING_APPROVAL>' (or whichever semantic label
is correct) so the SQL schema documents the meaning of 101; keep the conditional
logic using `@col`, `@sql`, PREPARE/EXECUTE as-is and only add the COMMENT to the
column definition and/or include a short SQL comment above the block explaining
the status code mapping.

3-14: Consider adding foreign key constraints.

The table references activity_id, record_id, user_id, and m_incentive_id which appear to be foreign keys to other tables. Without FK constraints, referential integrity is not enforced at the database level, potentially allowing orphaned records.

If these are intentionally omitted (e.g., for performance or cross-schema references), consider documenting this design decision in a comment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`
around lines 3 - 14, The migration creates incentive_pending_activity with
columns activity_id, record_id, user_id, and m_incentive_id but no foreign key
constraints; add appropriate FK constraints referencing the parent tables (e.g.,
activities, records/modules, users, m_incentive) for columns activity_id,
record_id, user_id, and m_incentive_id in the incentive_pending_activity table
(or if cross-schema/performance reasons prevent FKs, add an inline SQL
comment/documentation in the migration explaining the intentional omission).
Ensure you reference the incentive_pending_activity table and the exact column
names (activity_id, record_id, user_id, m_incentive_id) when adding the
constraints or the explanatory comment.

30-50: Use consistent snake_case naming for new columns.

verifiedBy_userId and verifiedBy_userName use mixed camelCase, while all existing columns in incentive_activity_record (activity_id, asha_id, ben_id, created_by, created_date, updated_by, updated_date) use snake_case. Rename to:

  • verifiedBy_userIdverified_by_user_id
  • verifiedBy_userNameverified_by_user_name
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`
around lines 30 - 50, The migration adds columns using camelCase names; change
both occurrences where `@col` is set ('verifiedBy_userId' and
'verifiedBy_userName') to snake_case ('verified_by_user_id' and
'verified_by_user_name') and update the dynamic ALTER TABLE string construction
(the CONCAT in `@sql`) and the fallback SELECT message to reference the new
snake_case names so the checks against INFORMATION_SCHEMA.COLUMNS (using
`@schema/`@table/@col) and the ALTER TABLE statements target the snake_case
columns for table incentive_activity_record.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`:
- Around line 96-105: The migration uses the misspelled column name stored in
`@col` as 'calimed_date'; update that identifier to the correct 'claimed_date'
everywhere in this migration (the SET `@col` assignment and any constructed ALTER
TABLE SQL built via `@sql/CONCAT`) so the ALTER TABLE ADD COLUMN creates
`claimed_date` (ensure the IF/SELECT fallback message also reflects the
corrected name).

---

Nitpick comments:
In
`@src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql`:
- Around line 107-116: The migration changes the default for is_default_activity
but doesn't backfill existing NULLs; after verifying the column exists (using
the existing `@schema`,`@table`,`@col` check/prepare logic around `@sql`) add and
execute an UPDATE to set NULL values to 0 for that column (e.g., update
`incentive_activity_record` set `is_default_activity` = 0 where
`is_default_activity` IS NULL), ensuring this runs only when the column exists
so existing rows are fixed in the same migration.
- Around line 19-28: The migration adds approval_status with default 101 but
doesn't explain the magic number; update the ALTER TABLE statement that uses
`@col/`@sql to set the column as ADD COLUMN `approval_status` INT DEFAULT 101
COMMENT '101 = <meaning, e.g., PENDING_APPROVAL>' (or whichever semantic label
is correct) so the SQL schema documents the meaning of 101; keep the conditional
logic using `@col`, `@sql`, PREPARE/EXECUTE as-is and only add the COMMENT to the
column definition and/or include a short SQL comment above the block explaining
the status code mapping.
- Around line 3-14: The migration creates incentive_pending_activity with
columns activity_id, record_id, user_id, and m_incentive_id but no foreign key
constraints; add appropriate FK constraints referencing the parent tables (e.g.,
activities, records/modules, users, m_incentive) for columns activity_id,
record_id, user_id, and m_incentive_id in the incentive_pending_activity table
(or if cross-schema/performance reasons prevent FKs, add an inline SQL
comment/documentation in the migration explaining the intentional omission).
Ensure you reference the incentive_pending_activity table and the exact column
names (activity_id, record_id, user_id, m_incentive_id) when adding the
constraints or the explanatory comment.
- Around line 30-50: The migration adds columns using camelCase names; change
both occurrences where `@col` is set ('verifiedBy_userId' and
'verifiedBy_userName') to snake_case ('verified_by_user_id' and
'verified_by_user_name') and update the dynamic ALTER TABLE string construction
(the CONCAT in `@sql`) and the fallback SELECT message to reference the new
snake_case names so the checks against INFORMATION_SCHEMA.COLUMNS (using
`@schema/`@table/@col) and the ALTER TABLE statements target the snake_case
columns for table incentive_activity_record.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 625d0d0c-7e71-459b-9c2d-b0f7185c258f

📥 Commits

Reviewing files that changed from the base of the PR and between ab297dd and 26e4d4e.

📒 Files selected for processing (1)
  • src/main/resources/db/migration/dbiemr/V70__migration_for_asha_supervisor_dbiemr.sql

@paras-dba paras-dba merged commit a891285 into main Mar 27, 2026
7 of 8 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.

2 participants