-
Notifications
You must be signed in to change notification settings - Fork 526
Make authentication database path configurable via DATABASE_PATH environment variable #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add DATABASE_PATH environment variable support in db.js - Automatically create database directory if custom path is provided - Update .env.example with DATABASE_PATH documentation for container deployments - Maintain backward compatibility with default path (server/database/auth.db) Co-authored-by: werdnum <271070+werdnum@users.noreply.github.com>
WalkthroughAdds a commented DATABASE CONFIGURATION block to Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant Env as Environment
participant DBM as DB Module
participant FS as File System
participant Log as Logger
participant DB as DB Client
App->>DBM: initialize()
DBM->>Env: read DATABASE_PATH
Env-->>DBM: value or undefined
rect rgba(200,230,255,0.35)
note right of DBM: Pre-connection setup
alt DATABASE_PATH is set
DBM->>FS: ensure parent dir exists (mkdir -p)
FS-->>DBM: ok
DBM->>Log: "Created/verified DB dir for custom path"
else default path
DBM->>Log: "Using default DB path"
end
end
rect rgba(220,255,220,0.35)
note right of DBM: Connect
DBM->>Log: "Connecting to DB at <resolved path>"
DBM->>DB: connect(resolvedPath)
DB-->>DBM: ready
DBM-->>App: db handle
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/database/db.js (1)
14-21
: Consider using async fs operations for consistency.The synchronous
fs.existsSync
andfs.mkdirSync
operations block the event loop during startup. While this is acceptable for one-time initialization, using async operations would be more consistent with the existinginitializeDatabase
function and Node.js best practices.If you'd like to refactor to async operations, you could create a setup function:
// After imports const setupDatabase = async () => { // Ensure database directory exists if custom path is provided if (process.env.DATABASE_PATH) { const dbDir = path.dirname(DB_PATH); try { await fs.promises.mkdir(dbDir, { recursive: true }); console.log(`Created database directory: ${dbDir}`); } catch (error) { if (error.code !== 'EEXIST') { console.error(`Failed to create database directory ${dbDir}:`, error.message); throw error; } } } }; // Then call it before database operations await setupDatabase();Note: This would require refactoring how the module is initialized.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.env.example
(1 hunks)server/database/db.js
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
server/database/db.js (1)
server/index.js (3)
path
(975-975)__dirname
(9-9)fs
(976-976)
🔇 Additional comments (3)
.env.example (1)
16-25
: LGTM!The DATABASE CONFIGURATION documentation is clear, concise, and provides helpful examples for different deployment scenarios (default, Docker). The note about persistent volumes for containers is particularly valuable.
server/database/db.js (2)
10-11
: LGTM!The environment variable reading with fallback to the default path is clean and maintains backward compatibility as stated in the PR objectives.
25-25
: LGTM!The enhanced logging that shows the actual database path is a useful improvement for debugging and observability, especially when troubleshooting configuration issues in different environments.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary
The authentication database path is now configurable via the
DATABASE_PATH
environment variable, enabling persistent data storage across container restarts and flexible deployment scenarios.Problem
Previously, the authentication database path was hardcoded to
server/database/auth.db
. This created issues for containerized deployments where:Solution
Added support for the
DATABASE_PATH
environment variable with the following features:✅ Configurable Path
The database location can now be set via environment variable:
✅ Automatic Directory Creation
If a custom path is provided, the database directory is automatically created:
✅ Backward Compatible
No changes required for existing deployments - defaults to
server/database/auth.db
whenDATABASE_PATH
is not set.✅ Enhanced Logging
The actual database path is now logged on startup for easier debugging:
Usage
Docker Deployment
Docker Compose
Local Development
Add to
.env
file:Testing
All functionality has been thoroughly tested:
Files Changed
server/database/db.js
- Added environment variable support and directory creation logic.env.example
- Documented the newDATABASE_PATH
variable with examplesMigration Guide
For existing deployments: No changes needed.
For container deployments wanting persistence:
DATABASE_PATH
environment variableThe database will be created at the new location on first startup.
Original prompt
Summary by CodeRabbit
New Features
Documentation