Skip to content

refactor: replace hardcoded 'env-default' strings with ENV_DEFAULT_ID#156

Open
Vswaroop04 wants to merge 3 commits into
BetterDB-inc:masterfrom
Vswaroop04:feat/export-env-default-id
Open

refactor: replace hardcoded 'env-default' strings with ENV_DEFAULT_ID#156
Vswaroop04 wants to merge 3 commits into
BetterDB-inc:masterfrom
Vswaroop04:feat/export-env-default-id

Conversation

@Vswaroop04
Copy link
Copy Markdown
Contributor

Summary

  • Removes the stale TODO comment from connection-registry.service.ts (the constant was already defined but not consistently used)
  • Introduces a single source of truth by importing ENV_DEFAULT_ID in:
    • connections.dto.ts (Swagger example values)
    • connection-registry.service.spec.ts (test fixtures)
    • Seed scripts
  • Seed scripts define a local alias with a reference comment to avoid introducing a NestJS dependency in standalone scripts

Why

Previously, renaming the sentinel value required updating 28+ hardcoded string literals across multiple files. This change centralizes the value, making future updates safer and easier.

Note

SQL schema defaults (DEFAULT 'env-default') in SQLite and PostgreSQL adapters are intentionally unchanged. These are database-level literals within migration/template strings, not part of application logic.

Test Plan

  • Run pnpm test and verify all existing registry tests pass
  • Confirm via grep that there are no remaining bare 'env-default' string literals in application code (excluding SQL schema and migration strings)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@Vswaroop04
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 7, 2026
@Vswaroop04
Copy link
Copy Markdown
Contributor Author

Hey @KIvanow 👋

I’ve been playing around with BetterDB and really like what you’re building, especially the MCP integration and semantic cache. While going through the codebase, I came across a few areas that could use some cleanup or improvements and put together a few contributions.

Happy to iterate based on your feedback. No rush at all

@KIvanow
Copy link
Copy Markdown
Member

KIvanow commented May 13, 2026

Hey @Vswaroop04 , thank you so much for the contribution!

Thanks for the clean refactor - the intent is right. A few things to address before this can merge:

  1. Dependency direction in connections.dto.ts
    Importing from connection-registry.service inside a DTO inverts the layering — DTOs should have no knowledge of the service layer. While there's no circular dependency today, this is fragile. The fix is to extract the constant to a dedicated file:

// apps/api/src/connections/connection.constants.ts
export const ENV_DEFAULT_ID = 'env-default';

Then import from there in both the service and the DTO. As a bonus, the seed scripts could also import from this file directly (it has no NestJS dependencies), eliminating the local duplicate copies.

  1. SQL injection pattern in seed-demo-data-pg.ts
    // current
    WHERE connection_id <> '${ENV_DEFAULT_ID}'

String interpolation in SQL is the injection pattern regardless of whether the value is currently safe. Please use a parameterized query:

pool.query(
SELECT connection_id, source_host, source_port FROM command_log_entries WHERE connection_id <> $1 ORDER BY captured_at DESC LIMIT 1,
[ENV_DEFAULT_ID]
)

  1. Unsigned commits

The commit 130c0e4 is not GPG-signed.

@KIvanow KIvanow self-requested a review May 13, 2026 11:09
Removes the TODO from connection-registry.service.ts and propagates the
already-exported ENV_DEFAULT_ID constant to all application-level call
sites. DTOs, the registry spec, and seed scripts now reference the
constant so a future rename only requires one change.

SQL schema DEFAULT clauses in adapter files are left as-is — they are
database-level string literals that cannot reference TypeScript constants.
@Vswaroop04 Vswaroop04 force-pushed the feat/export-env-default-id branch from 130c0e4 to 9836dc7 Compare May 13, 2026 19:12
- Extract ENV_DEFAULT_ID to connection.constants.ts to fix inverted
  dependency (DTO was importing from service layer)
- Update service, DTO, and seed scripts to import from the constants file
- Fix SQL injection pattern in seed-demo-data-pg.ts using parameterized query
@KIvanow
Copy link
Copy Markdown
Member

KIvanow commented May 14, 2026

Hey @Vswaroop04 all three issues from the first review are cleanly addressed, thanks for the quick turnaround. One last
minor thing before this merges:

connection-registry.service.spec.ts still imports ENV_DEFAULT_ID from '../connection-registry.service' (the re-export)
rather than from '../connection.constants' directly:

// current
import { ConnectionRegistry, ENV_DEFAULT_ID } from '../connection-registry.service';

// preferred
import { ConnectionRegistry } from '../connection-registry.service';
import { ENV_DEFAULT_ID } from '../connection.constants';

The re-export works, but it slightly undermines the extraction - the spec is still coupled to the service for a value that now lives independently. A one-line import split fixes it. After that this is good to go.

@Vswaroop04 Vswaroop04 force-pushed the feat/export-env-default-id branch from e27eb94 to 0a60b17 Compare May 14, 2026 20:31
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