[self-hosted] specify sql file location of auth, activity and main store#5487
[self-hosted] specify sql file location of auth, activity and main store#5487
Conversation
…ocation Entire-Checkpoint: 6025365f10d4
📝 WalkthroughWalkthroughAdds optional SQLite file path configuration for server stores and embedded IdP, wires those values into environment variables during startup, and updates SQLite store initializers to accept and resolve custom file paths (relative to dataDir) and preserve query parameters. Changes
Sequence Diagram(s)sequenceDiagram
participant Config as Config (combined/cmd)
participant Env as Env (process env)
participant Init as Init (token/root)
participant Store as Store (sql_store.go)
participant Activity as ActivityStore (activity/sql_store.go)
Config->>Init: provide Server.Store.File / ActivityStore.File / AuthStore.File
Init->>Env: set NB_STORE_ENGINE_SQLITE_FILE, NB_ACTIVITY_EVENT_SQLITE_FILE
Env->>Store: NB_STORE_ENGINE_SQLITE_FILE read
Store->>Store: resolve path (abs/rel -> dataDir), split query, compose connStr
Store->>Store: sqlite.Open(connStr)
Env->>Activity: NB_ACTIVITY_EVENT_SQLITE_FILE read
Activity->>Activity: resolve path (abs/rel -> dataDir), compose connStr
Activity->>Activity: sqlite.Open(connStr)
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@combined/cmd/config.go`:
- Around line 572-574: The assignment of c.Server.AuthStore.File to
authStorageFile should resolve relative paths against mgmt.DataDir so the auth
DB lives under the management data directory like the other sqlite stores;
update the logic where authStorageFile is set (referencing
c.Server.AuthStore.File and authStorageFile) to check if the value is non-empty
and not an absolute path (use filepath.IsAbs) and if so join it with
mgmt.DataDir (use filepath.Join and optionally filepath.Clean) before assigning;
keep absolute paths unchanged.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
combined/cmd/config.gocombined/cmd/root.gocombined/cmd/token.gocombined/config.yaml.examplemanagement/server/activity/store/sql_store.gomanagement/server/store/sql_store.go
…ocation Entire-Checkpoint: 1f5346444ce6
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
combined/cmd/config.go (1)
572-578: Inconsistent use ofpathvsfilepathfor filesystem paths.Line 572 uses
path.Joinwhile line 576 usesfilepath.Join. Thepathpackage uses forward slashes unconditionally (POSIX-style), whilefilepathuses OS-native separators. For filesystem operations,filepathshould be used consistently to ensure Windows compatibility.♻️ Proposed fix for consistency
- authStorageFile = path.Join(mgmt.DataDir, "idp.db") + authStorageFile = filepath.Join(mgmt.DataDir, "idp.db") if c.Server.AuthStore.File != "" { authStorageFile = c.Server.AuthStore.File if !filepath.IsAbs(authStorageFile) { authStorageFile = filepath.Join(mgmt.DataDir, authStorageFile) } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@combined/cmd/config.go` around lines 572 - 578, The code uses path.Join to build authStorageFile but elsewhere uses filepath.Join; replace path.Join(mgmt.DataDir, "idp.db") with filepath.Join(mgmt.DataDir, "idp.db") so all filesystem joins use the OS-aware filepath package (ensure the filepath import is present and remove the unused path import if it becomes unused); keep the rest of the logic that overrides authStorageFile from c.Server.AuthStore.File unchanged (the symbols to look for are authStorageFile, mgmt.DataDir, and c.Server.AuthStore.File).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@combined/cmd/config.go`:
- Around line 572-578: The code uses path.Join to build authStorageFile but
elsewhere uses filepath.Join; replace path.Join(mgmt.DataDir, "idp.db") with
filepath.Join(mgmt.DataDir, "idp.db") so all filesystem joins use the OS-aware
filepath package (ensure the filepath import is present and remove the unused
path import if it becomes unused); keep the rest of the logic that overrides
authStorageFile from c.Server.AuthStore.File unchanged (the symbols to look for
are authStorageFile, mgmt.DataDir, and c.Server.AuthStore.File).



Describe your changes
Allows specifying custom SQLite file paths via store.file, activityStore.file, and authStore.file in the combined server config. Without this, all SQLite databases are
hardcoded to {dataDir}/store.db, {dataDir}/events.db, and {dataDir}/idp.db respectively.
The combined server propagates the file paths to the underlying store packages via NB_STORE_ENGINE_SQLITE_FILE and NB_ACTIVITY_EVENT_SQLITE_FILE env vars (matching the
existing DSN env var pattern). The auth store file is passed directly through the embedded IdP config.
Both absolute paths and SQLite URI query parameters (e.g., ?cache=shared) are supported.
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit
New Features
Documentation