Skip to content

Commit

Permalink
harmonydb safety
Browse files Browse the repository at this point in the history
  • Loading branch information
snadrus committed Mar 20, 2024
1 parent 81e65db commit 32efba7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/harmony/harmonydb/harmonydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (db *DB) upgrade() error {
if len(dir) == 0 {
logger.Error("No sql files found.")
}
last := ""
for _, e := range dir {
name := e.Name()
if !strings.HasSuffix(name, ".sql") {
Expand All @@ -273,6 +274,9 @@ func (db *DB) upgrade() error {
logger.Debug("DB Schema " + name + " already applied.")
continue
}
if last[:8] == name[:8] {
return xerrors.Errorf("Two files have the same date prefix: " + last + " and " + name)
}
file, err := fs.ReadFile("sql/" + name)
if err != nil {
logger.Error("weird embed file read err")
Expand All @@ -296,6 +300,7 @@ func (db *DB) upgrade() error {
logger.Error("Cannot update base: " + err.Error())
return xerrors.Errorf("cannot insert into base: %w", err)
}
last = name
}
return nil
}

0 comments on commit 32efba7

Please sign in to comment.