Skip to content

1899 Updated db_upgrade scripts for audit-manager#292

Open
abhishek8shankar wants to merge 1 commit into
mosip:developfrom
abhishek8shankar:MOSIP-1899
Open

1899 Updated db_upgrade scripts for audit-manager#292
abhishek8shankar wants to merge 1 commit into
mosip:developfrom
abhishek8shankar:MOSIP-1899

Conversation

@abhishek8shankar

@abhishek8shankar abhishek8shankar commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Updated database upgrade and rollback steps to use configurable connection and user values instead of fixed names.
    • Improved privilege handling during upgrades so the correct database user is targeted consistently.
    • Passed the required database variables through the upgrade process to support more reliable execution.

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

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The mosip_audit upgrade/rollback SQL scripts and driving shell script are updated to replace hardcoded database name (mosip_audit) and username (audituser) references with parameterized :mosipdbname and :dbuname placeholders, sourced from a new DB_UNAME property and passed via -v flags in psql invocations.

Changes

Parameterized DB Connection and Privileges

Layer / File(s) Summary
DB_UNAME property added
db_upgrade_scripts/mosip_audit/upgrade.properties
Adds DB_UNAME=audituser property for use in downstream scripts.
SQL scripts parameterize connection and grants
db_upgrade_scripts/mosip_audit/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql, db_upgrade_scripts/mosip_audit/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql
Replaces hardcoded \c mosip_audit with \c :mosipdbname, and hardcoded audituser grant/revoke targets with :dbuname placeholders.
Shell script injects variables into psql calls
db_upgrade_scripts/mosip_audit/upgrade.sh
Terminate-connection, upgrade, and rollback psql invocations now pass -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant upgrade.sh
  participant upgrade.properties
  participant psql
  upgrade.sh->>upgrade.properties: read MOSIP_DB_NAME, DB_UNAME
  upgrade.sh->>psql: terminate connections (-v mosipdbname, -v dbuname)
  upgrade.sh->>psql: run upgrade SQL (-v mosipdbname, -v dbuname)
  upgrade.sh->>psql: run rollback SQL (-v mosipdbname, -v dbuname)
Loading

Possibly related PRs

  • mosip/audit-manager#269: Both PRs parameterize the audit DB upgrade/rollback SQL flow by switching \c mosip_audit/audituser to :mosipdbname/:dbuname and injecting these variables via the driving shell scripts.

Suggested reviewers: ckm007

Poem

A hardcoded name, hopping away,
Now :mosipdbname leads the way!
audituser traded for :dbuname too,
Scripts stay flexible, tried and true.
Thump thump — deploy anew! 🐰✨

🚥 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 clearly identifies the db_upgrade script changes for audit-manager and matches the main scope of the PR.
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 (1)
db_upgrade_scripts/mosip_audit/upgrade.sh (1)

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

Quote the new -v variable expansions.

The newly added -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME args are unquoted, matching flagged shellcheck (SC2086) warnings on these lines. Since these values come from the properties file (not user input) the practical risk is low, but quoting avoids word-splitting/globbing surprises if a value ever contains spaces or glob characters.

🔧 Proposed fix
-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;)
+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;)

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_audit/upgrade.sh` at line 24, The psql command in
upgrade.sh passes new -v variables without quoting, which can trigger
word-splitting and shellcheck SC2086 warnings. Update the command construction
in the affected upgrade steps to quote the mosipdbname and dbuname expansions
while keeping the existing psql invocation and variable names intact. Apply the
same quoting pattern consistently wherever these -v arguments are used in the
script.

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_audit/upgrade.sh`:
- Line 24: The psql command in upgrade.sh passes new -v variables without
quoting, which can trigger word-splitting and shellcheck SC2086 warnings. Update
the command construction in the affected upgrade steps to quote the mosipdbname
and dbuname expansions while keeping the existing psql invocation and variable
names intact. Apply the same quoting pattern consistently wherever these -v
arguments are used in the script.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1d3a9b8-b82d-4409-8078-26694454eeb0

📥 Commits

Reviewing files that changed from the base of the PR and between 770f498 and 673aab9.

📒 Files selected for processing (4)
  • db_upgrade_scripts/mosip_audit/sql/1.1.5.5_to_1.2.0.1-B1_rollback.sql
  • db_upgrade_scripts/mosip_audit/sql/1.1.5.5_to_1.2.0.1-B1_upgrade.sql
  • db_upgrade_scripts/mosip_audit/upgrade.properties
  • db_upgrade_scripts/mosip_audit/upgrade.sh

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