feat: enable URL-safe encoding for DB passwords with special characters
closes #541
Summary by CodeRabbit
-
Bug Fixes
- Improved validation for required database environment variables, ensuring the app fails to start if any are missing.
- Enhanced handling of special characters in database passwords for more reliable connections.
-
Chores
- Updated database connection string prefix for compatibility and standards compliance.
Walkthrough
The changes introduce explicit validation for required database-related environment variables (DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME) in three server-side modules. Each module now checks for the presence of these variables before constructing the PostgreSQL connection string, throwing an error if any are missing. The connection string prefix is standardized to postgresql://, and the database password is URL-encoded using encodeURIComponent to safely handle special characters. No modifications were made to exported or public entity declarations.
Changes
| File(s) | Change Summary |
|---|---|
| server/src/pgboss-worker.ts, server/src/schedule-worker.ts, server/src/storage/db.ts | Added explicit checks for required DB environment variables, throw error if missing; switched connection string to postgresql://; URL-encoded DB password with encodeURIComponent. |
Suggested labels
Type: Infra
Poem
A bunny hopped near database land,
Checked the env vars, gave errors on demand.
With passwords encoded, no secrets will leak,
The connection string's stronger, no longer weak.
"postgresql://" is now the way,
Robust and secureβhip hip hooray!
ππ
[!TIP]
β‘π¬ Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 0f472ca2aeb73312be869b6a61648aeb60c1e069 and dcf4969fbf0426e581c23ca891f447f4b68b0107.
π Files selected for processing (3)
-
server/src/pgboss-worker.ts(2 hunks) -
server/src/schedule-worker.ts(1 hunks) -
server/src/storage/db.ts(2 hunks)
π Additional comments (8)
server/src/storage/db.ts (3)
6-9: Good addition of environment variable validation.This validation ensures that the application fails fast with a clear error message if any required database configuration variables are missing, rather than failing with a cryptic error later.
10-10: Great security improvement with URL-encoding for passwords.Using
encodeURIComponenton the password properly handles special characters that would otherwise cause issues in the connection string. This is particularly important for secure passwords that often include special characters.
49-49: LGTM for the default export.The default export of the sequelize instance is retained, maintaining compatibility with the existing codebase.
server/src/pgboss-worker.ts (3)
24-27: Good validation with contextual error message.Adding validation for required environment variables with a specific error message related to the PgBoss worker provides better error context and helps with troubleshooting.
28-28: Consistent connection string format with proper password encoding.The connection string now uses the standardized
postgresql://prefix and properly URL-encodes the password withencodeURIComponent(), ensuring compatibility with special characters in passwords.
529-529: LGTM for the PgBoss export.The export of the PgBoss instance is retained, maintaining compatibility with the existing codebase.
server/src/schedule-worker.ts (2)
10-13: Good addition of environment variable validation.This validation ensures that the schedule worker fails with a clear error message if any required database configuration variables are missing, improving the robustness of the application.
14-14: Consistent connection string format with proper password encoding.The connection string now uses the standardized
postgresql://prefix (instead ofpostgres://) and properly URL-encodes the password usingencodeURIComponent(). This ensures compatibility with special characters in database passwords across all components of the system.
β¨ Finishing Touches
- [ ] π Generate Docstrings
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.
πͺ§ 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. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin 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 generate unit testing code. -
@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.
-
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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
@amhsirak LGTM