MCPcopy
hub / github.com/dnote/dnote / InitSystem

Function InitSystem

pkg/cli/infra/init.go:269–295  ·  view source on GitHub ↗

InitSystem inserts system data if missing

(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

267
268// InitSystem inserts system data if missing
269func InitSystem(ctx context.DnoteCtx) error {
270 log.Debug("initializing the system\n")
271
272 db := ctx.DB
273
274 tx, err := db.Begin()
275 if err != nil {
276 return errors.Wrap(err, "beginning a transaction")
277 }
278
279 nowStr := strconv.FormatInt(time.Now().Unix(), 10)
280 if err := initSystemKV(tx, consts.SystemLastUpgrade, nowStr); err != nil {
281 return errors.Wrapf(err, "initializing system config for %s", consts.SystemLastUpgrade)
282 }
283 if err := initSystemKV(tx, consts.SystemLastMaxUSN, "0"); err != nil {
284 return errors.Wrapf(err, "initializing system config for %s", consts.SystemLastMaxUSN)
285 }
286 if err := initSystemKV(tx, consts.SystemLastSyncAt, "0"); err != nil {
287 return errors.Wrapf(err, "initializing system config for %s", consts.SystemLastSyncAt)
288 }
289
290 if err := tx.Commit(); err != nil {
291 return errors.Wrap(err, "committing transaction")
292 }
293
294 return nil
295}
296
297// getEditorCommand returns the system's editor command with appropriate flags,
298// if necessary, to make the command wait until editor is close to exit.

Callers 2

generateSchemaFunction · 0.92
InitFunction · 0.85

Calls 5

DebugFunction · 0.92
initSystemKVFunction · 0.85
BeginMethod · 0.65
NowMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected