1
0
Fork 0
Philip O'Toole 8 months ago
parent 40196c7f0e
commit f47aa4117e

@ -25,7 +25,9 @@ func OpenSwappable(dbPath string, fkEnabled, wal bool) (*SwappableDB, error) {
return &SwappableDB{db: db}, nil
}
// Swap swaps the underlying database with that at the given path.
// Swap swaps the underlying database with that at the given path. The Swap operation
// may fail on some platforms if the file at path is open by another process. It is
// the caller's responsibility to ensure the file at path is not in use.
func (s *SwappableDB) Swap(path string, fkConstraints, walEnabled bool) error {
if !IsValidSQLiteFile(path) {
return fmt.Errorf("invalid SQLite data")

@ -75,6 +75,9 @@ func Test_SwapSuccess(t *testing.T) {
defer swappableDB.Close()
// Perform the swap
if err := srcDB.Close(); err != nil {
t.Fatalf("failed to close source database pre-swap: %s", err)
}
if err := swappableDB.Swap(srcPath, false, false); err != nil {
t.Fatalf("failed to swap database: %s", err)
}

Loading…
Cancel
Save