Run performs unrun migrations
(ctx context.DnoteCtx, migrations []migration, mode int)
| 131 | |
| 132 | // Run performs unrun migrations |
| 133 | func Run(ctx context.DnoteCtx, migrations []migration, mode int) error { |
| 134 | schemaKey, err := getSchemaKey(mode) |
| 135 | if err != nil { |
| 136 | return errors.Wrap(err, "getting schema key") |
| 137 | } |
| 138 | |
| 139 | schema, err := getSchema(ctx, schemaKey) |
| 140 | if err != nil { |
| 141 | return errors.Wrap(err, "getting the current schema") |
| 142 | } |
| 143 | |
| 144 | log.Debug("%s: %d of %d\n", schemaKey, schema, len(migrations)) |
| 145 | |
| 146 | toRun := migrations[schema:] |
| 147 | |
| 148 | for _, m := range toRun { |
| 149 | if err := execute(ctx, m, schemaKey); err != nil { |
| 150 | return errors.Wrap(err, "running migration") |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return nil |
| 155 | } |