Skip to content

Commit

Permalink
skip migrations for new installs
Browse files Browse the repository at this point in the history
  • Loading branch information
radulucut committed Oct 31, 2024
1 parent ded6df8 commit e330d98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 4 additions & 7 deletions storage/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import (
type MigrationFunc func() error

func (s *LocalStorage) Migrate() error {
migrations := []MigrationFunc{
s.UpdateSessionDir,
}
if s.config.LastMigration >= len(migrations) {
if s.config.LastMigration >= len(s.migrations) {
return nil
}
for i := s.config.LastMigration; i < len(migrations); i++ {
err := migrations[i]()
for i := s.config.LastMigration; i < len(s.migrations); i++ {
err := s.migrations[i]()
if err != nil {
fmt.Printf("Warning: migration %d failed: %v", i, err)
}
}
s.config.LastMigration = len(migrations)
s.config.LastMigration = len(s.migrations)
return s.SaveConfig()
}

Expand Down
11 changes: 9 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type LocalStorage struct {
sessionsDir string
currentSessionDir string
config *Config

migrations []MigrationFunc
}

func NewLocalStorage(utils utils.Utils) *LocalStorage {
Expand All @@ -31,6 +33,10 @@ func NewLocalStorage(utils utils.Utils) *LocalStorage {
}

func (s *LocalStorage) Init(dirName string) error {
s.migrations = []MigrationFunc{
s.UpdateSessionDir,
}

homeDir, err := os.UserHomeDir()
if err != nil {
return err
Expand All @@ -51,8 +57,9 @@ func (s *LocalStorage) Init(dirName string) error {
if err != nil {
if os.IsNotExist(err) {
s.config = &Config{
Profile: "default",
Profiles: make(map[string]*Profile),
Profile: "default",
Profiles: make(map[string]*Profile),
LastMigration: len(s.migrations),
}
s.SaveConfig()
}
Expand Down

0 comments on commit e330d98

Please sign in to comment.