Skip to content

Fix to use PG user from env variables - #593

Merged
DZakh merged 1 commit into
mainfrom
dz/fix-pg-user-from-env-vars
Jun 15, 2025
Merged

Fix to use PG user from env variables#593
DZakh merged 1 commit into
mainfrom
dz/fix-pg-user-from-env-vars

Conversation

@DZakh

@DZakh DZakh commented Jun 15, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added support for specifying a custom PostgreSQL user when setting up schema permissions, allowing greater flexibility in database configuration.
  • Tests

    • Updated test cases to accommodate the new PostgreSQL user parameter, ensuring continued reliability and correctness.

@coderabbitai

coderabbitai Bot commented Jun 15, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new pgUser parameter to the schema initialization logic, replacing the previously hardcoded PostgreSQL user in privilege grant statements. This parameter is now required in relevant function signatures and is propagated through the codebase, including in configuration and test files, to ensure dynamic assignment of the database user.

Changes

Files/Group Change Summary
codegenerator/cli/npm/envio/src/PgStorage.res Added ~pgUser parameter to makeInitializeTransaction and make; updated grant logic.
codegenerator/cli/templates/static/codegen/src/Config.res Updated call to PgStorage.make to pass ~pgUser=Env.Db.user.
scenarios/test_codegen/test/lib_tests/EntityHistory_test.res Updated all PgStorage.make calls to include ~pgUser="postgres".
scenarios/test_codegen/test/lib_tests/PgStorage_test.res Updated all PgStorage.makeInitializeTransaction calls to include ~pgUser="postgres".

Poem

A schema grant, once hard and fast,
Now takes a user, set at last!
From tests to config, the change flows through,
Dynamic users—flexible, new.
The rabbit hops with joyful cheer,
For code that’s clearer, far and near!
🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
codegenerator/cli/npm/envio/src/PgStorage.res (1)

55-63: Signature updated but not documented

makeInitializeTransaction now requires ~pgUser, yet the file header / doc-comments were not updated. Adding a one-liner explaining the new argument will prevent misuse.

scenarios/test_codegen/test/lib_tests/EntityHistory_test.res (1)

240-243: Avoid magic strings for pgUser in tests

"postgres" is duplicated in several tests. Define once:

let pgUser = "postgres"

and reuse to keep refactors trivial.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af96efd and 7e0e396.

⛔ Files ignored due to path filters (1)
  • scenarios/test_codegen/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • codegenerator/cli/npm/envio/src/PgStorage.res (4 hunks)
  • codegenerator/cli/templates/static/codegen/src/Config.res (1 hunks)
  • scenarios/test_codegen/test/lib_tests/EntityHistory_test.res (4 hunks)
  • scenarios/test_codegen/test/lib_tests/PgStorage_test.res (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (3)
codegenerator/cli/templates/static/codegen/src/Config.res (1)

88-89: Parameter correctly propagated – looks good

Passing ~pgUser=Env.Db.user forwards the new mandatory parameter without hard-wiring the role. No further issues spotted here.

codegenerator/cli/npm/envio/src/PgStorage.res (1)

151-168: API surface changed – consider version bump

make is now a breaking change (new required param). Down-stream packages importing this module will fail to compile. Recommend bumping the minor version (or major if semver is strictly followed) and updating changelog.

scenarios/test_codegen/test/lib_tests/PgStorage_test.res (1)

115-118: Expected SQL must follow quoting decision

If the production code is updated to quote pgUser, remember to mirror it here:

-CREATE SCHEMA "test_schema";GRANT ALL ON SCHEMA "test_schema" TO postgres;
+CREATE SCHEMA "test_schema";GRANT ALL ON SCHEMA "test_schema" TO "postgres";

Failing to align tests will cause brittle failures.

Comment on lines +79 to 81
`GRANT ALL ON SCHEMA "${pgSchema}" TO ${pgUser};
GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Quote pgUser to avoid SQL-injection & case-sensitivity pitfalls

pgUser is injected unquoted, which:

  1. Breaks when the role contains caps or special chars.
  2. Opens a minor injection vector if the env var is ever user-supplied.

A minimal, safe fix:

-    `GRANT ALL ON SCHEMA "${pgSchema}" TO ${pgUser};
+    `GRANT ALL ON SCHEMA "${pgSchema}" TO "${pgUser}";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`GRANT ALL ON SCHEMA "${pgSchema}" TO ${pgUser};
GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
)
`GRANT ALL ON SCHEMA "${pgSchema}" TO "${pgUser}";
GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
)
🤖 Prompt for AI Agents
In codegenerator/cli/npm/envio/src/PgStorage.res around lines 79 to 81, the
variable pgUser is injected into the SQL string without quotes, which risks SQL
injection and breaks if the role contains uppercase letters or special
characters. Fix this by wrapping pgUser in double quotes within the SQL string
to ensure proper quoting and prevent injection vulnerabilities.

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