Skip to content

1899 Updated db_upgrade scripts for admin-services#1387

Open
abhishek8shankar wants to merge 2 commits into
mosip:developfrom
abhishek8shankar:MOSIP-1899
Open

1899 Updated db_upgrade scripts for admin-services#1387
abhishek8shankar wants to merge 2 commits into
mosip:developfrom
abhishek8shankar:MOSIP-1899

Conversation

@abhishek8shankar

@abhishek8shankar abhishek8shankar commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Database upgrade and rollback steps now use configurable database and user values instead of fixed names.
    • Privileges and connection settings are applied to the selected database/user during upgrade and rollback.
    • Connection handling scripts now pass the required values consistently for both upgrade paths.

Signed-off-by: abhishek8shankar <abhishek.shankarcs@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@abhishek8shankar, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e15c1fa-c946-41fb-ae7f-ecd4ce6dbb04

📥 Commits

Reviewing files that changed from the base of the PR and between d4af50e and ba066d9.

📒 Files selected for processing (2)
  • db_upgrade_scripts/mosip_hotlist/upgrade.properties
  • db_upgrade_scripts/mosip_master/upgrade.properties

Walkthrough

Hard-coded database names (mosip_hotlist, mosip_master) and role names (hotlistuser, masteruser) in SQL upgrade/rollback scripts are replaced with psql bind variables (:mosipdbname, :dbuname). Corresponding upgrade.properties files add a DB_UNAME entry, and upgrade.sh scripts pass these values as psql -v parameters.

Changes

mosip_hotlist DB parameterization

Layer / File(s) Summary
Parameterize hotlist SQL scripts
db_upgrade_scripts/mosip_hotlist/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql, db_upgrade_scripts/mosip_hotlist/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql
Hard-coded mosip_hotlist database and hotlistuser role are replaced with :mosipdbname and :dbuname in DB creation/drop, connection, search_path, role creation, and grant statements.
Wire DB_UNAME through properties and shell script
db_upgrade_scripts/mosip_hotlist/upgrade.properties, db_upgrade_scripts/mosip_hotlist/upgrade.sh
A new DB_UNAME= property is added and upgrade.sh passes mosipdbname and dbuname as psql -v variables during connection termination and upgrade/rollback execution.

mosip_master DB parameterization

Layer / File(s) Summary
Parameterize master 1.1.5.5→1.2.0.1-B1 SQL scripts
db_upgrade_scripts/mosip_master/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql, db_upgrade_scripts/mosip_master/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql
Connection, schema privilege, and table-level grants for master.blocklisted_words, master.ui_spec, and master.permitted_local_config target :dbuname/:mosipdbname instead of masteruser/mosip_master.
Parameterize master 1.2.1.4→1.3.0 SQL scripts
db_upgrade_scripts/mosip_master/sql/1.2.1.4_to_1.3.0_upgrade.sql, db_upgrade_scripts/mosip_master/sql/1.2.1.4_to_1.3.0_rollback.sql
Initial database connection command changes from hard-coded mosip_master to :mosipdbname.
Wire DB_UNAME through properties and shell script
db_upgrade_scripts/mosip_master/upgrade.properties, db_upgrade_scripts/mosip_master/upgrade.sh
A new DB_UNAME= property is added and upgrade.sh passes mosipdbname and dbuname as psql -v variables during connection termination and upgrade/rollback execution.

Estimated code review effort: 2 (Simple) | ~15 minutes

Poem

Hoppity hop through scripts of old,
Names once fixed, now free and bold,
:dbuname and :mosipdbname take their place,
A rabbit's cheer for tidy grace,
No more hard-coded burrow to find! 🐇✨

🚥 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 is concise and matches the main change: updates to db_upgrade scripts for admin-services.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

🧹 Nitpick comments (4)
db_upgrade_scripts/mosip_hotlist/upgrade.sh (2)

24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unnecessary -v variables on the terminate-connections call.

mosipdbname/dbuname are passed but the inline -c query only references $MOSIP_DB_NAME (shell var), not :mosipdbname. Harmless but dead parameters.

🤖 Prompt for 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.

In `@db_upgrade_scripts/mosip_hotlist/upgrade.sh` at line 24, The
terminate-connections psql invocation in upgrade.sh passes unused -v variables,
since the SQL in the -c block references the shell variable MOSIP_DB_NAME
directly instead of the psql variables mosipdbname/dbuname. Remove the dead
variable bindings from the psql command (or switch the query to use the named
psql variables consistently) so the call only keeps the parameters actually
used.

24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unquoted shell variables in psql invocations (SC2086).

Static analysis flags the newly added mosipdbname=$MOSIP_DB_NAME / dbuname=$DB_UNAME args (and pre-existing ones) as unquoted, risking word-splitting/globbing if values contain spaces/special chars.

Also applies to: 33-33, 43-43

🤖 Prompt for 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.

