Skip to content

feat(database): add getConnectionString method#652

Merged
eduardoboucas merged 1 commit intomainfrom
feat/getconnectionstring
Apr 14, 2026
Merged

feat(database): add getConnectionString method#652
eduardoboucas merged 1 commit intomainfrom
feat/getconnectionstring

Conversation

@eduardoboucas
Copy link
Copy Markdown
Member

No description provided.

@eduardoboucas eduardoboucas requested a review from a team as a code owner April 14, 2026 09:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a utility to retrieve and validate database connection configuration.
    • Enhanced error handling to alert when database configuration is missing.
  • Tests

    • Updated and expanded test coverage for database connection initialization and validation scenarios.

Walkthrough

A new getConnectionString() helper function is exported from the database module that reads the NETLIFY_DB_URL environment variable and throws MissingDatabaseConnectionError if absent. The test suite is updated to import this helper, extract connection string values into shared constants, and add a dedicated test block that verifies the helper returns the expected value when the environment variable is set and throws the appropriate error when it is not.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether it relates to the changeset. Add a pull request description explaining the purpose, motivation, or use case for the new getConnectionString method and how it relates to the existing getDatabase function.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a new getConnectionString method to the database package, which is confirmed by the raw summary showing the addition of this exported helper function.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/getconnectionstring

Comment @coderabbitai help to get the list of available commands and usage tips.

@eduardoboucas eduardoboucas enabled auto-merge (squash) April 14, 2026 09:32
Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (1)
packages/database/prod/src/main.ts (1)

39-48: Consider using this helper inside getDatabase() to avoid logic drift.

Line 40 to Line 47 now duplicates connection-string resolution/validation logic that also exists in getDatabase(). Wiring getDatabase() through this helper for the env path would keep a single source of truth.

♻️ Suggested refactor
 export function getDatabase(options: GetDatabaseOptions = {}): DatabaseConnection {
-  const env = getEnvironment()
-  const connectionString = options.connectionString ?? env.get('NETLIFY_DB_URL')
-
-  if (!connectionString) {
-    throw new MissingDatabaseConnectionError()
-  }
+  const env = getEnvironment()
+  const connectionString = options.connectionString ?? getConnectionString()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/database/prod/src/main.ts` around lines 39 - 48, The
connection-string resolution in getDatabase() is duplicated; refactor
getDatabase() to call the existing getConnectionString() helper instead of
re-reading the env or duplicating validation. Update getDatabase() to use
getEnvironment() only inside getConnectionString(), remove any NETLIFY_DB_URL
lookup/throw in getDatabase(), and ensure MissingDatabaseConnectionError remains
the single failure path so all callers rely on getConnectionString() for the
env.get('NETLIFY_DB_URL') logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/database/prod/src/main.ts`:
- Around line 39-48: The connection-string resolution in getDatabase() is
duplicated; refactor getDatabase() to call the existing getConnectionString()
helper instead of re-reading the env or duplicating validation. Update
getDatabase() to use getEnvironment() only inside getConnectionString(), remove
any NETLIFY_DB_URL lookup/throw in getDatabase(), and ensure
MissingDatabaseConnectionError remains the single failure path so all callers
rely on getConnectionString() for the env.get('NETLIFY_DB_URL') logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b97063b-9eed-4789-b67b-12459485d113

📥 Commits

Reviewing files that changed from the base of the PR and between bdb9264 and af7019b.

📒 Files selected for processing (2)
  • packages/database/prod/src/main.test.ts
  • packages/database/prod/src/main.ts

@eduardoboucas eduardoboucas merged commit 9a65377 into main Apr 14, 2026
18 checks passed
@eduardoboucas eduardoboucas deleted the feat/getconnectionstring branch April 14, 2026 09:49
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.

3 participants