Skip to content

[MOSIP-37808] Updated DB attributes of MOSIP for audit service#269

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

[MOSIP-37808] Updated DB attributes of MOSIP for audit service#269
abhishek8shankar wants to merge 1 commit into
mosip:developfrom
abhishek8shankar:MOSIP-37808

Conversation

@abhishek8shankar
Copy link
Copy Markdown
Member

@abhishek8shankar abhishek8shankar commented May 18, 2026

Summary by CodeRabbit

Release Notes

  • Chores
    • Database deployment infrastructure has been enhanced to support parameterized configuration values. Database names and user identifiers are now configurable through parameters instead of hardcoded values, improving deployment flexibility and enabling consistent deployments across multiple environments without requiring script modifications.

Review Change Stack

Signed-off-by: Abhi <abhishek.shankarcs@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Walkthrough

This PR parameterizes the audit database deployment scripts by replacing hardcoded database and role names (mosip_audit, audituser) with placeholder variables (:mosipdbname, :dbuname) that are injected at deployment time through the shell script orchestrator.

Changes

Parameterized Database Deployment Configuration

Layer / File(s) Summary
Deployment configuration setup
db_scripts/mosip_audit/deploy.properties
Configuration adds DB_UNAME property set to audituser to define the database username.
Database and schema creation with placeholders
db_scripts/mosip_audit/db.sql, ddl.sql, drop_db.sql
Database creation scripts switch from hardcoded mosip_audit to :mosipdbname placeholder in CREATE DATABASE, connection targets (\c), and ALTER DATABASE statements; drop script similarly targets :mosipdbname.
Role creation and permission grants with placeholders
db_scripts/mosip_audit/role_dbuser.sql, drop_role.sql, grants.sql
Role creation uses :dbuname instead of audituser; all grants (GRANT CONNECT/USAGE/SELECT/INSERT/UPDATE/DELETE and ALTER DEFAULT PRIVILEGES) target :dbuname as grantee and :mosipdbname as database.
Deployment script variable injection
db_scripts/mosip_audit/deploy.sh
Shell script now injects mosipdbname and dbuname variables into all SQL invocations (drop_db.sql, drop_role.sql, db.sql, ddl.sql, role_dbuser.sql, grants.sql, dml.sql); adds explicit messaging around connection termination.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A database reborn, no longer bound,
By names carved in stone and script,
Now placeholders dance around,
Variables whispered at deploy's grip,
🐰 Flexibility blooms in every SQL script!

🚥 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 the main objective of the changeset: parameterizing database and role attributes in the audit service deployment scripts to make them configurable instead of hardcoded.
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.

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

✨ 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 and usage tips.

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: 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 `@db_scripts/mosip_audit/db.sql`:
- Line 1: The SQL uses the unquoted substitution token :mosipdbname which fails
for mixed-case or special-character database names; update all occurrences
(e.g., the CREATE DATABASE statement and the other DDL/DML uses at the noted
spots) to use psql identifier-quoting syntax :"mosipdbname" so the substituted
name is treated as an identifier, not a raw token; ensure every instance of
:mosipdbname in the script is replaced with :"mosipdbname" (including the CREATE
DATABASE, any GRANT/OWNER or CONNECT statements) so names with hyphens or
upper-case are handled correctly.

In `@db_scripts/mosip_audit/deploy.sh`:
- Around line 25-37: The psql invocations in deploy.sh use unquoted shell
variables (e.g., $SU_USER, $DB_SERVERIP, $DB_PORT, $DEFAULT_DB_NAME,
$MOSIP_DB_NAME, $DB_UNAME, $DBUSER_PWD) which can trigger word-splitting or glob
expansion; update every PGPASSWORD=... and psql command (the lines invoking psql
to run drop_db.sql, drop_role.sql, db.sql, ddl.sql, role_dbuser.sql, grants.sql)
to wrap each variable expansion in double quotes (for example
"--username=\"$SU_USER\"" and "--host=\"$DB_SERVERIP\"" and "-v
mosipdbname=\"$MOSIP_DB_NAME\"" and "-v dbuserpwd=\"$DBUSER_PWD\"") so values
with spaces/special chars are passed safely.

In `@db_scripts/mosip_audit/grants.sql`:
- Around line 3-5: The GRANT statement hardcodes the role "audituser" instead of
using the role parameter, so change the GRANT CONNECT statement to grant the
privilege to the configured role parameter (replace the literal audituser with
the parameter :dbuname or DB_UNAME used elsewhere); update the line in
grants.sql where GRANT CONNECT ON DATABASE :mosipdbname TO audituser is defined
so it references the role variable (:dbuname/DB_UNAME) consistently with your
templating.
🪄 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

Run ID: 45538f99-4c04-4537-b529-e492416a2abe

📥 Commits

Reviewing files that changed from the base of the PR and between 03c923a and 1274945.

📒 Files selected for processing (8)
  • db_scripts/mosip_audit/db.sql
  • db_scripts/mosip_audit/ddl.sql
  • db_scripts/mosip_audit/deploy.properties
  • db_scripts/mosip_audit/deploy.sh
  • db_scripts/mosip_audit/drop_db.sql
  • db_scripts/mosip_audit/drop_role.sql
  • db_scripts/mosip_audit/grants.sql
  • db_scripts/mosip_audit/role_dbuser.sql

Comment thread db_scripts/mosip_audit/db.sql
Comment thread db_scripts/mosip_audit/deploy.sh
Comment thread db_scripts/mosip_audit/grants.sql
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