prepareEmptyServerSync marks all local books and notes as dirty when syncing to an empty server. This is typically used when switching to a new empty server but wanting to upload existing local data. Returns true if preparation was done, false otherwise.
(tx *database.DB)
| 1073 | // This is typically used when switching to a new empty server but wanting to upload existing local data. |
| 1074 | // Returns true if preparation was done, false otherwise. |
| 1075 | func prepareEmptyServerSync(tx *database.DB) error { |
| 1076 | // Mark all books and notes as dirty and reset USN to 0 |
| 1077 | if _, err := tx.Exec("UPDATE books SET usn = 0, dirty = 1 WHERE deleted = 0"); err != nil { |
| 1078 | return errors.Wrap(err, "marking books as dirty") |
| 1079 | } |
| 1080 | if _, err := tx.Exec("UPDATE notes SET usn = 0, dirty = 1 WHERE deleted = 0"); err != nil { |
| 1081 | return errors.Wrap(err, "marking notes as dirty") |
| 1082 | } |
| 1083 | |
| 1084 | // Reset lastMaxUSN to 0 to match the server |
| 1085 | if err := updateLastMaxUSN(tx, 0); err != nil { |
| 1086 | return errors.Wrap(err, "resetting last max usn") |
| 1087 | } |
| 1088 | |
| 1089 | return nil |
| 1090 | } |
| 1091 | |
| 1092 | func newRun(ctx context.DnoteCtx) infra.RunEFunc { |
| 1093 | return func(cmd *cobra.Command, args []string) error { |