Repository navigation
feat(config): Automatically create directory for SQLite database - #158
Merged
Merged
Conversation
Contributor
Reviewer's GuideIn GetDSN(), the sqlite branch now auto-creates the parent directory for the database file using os.MkdirAll and immediately panics with a clear error if directory creation fails, preventing obscure file-open errors later. Sequence diagram for SQLite DSN retrieval with directory creationsequenceDiagram
participant App as Application
participant Config as DatabaseConfig
participant OS as Operating System
App->>Config: GetDSN()
Config->>OS: MkdirAll(parentDir(DBName), 0755)
alt Directory creation succeeds
Config-->>App: Return DBName
else Directory creation fails
Config-->>App: Panic with error
end
Class diagram for updated DatabaseConfig.GetDSN() logicclassDiagram
class DatabaseConfig {
+string DBType
+string DBName
+GetDSN() string
}
DatabaseConfig : +GetDSN() now creates parent dir for SQLite
DatabaseConfig : +GetDSN() panics if MkdirAll fails
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey @kerwin612 - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://github.com/AmoyLab/docs/blob/f4df89dc3069e78a6d7cc247494ff43806ef7a6d/docs/development/local-development.md?plain=1#L59-L61
Unla/.env.example
Line 31 in 62eb078
Currently, when the application is configured to use SQLite, it fails to start if the directory for the database file (e.g., data/unla.db) does not exist. The application is unable to create the database file, and the user must manually create the parent directory (data/) to resolve the issue.
To improve usability and adhere to the "fail-fast" principle, this PR enhances the database configuration logic.
Within the (c *DatabaseConfig) GetDSN() function, for the sqlite case, the application now ensures the parent directory for the database file exists by attempting to create it with os.MkdirAll. If directory creation fails (e.g., due to a permissions issue), the application will panic immediately with a descriptive error message. This prevents a more obscure error from appearing later when the database driver attempts to open the file.
Summary by Sourcery
Enhancements: