InitSystem inserts system data if missing
(ctx context.DnoteCtx)
| 267 | |
| 268 | // InitSystem inserts system data if missing |
| 269 | func 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. |
no test coverage detected