refactor: replace hardcoded 'env-default' strings with ENV_DEFAULT_ID#156
refactor: replace hardcoded 'env-default' strings with ENV_DEFAULT_ID#156Vswaroop04 wants to merge 3 commits into
Conversation
|
All contributors have signed the CLA. ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
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 |
|
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:
// apps/api/src/connections/connection.constants.ts 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.
String interpolation in SQL is the injection pattern regardless of whether the value is currently safe. Please use a parameterized query: pool.query(
The commit 130c0e4 is not GPG-signed. |
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.
130c0e4 to
9836dc7
Compare
- 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
|
Hey @Vswaroop04 all three issues from the first review are cleanly addressed, thanks for the quick turnaround. One last connection-registry.service.spec.ts still imports ENV_DEFAULT_ID from '../connection-registry.service' (the re-export) // current // preferred 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. |
e27eb94 to
0a60b17
Compare
Summary
TODOcomment fromconnection-registry.service.ts(the constant was already defined but not consistently used)ENV_DEFAULT_IDin:connections.dto.ts(Swagger example values)connection-registry.service.spec.ts(test fixtures)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
pnpm testand verify all existing registry tests pass'env-default'string literals in application code (excluding SQL schema and migration strings)