diff options
author | Joe Chen <jc@unknwon.io> | 2022-03-26 15:10:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 15:10:39 +0800 |
commit | f37cd9672cb447cb820e2da5144a25d5d6b654d7 (patch) | |
tree | 8d2acad4a80ed308cad2cc8eb65a79d62c385532 /internal/db | |
parent | 9bce320160a772fb32e8cc5ea612937d8ad6a889 (diff) |
restore: clean up leftover and invalid chars (#6875)
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/backup.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/internal/db/backup.go b/internal/db/backup.go index f4dec721..e03d78c1 100644 --- a/internal/db/backup.go +++ b/internal/db/backup.go @@ -2,6 +2,7 @@ package db import ( "bufio" + "bytes" "fmt" "io" "os" @@ -176,8 +177,11 @@ func importTable(db *gorm.DB, table interface{}, r io.Reader) error { scanner := bufio.NewScanner(r) for scanner.Scan() { + // PostgreSQL does not like the null characters (U+0000) + cleaned := bytes.ReplaceAll(scanner.Bytes(), []byte("\\u0000"), []byte("")) + elem := reflect.New(reflect.TypeOf(table).Elem()).Interface() - err = jsoniter.Unmarshal(scanner.Bytes(), elem) + err = jsoniter.Unmarshal(cleaned, elem) if err != nil { return errors.Wrap(err, "unmarshal JSON to struct") } |