harmonydb safety
This commit is contained in:
parent
81e65dba56
commit
32efba72cf
@ -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") {
|
||||
@ -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")
|
||||
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user