3
0

Simplify migration source requirements

Remove the need of stream seeking.
This commit is contained in:
Tomaž Jerman
2020-03-01 20:52:29 +01:00
parent 8b82eaee1d
commit 440cf71798
2 changed files with 5 additions and 3 deletions
+4 -2
View File
@@ -46,7 +46,6 @@ func Migrate(mg []types.Migrateable, ns *cct.Namespace, ctx context.Context) err
}
uMap, err := migrateUsers(mgUsr, ns, ctx)
mgUsr.Source.Seek(0, 0)
if err != nil {
return err
}
@@ -237,7 +236,9 @@ func migrateUsers(mg types.Migrateable, ns *cct.Namespace, ctx context.Context)
mapping := make(map[string]uint64)
// get fields
r := csv.NewReader(mg.Source)
var srcBuf bytes.Buffer
tee := io.TeeReader(mg.Source, &srcBuf)
r := csv.NewReader(tee)
header, err := r.Read()
if err != nil {
return nil, err
@@ -319,5 +320,6 @@ func migrateUsers(mg types.Migrateable, ns *cct.Namespace, ctx context.Context)
mapping[record[0]] = u.ID
}
mg.Source = &srcBuf
return mapping, nil
}
+1 -1
View File
@@ -13,6 +13,6 @@ type (
Name string
Path string
Source io.ReadSeeker
Source io.Reader
}
)