mirror of https://github.com/status-im/migrate.git
Remove unnecessary panics from core implementation
This commit is contained in:
parent
9b449be538
commit
0f8263de2e
|
@ -16,7 +16,7 @@ import (
|
||||||
// Test runs tests against database implementations.
|
// Test runs tests against database implementations.
|
||||||
func Test(t *testing.T, d database.Driver, migration []byte) {
|
func Test(t *testing.T, d database.Driver, migration []byte) {
|
||||||
if migration == nil {
|
if migration == nil {
|
||||||
panic("test must provide migration reader")
|
t.Fatal("test must provide migration reader")
|
||||||
}
|
}
|
||||||
|
|
||||||
TestNilVersion(t, d) // test first
|
TestNilVersion(t, d) // test first
|
||||||
|
@ -46,7 +46,7 @@ func TestLockAndUnlock(t *testing.T, d database.Driver) {
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
panic(fmt.Sprintf("Timeout after 15 seconds. Looks like a deadlock in Lock/UnLock.\n%#v", d))
|
t.Fatal(fmt.Sprintf("Timeout after 15 seconds. Looks like a deadlock in Lock/UnLock.\n%#v", d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -81,7 +81,7 @@ func TestLockAndUnlock(t *testing.T, d database.Driver) {
|
||||||
|
|
||||||
func TestRun(t *testing.T, d database.Driver, migration io.Reader) {
|
func TestRun(t *testing.T, d database.Driver, migration io.Reader) {
|
||||||
if migration == nil {
|
if migration == nil {
|
||||||
panic("migration can't be nil")
|
t.Fatal("migration can't be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.Run(migration); err != nil {
|
if err := d.Run(migration); err != nil {
|
||||||
|
|
14
migrate.go
14
migrate.go
|
@ -5,6 +5,7 @@
|
||||||
package migrate
|
package migrate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -25,10 +26,11 @@ var DefaultPrefetchMigrations = uint(10)
|
||||||
var DefaultLockTimeout = 15 * time.Second
|
var DefaultLockTimeout = 15 * time.Second
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoChange = fmt.Errorf("no change")
|
ErrNoChange = errors.New("no change")
|
||||||
ErrNilVersion = fmt.Errorf("no migration")
|
ErrNilVersion = errors.New("no migration")
|
||||||
ErrLocked = fmt.Errorf("database locked")
|
ErrInvalidVersion = errors.New("version must be >= -1")
|
||||||
ErrLockTimeout = fmt.Errorf("timeout: can't acquire database lock")
|
ErrLocked = errors.New("database locked")
|
||||||
|
ErrLockTimeout = errors.New("timeout: can't acquire database lock")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrShortLimit is an error returned when not enough migrations
|
// ErrShortLimit is an error returned when not enough migrations
|
||||||
|
@ -357,7 +359,7 @@ func (m *Migrate) Run(migration ...*Migration) error {
|
||||||
// It resets the dirty state to false.
|
// It resets the dirty state to false.
|
||||||
func (m *Migrate) Force(version int) error {
|
func (m *Migrate) Force(version int) error {
|
||||||
if version < -1 {
|
if version < -1 {
|
||||||
panic("version must be >= -1")
|
return ErrInvalidVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.lock(); err != nil {
|
if err := m.lock(); err != nil {
|
||||||
|
@ -722,7 +724,7 @@ func (m *Migrate) runMigrations(ret <-chan interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic("unknown type")
|
return fmt.Errorf("unknown type: %T with value: %+v", r, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue