Skip to content

refactor: Refactors AAI PostgreSQL fallback configuration (#541) - #542

Merged
ct3685 merged 1 commit into
productionfrom
staging
Sep 15, 2025
Merged

refactor: Refactors AAI PostgreSQL fallback configuration (#541)#542
ct3685 merged 1 commit into
productionfrom
staging

Conversation

@ct3685

@ct3685 ct3685 commented Sep 15, 2025

Copy link
Copy Markdown

Summary

Refactors AAI PostgreSQL fallback configuration to use individual variable fallbacks instead of all-or-nothing HOST checks, making it more flexible and concise.

Changes

  • Replace conditional blocks with ||= logical assignment operator for cleaner syntax
  • Provide individual fallbacks for each database variable (HOST, PORT, DATABASE, USER, PASSWORD)
  • Reduce code from 24 lines to 16 lines while improving functionality

Problem Solved

Previously, AAI service fallbacks only worked if the entire HOST variable was missing. This meant:

  • If AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOST was set but AAI_DEFAULT_POSTGRES_RECORDMANAGER_PORT was missing, no fallback would occur
  • Users couldn't selectively override individual variables while keeping others as defaults

Benefits

  • More flexible: Each variable can now have its own fallback
  • More concise: 33% reduction in lines of code
  • Modern syntax: Uses ES2021 ||= operator
  • Better maintainability: Clearer intent and easier to modify
  • Same precedence: Maintains existing precedence order (Individual AAI secrets > Individual AAI variables > Shared DATABASE_SECRET)

Testing

  • Linting passes
  • No breaking changes to existing functionality
  • Maintains backward compatibility

Type of Change

  • Refactor (non-breaking change that improves code quality)

## Summary
Refactors AAI PostgreSQL fallback configuration to use individual
variable fallbacks instead of all-or-nothing HOST checks, making it more
flexible and concise.

## Changes
- Replace conditional blocks with `||=` logical assignment operator for
cleaner syntax
- Provide individual fallbacks for each database variable (HOST, PORT,
DATABASE, USER, PASSWORD)
- Reduce code from 24 lines to 16 lines while improving functionality

## Problem Solved
Previously, AAI service fallbacks only worked if the entire HOST
variable was missing. This meant:
- If `AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOST` was set but
`AAI_DEFAULT_POSTGRES_RECORDMANAGER_PORT` was missing, no fallback would
occur
- Users couldn't selectively override individual variables while keeping
others as defaults

## Benefits
- ✅ **More flexible**: Each variable can now have its own fallback
- ✅ **More concise**: 33% reduction in lines of code  
- ✅ **Modern syntax**: Uses ES2021 `||=` operator
- ✅ **Better maintainability**: Clearer intent and easier to modify
- ✅ **Same precedence**: Maintains existing precedence order (Individual
AAI secrets > Individual AAI variables > Shared DATABASE_SECRET)

## Testing
- [x] Linting passes
- [x] No breaking changes to existing functionality
- [x] Maintains backward compatibility

## Type of Change
- [x] Refactor (non-breaking change that improves code quality)
@vercel

vercel Bot commented Sep 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
answerai-docs Building Building Preview Sep 15, 2025 7:03pm
the-answerai Building Building Preview Sep 15, 2025 7:03pm

@ct3685
ct3685 merged commit ba63e09 into production Sep 15, 2025
5 of 8 checks passed
@maxtechera
maxtechera temporarily deployed to staging - theanswer-iek0 September 15, 2025 19:03 — with Render Inactive
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