migrateToV6 adds a 'public' field to notes
(ctx context.DnoteCtx)
| 744 | |
| 745 | // migrateToV6 adds a 'public' field to notes |
| 746 | func migrateToV6(ctx context.DnoteCtx) error { |
| 747 | notePath := fmt.Sprintf("%s/dnote", ctx.Paths.LegacyDnote) |
| 748 | |
| 749 | b, err := os.ReadFile(notePath) |
| 750 | if err != nil { |
| 751 | return errors.Wrap(err, "Failed to read the note file") |
| 752 | } |
| 753 | |
| 754 | var preDnote migrateToV6PreDnote |
| 755 | postDnote := migrateToV6PostDnote{} |
| 756 | |
| 757 | err = json.Unmarshal(b, &preDnote) |
| 758 | if err != nil { |
| 759 | return errors.Wrap(err, "Failed to unmarshal existing dnote into JSON") |
| 760 | } |
| 761 | |
| 762 | for bookName, book := range preDnote { |
| 763 | var notes = make([]migrateToV6PostNote, 0, len(book.Notes)) |
| 764 | public := false |
| 765 | for _, note := range book.Notes { |
| 766 | newNote := migrateToV6PostNote{ |
| 767 | UUID: note.UUID, |
| 768 | Content: note.Content, |
| 769 | AddedOn: note.AddedOn, |
| 770 | EditedOn: note.EditedOn, |
| 771 | Public: &public, |
| 772 | } |
| 773 | |
| 774 | notes = append(notes, newNote) |
| 775 | } |
| 776 | |
| 777 | b := migrateToV6PostBook{ |
| 778 | Name: bookName, |
| 779 | Notes: notes, |
| 780 | } |
| 781 | |
| 782 | postDnote[bookName] = b |
| 783 | } |
| 784 | |
| 785 | d, err := json.MarshalIndent(postDnote, "", " ") |
| 786 | if err != nil { |
| 787 | return errors.Wrap(err, "Failed to marshal new dnote into JSON") |
| 788 | } |
| 789 | |
| 790 | err = os.WriteFile(notePath, d, 0644) |
| 791 | if err != nil { |
| 792 | return errors.Wrap(err, "Failed to write the new dnote into the file") |
| 793 | } |
| 794 | |
| 795 | return nil |
| 796 | } |
| 797 | |
| 798 | // migrateToV7 migrates data of edit_note action to the proper version which is |
| 799 | // EditNoteDataV2. Due to a bug, edit logged actions with schema version '2' |
no outgoing calls