MCPcopy Index your code
hub / github.com/riverqueue/river / validateAndInit

Function validateAndInit

rivermigrate/river_migrate.go:868–898  ·  view source on GitHub ↗

Validates and fully initializes a set of migrations to reduce the probability of configuration problems as new migrations are introduced. e.g. Checks for missing fields or accidentally duplicated version numbers from copy/pasta problems.

(versions []Migration)

Source from the content-addressed store, hash-verified

866// missing fields or accidentally duplicated version numbers from copy/pasta
867// problems.
868func validateAndInit(versions []Migration) map[int]Migration {
869 lastVersion := 0
870 migrations := make(map[int]Migration, len(versions))
871
872 for _, versionBundle := range versions {
873 if versionBundle.SQLDown == "" {
874 panic(fmt.Sprintf("version bundle should specify Down: %+v", versionBundle))
875 }
876 if versionBundle.SQLUp == "" {
877 panic(fmt.Sprintf("version bundle should specify Up: %+v", versionBundle))
878 }
879 if versionBundle.Version == 0 {
880 panic(fmt.Sprintf("version bundle should specify Version: %+v", versionBundle))
881 }
882
883 if _, ok := migrations[versionBundle.Version]; ok {
884 panic(fmt.Sprintf("duplicate version: %03d", versionBundle.Version))
885 }
886 if versionBundle.Version <= lastVersion {
887 panic(fmt.Sprintf("versions should be ascending; current: %03d, last: %03d", versionBundle.Version, lastVersion))
888 }
889 if versionBundle.Version > lastVersion+1 {
890 panic(fmt.Sprintf("versions shouldn't skip a sequence number; current: %03d, last: %03d", versionBundle.Version, lastVersion))
891 }
892
893 lastVersion = versionBundle.Version
894 migrations[versionBundle.Version] = versionBundle
895 }
896
897 return migrations
898}

Callers 2

NewFunction · 0.85

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…