1package goose
2
3import (
4 "errors"
5 "fmt"
6)
7
8var (
9 // ErrVersionNotFound is returned when a specific migration version is not located. This can
10 // occur if a .sql file or a Go migration function for the specified version is missing.
11 ErrVersionNotFound = errors.New("version not found")
12
13 // ErrNoMigrations is returned by [NewProvider] when no migrations are found.
14 ErrNoMigrations = errors.New("no migrations found")
15
16 // ErrAlreadyApplied indicates that the migration cannot be applied because it has already been
17 // executed. This error is returned by [Provider.Apply].
18 ErrAlreadyApplied = errors.New("migration already applied")
19
20 // ErrNotApplied indicates that the rollback cannot be performed because the migration has not
21 // yet been applied. This error is returned by [Provider.Apply].
22 ErrNotApplied = errors.New("migration not applied")
23
24 // errInvalidVersion is returned when a migration version is invalid.
25 errInvalidVersion = errors.New("version must be greater than 0")
26)
27
28// PartialError is returned when a migration fails, but some migrations already got applied.
29type PartialError struct {
30 // Applied are migrations that were applied successfully before the error occurred. May be
31 // empty.
32 Applied []*MigrationResult
33 // Failed contains the result of the migration that failed. Cannot be nil.
34 Failed *MigrationResult
35 // Err is the error that occurred while running the migration and caused the failure.
36 Err error
37}
38
39func (e *PartialError) Error() string {
40 return fmt.Sprintf(
41 "partial migration error (type:%s,version:%d): %v",
42 e.Failed.Source.Type, e.Failed.Source.Version, e.Err,
43 )
44}
45
46func (e *PartialError) Unwrap() error {
47 return e.Err
48}