chore: update postgres profile

This commit is contained in:
Steven
2023-12-19 08:59:07 +08:00
parent 47346182f0
commit d4c7de3916
2 changed files with 13 additions and 25 deletions

View File

@ -34,7 +34,7 @@ func (p *Profile) IsDev() bool {
return p.Mode != "prod"
}
func checkDSN(dataDir string) (string, error) {
func checkDataDir(dataDir string) (string, error) {
// Convert to absolute path if relative path is supplied.
if !filepath.IsAbs(dataDir) {
relativeDir := filepath.Join(filepath.Dir(os.Args[0]), dataDir)
@ -82,15 +82,19 @@ func GetProfile() (*Profile, error) {
}
}
dataDir, err := checkDSN(profile.Data)
if err != nil {
fmt.Printf("Failed to check dsn: %s, err: %+v\n", dataDir, err)
return nil, err
}
if profile.Driver == "sqlite" {
dataDir, err := checkDataDir(profile.Data)
if err != nil {
fmt.Printf("Failed to check dsn: %s, err: %+v\n", dataDir, err)
return nil, err
}
profile.Data = dataDir
dbFile := fmt.Sprintf("slash_%s.db", profile.Mode)
profile.DSN = filepath.Join(dataDir, dbFile)
profile.Data = dataDir
if profile.DSN == "" {
dbFile := fmt.Sprintf("slash_%s.db", profile.Mode)
profile.DSN = filepath.Join(dataDir, dbFile)
}
}
profile.Version = version.GetCurrentVersion(profile.Mode)
return &profile, nil