Legacy performs migration on JSON-based dnote if necessary
(ctx context.DnoteCtx)
| 89 | |
| 90 | // Legacy performs migration on JSON-based dnote if necessary |
| 91 | func Legacy(ctx context.DnoteCtx) error { |
| 92 | // If schema does not exist, no need run a legacy migration |
| 93 | schemaPath := getSchemaPath(ctx) |
| 94 | ok, err := utils.FileExists(schemaPath) |
| 95 | if err != nil { |
| 96 | return errors.Wrap(err, "checking if schema exists") |
| 97 | } |
| 98 | if !ok { |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | unrunMigrations, err := getUnrunMigrations(ctx) |
| 103 | if err != nil { |
| 104 | return errors.Wrap(err, "Failed to get unrun migrations") |
| 105 | } |
| 106 | |
| 107 | for _, mig := range unrunMigrations { |
| 108 | log.Debug("running legacy migration %d\n", mig) |
| 109 | if err := performMigration(ctx, mig); err != nil { |
| 110 | return errors.Wrapf(err, "running migration #%d", mig) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | // performMigration backs up current .dnote data, performs migration, and |
| 118 | // restores or cleans backups depending on if there is an error |
no test coverage detected