2021-06-20 19:46:57 +00:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
2021-07-24 04:28:05 +00:00
|
|
|
"context"
|
|
|
|
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2021-06-20 19:46:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var oldSequences = map[string]string{
|
2021-07-28 02:47:38 +00:00
|
|
|
kv.EthTx: "eth_tx",
|
2021-06-20 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var fixSequences = Migration{
|
|
|
|
Name: "fix_sequences",
|
2021-07-28 02:47:38 +00:00
|
|
|
Up: func(db kv.RwDB, tmpdir string, progress []byte, BeforeCommit Callback) (err error) {
|
2021-07-24 04:28:05 +00:00
|
|
|
tx, err := db.BeginRw(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2021-06-20 19:46:57 +00:00
|
|
|
for bkt, oldbkt := range oldSequences {
|
2021-07-28 02:47:38 +00:00
|
|
|
seq, getErr := tx.GetOne(kv.Sequence, []byte(oldbkt))
|
2021-06-20 19:46:57 +00:00
|
|
|
if getErr != nil {
|
|
|
|
return getErr
|
|
|
|
}
|
|
|
|
|
|
|
|
if seq != nil {
|
2021-07-28 02:47:38 +00:00
|
|
|
putErr := tx.Put(kv.Sequence, []byte(bkt), seq)
|
2021-06-20 19:46:57 +00:00
|
|
|
if putErr != nil {
|
|
|
|
return putErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 04:28:05 +00:00
|
|
|
if err := BeforeCommit(tx, nil, true); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return tx.Commit()
|
2021-06-20 19:46:57 +00:00
|
|
|
},
|
|
|
|
}
|