1
0
Fork 0

Check FK state before load

master
Philip O Toole 8 years ago
parent 4c6ee1ad39
commit 31560160a1

@ -2,6 +2,7 @@ package http
import (
"fmt"
"io"
"net/http"
"testing"
@ -392,6 +393,10 @@ func (m *MockStore) Backup(leader bool) ([]byte, error) {
return nil, nil
}
func (m *MockStore) Load(r io.Reader) (int64, error) {
return 0, nil
}
type mockCredentialStore struct {
CheckOK bool
HasPermOK bool

@ -442,6 +442,15 @@ func (s *Store) Load(r io.Reader) (int64, error) {
return 0, ErrNotLeader
}
// Disable FK constraints for loading.
currFK, err := s.db.FKConstraints()
if err != nil {
return 0, err
}
if err := s.db.EnableFKConstraints(false); err != nil {
return 0, err
}
// Read the dump, executing the commands.
var n int64
buf := bufio.NewReader(r)
@ -469,6 +478,10 @@ func (s *Store) Load(r io.Reader) (int64, error) {
n += int64(len(queries))
}
// Restore FK constraints to starting state.
if err := s.db.EnableFKConstraints(currFK); err != nil {
return n, err
}
return n, nil
}

Loading…
Cancel
Save