In `@db_upgrade_scripts/mosip_hotlist/upgrade.sh` at line 24, The psql call in
upgrade.sh is passing shell-expanded values such as SU_USER_PWD, MOSIP_DB_NAME,
DB_UNAME, SU_USER, DB_SERVERIP, DB_PORT, and DEFAULT_DB_NAME without quotes,
which can trigger word-splitting or globbing; update the command in the upgrade
flow so each variable expansion is quoted or otherwise safely passed when
invoking psql. Apply the same fix consistently in the other affected psql
invocations in this script, including the ones used alongside the CONN
assignment and any related database checks.

Source: Linters/SAST tools

db_upgrade_scripts/mosip_master/upgrade.sh (2)

24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unused CONN and no-op exit inside command substitution.

CONN is assigned but never read afterward, and exit runs inside the $(...) subshell so it doesn't actually stop the script if terminating connections fails — execution proceeds to the upgrade/rollback step regardless.

♻️ Optional cleanup
-CONN=$(PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()";exit;)
+PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -t -c "SELECT count(pg_terminate_backend(pg_stat_activity.pid)) FROM pg_stat_activity WHERE datname = '$MOSIP_DB_NAME' AND pid <> pg_backend_pid()"
🤖 Prompt for 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.

In `@db_upgrade_scripts/mosip_master/upgrade.sh` at line 24, The
connection-termination step in upgrade.sh is assigning the result to CONN even
though it is never used, and the trailing exit inside the command substitution
does not stop the main script. Update the psql/pg_terminate_backend logic in the
CONN assignment so failures are handled in the parent shell, and ensure the
upgrade flow halts before the rollback/upgrade step if terminating active
sessions does not succeed.

Source: Linters/SAST tools


24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Quote variable expansions in -v args (shellcheck SC2086).

$MOSIP_DB_NAME, $DB_UNAME, etc. are unquoted in the psql -v invocations, risking word-splitting/globbing if a value ever contains spaces/special chars.

Also applies to: 33-33, 43-43

🤖 Prompt for 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.

In `@db_upgrade_scripts/mosip_master/upgrade.sh` at line 24, The psql invocation
in the upgrade script passes shell variables into -v without quoting, which can
trigger word splitting or globbing if values contain spaces or special
characters. Update the psql command(s) that set mosipdbname, dbuname, and any
similar variables to use properly quoted variable expansions, and apply the same
fix to the other affected psql calls in the script so the values are passed
safely and consistently.

Source: Linters/SAST tools

🤖 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.

Nitpick comments:
In `@db_upgrade_scripts/mosip_hotlist/upgrade.sh`:
- Line 24: The terminate-connections psql invocation in upgrade.sh passes unused
-v variables, since the SQL in the -c block references the shell variable
MOSIP_DB_NAME directly instead of the psql variables mosipdbname/dbuname. Remove
the dead variable bindings from the psql command (or switch the query to use the
named psql variables consistently) so the call only keeps the parameters
actually used.
- Line 24: The psql call in upgrade.sh is passing shell-expanded values such as
SU_USER_PWD, MOSIP_DB_NAME, DB_UNAME, SU_USER, DB_SERVERIP, DB_PORT, and
DEFAULT_DB_NAME without quotes, which can trigger word-splitting or globbing;
update the command in the upgrade flow so each variable expansion is quoted or
otherwise safely passed when invoking psql. Apply the same fix consistently in
the other affected psql invocations in this script, including the ones used
alongside the CONN assignment and any related database checks.

In `@db_upgrade_scripts/mosip_master/upgrade.sh`:
- Line 24: The connection-termination step in upgrade.sh is assigning the result
to CONN even though it is never used, and the trailing exit inside the command
substitution does not stop the main script. Update the psql/pg_terminate_backend
logic in the CONN assignment so failures are handled in the parent shell, and
ensure the upgrade flow halts before the rollback/upgrade step if terminating
active sessions does not succeed.
- Line 24: The psql invocation in the upgrade script passes shell variables into
-v without quoting, which can trigger word splitting or globbing if values
contain spaces or special characters. Update the psql command(s) that set
mosipdbname, dbuname, and any similar variables to use properly quoted variable
expansions, and apply the same fix to the other affected psql calls in the
script so the values are passed safely and consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 29d9586f-26f6-4fb1-bbe5-4ef1249d357d

📥 Commits

Reviewing files that changed from the base of the PR and between 0d2f3e3 and d4af50e.

📒 Files selected for processing (10)
  • db_upgrade_scripts/mosip_hotlist/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql
  • db_upgrade_scripts/mosip_hotlist/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql
  • db_upgrade_scripts/mosip_hotlist/upgrade.properties
  • db_upgrade_scripts/mosip_hotlist/upgrade.sh
  • db_upgrade_scripts/mosip_master/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql
  • db_upgrade_scripts/mosip_master/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql
  • db_upgrade_scripts/mosip_master/sql/1.2.1.4_to_1.3.0_rollback.sql
  • db_upgrade_scripts/mosip_master/sql/1.2.1.4_to_1.3.0_upgrade.sql
  • db_upgrade_scripts/mosip_master/upgrade.properties
  • db_upgrade_scripts/mosip_master/upgrade.sh

Signed-off-by: abhishek8shankar <abhishek.shankarcs@gmail.com>
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.

1 participant