mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 14:01:24 +00:00
chore: update postgres profile
This commit is contained in:
parent
47346182f0
commit
d4c7de3916
@ -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
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@ -72,16 +71,6 @@ func (d *DB) Migrate(ctx context.Context) error {
|
||||
|
||||
if version.IsVersionGreaterThan(version.GetSchemaVersion(currentVersion), latestMigrationHistoryVersion) {
|
||||
minorVersionList := getMinorVersionList()
|
||||
// backup the raw database file before migration
|
||||
rawBytes, err := os.ReadFile(d.profile.DSN)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read raw database file")
|
||||
}
|
||||
backupDBFilePath := fmt.Sprintf("%s/memos_%s_%d_backup.db", d.profile.Data, d.profile.Version, time.Now().Unix())
|
||||
if err := os.WriteFile(backupDBFilePath, rawBytes, 0644); err != nil {
|
||||
return errors.Wrap(err, "failed to write raw database file")
|
||||
}
|
||||
println("succeed to copy a backup database file")
|
||||
println("start migrate")
|
||||
for _, minorVersion := range minorVersionList {
|
||||
normalizedVersion := minorVersion + ".0"
|
||||
@ -93,11 +82,6 @@ func (d *DB) Migrate(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
println("end migrate")
|
||||
|
||||
// remove the created backup db file after migrate succeed
|
||||
if err := os.Remove(backupDBFilePath); err != nil {
|
||||
println(fmt.Sprintf("Failed to remove temp database file, err %v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user