MCPcopy Index your code
hub / github.com/dnote/dnote / Legacy

Function Legacy

pkg/cli/migrate/legacy.go:91–115  ·  view source on GitHub ↗

Legacy performs migration on JSON-based dnote if necessary

(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

89
90// Legacy performs migration on JSON-based dnote if necessary
91func 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

Callers 1

InitFunction · 0.92

Calls 5

FileExistsFunction · 0.92
DebugFunction · 0.92
getSchemaPathFunction · 0.85
getUnrunMigrationsFunction · 0.85
performMigrationFunction · 0.85

Tested by

no test coverage detected