readUp reads up migrations from `from` limitted by `limit`. limit can be -1, implying no limit and reading until there are no more migrations. Each migration is then written to the ret channel. If an error occurs during reading, that error is written to the ret channel, too. Once readUp is done read
(limit int64, ret chan<- interface{}, bar *pb.ProgressBar)
| 1050 | // If an error occurs during reading, that error is written to the ret channel, too. |
| 1051 | // Once readUp is done reading it will close the ret channel. |
| 1052 | func (m *Migrate) readUp(limit int64, ret chan<- interface{}, bar *pb.ProgressBar) { |
| 1053 | defer close(ret) |
| 1054 | |
| 1055 | if limit == 0 { |
| 1056 | ret <- ErrNoChange |
| 1057 | return |
| 1058 | } |
| 1059 | |
| 1060 | if limit == -1 { // To get no of migrations to be applied on server if limit is -1 |
| 1061 | noOfUnappliedMigrations := 0 |
| 1062 | for _, migration := range m.status.Migrations { |
| 1063 | if migration.IsPresent && !migration.IsApplied { // needs to be applied |
| 1064 | noOfUnappliedMigrations++ |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | if noOfUnappliedMigrations == 0 { |
| 1069 | ret <- ErrNoChange |
| 1070 | return |
| 1071 | } |
| 1072 | |
| 1073 | setTotalProgressBar(bar, int64(noOfUnappliedMigrations)) |
| 1074 | } else { |
| 1075 | setTotalProgressBar(bar, limit) |
| 1076 | } |
| 1077 | |
| 1078 | count := int64(0) |
| 1079 | from := int64(-1) |
| 1080 | for count < limit || limit == -1 { |
| 1081 | if m.stop() { |
| 1082 | return |
| 1083 | } |
| 1084 | |
| 1085 | if from == -1 { |
| 1086 | firstVersion, err := m.sourceDrv.First() |
| 1087 | if err != nil { |
| 1088 | ret <- err |
| 1089 | return |
| 1090 | } |
| 1091 | |
| 1092 | // Check if this version present in DB |
| 1093 | ok := m.databaseDrv.Read(firstVersion) |
| 1094 | if ok { |
| 1095 | from = int64(firstVersion) |
| 1096 | continue |
| 1097 | } |
| 1098 | |
| 1099 | // Check if firstVersion files exists (yaml or sql) |
| 1100 | if err = m.versionUpExists(firstVersion); err != nil { |
| 1101 | ret <- err |
| 1102 | return |
| 1103 | } |
| 1104 | |
| 1105 | migr, err := m.newMigration(firstVersion, int64(firstVersion)) |
| 1106 | if err != nil { |
| 1107 | ret <- err |
| 1108 | return |
| 1109 | } |
no test coverage detected