mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
Remove public from CLI
This commit is contained in:
parent
e3380a4dfa
commit
78d941da90
14 changed files with 141 additions and 81 deletions
|
|
@ -96,7 +96,7 @@ dnote find "merge sort" -b algorithm
|
|||
|
||||
_alias: s_
|
||||
|
||||
Sync notes with Dnote server. All your data is encrypted before being sent to the server.
|
||||
Sync notes with Dnote server.
|
||||
|
||||
## dnote login
|
||||
|
||||
|
|
|
|||
|
|
@ -246,7 +246,6 @@ type SyncFragNote struct {
|
|||
AddedOn int64 `json:"added_on"`
|
||||
EditedOn int64 `json:"edited_on"`
|
||||
Body string `json:"content"`
|
||||
Public bool `json:"public"`
|
||||
Deleted bool `json:"deleted"`
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +457,6 @@ func CreateNote(ctx context.DnoteCtx, bookUUID, content string) (CreateNoteResp,
|
|||
type updateNotePayload struct {
|
||||
BookUUID *string `json:"book_uuid"`
|
||||
Body *string `json:"content"`
|
||||
Public *bool `json:"public"`
|
||||
}
|
||||
|
||||
// UpdateNoteResp is the response from create book api
|
||||
|
|
@ -468,11 +466,10 @@ type UpdateNoteResp struct {
|
|||
}
|
||||
|
||||
// UpdateNote updates a note in the server
|
||||
func UpdateNote(ctx context.DnoteCtx, uuid, bookUUID, content string, public bool) (UpdateNoteResp, error) {
|
||||
func UpdateNote(ctx context.DnoteCtx, uuid, bookUUID, content string) (UpdateNoteResp, error) {
|
||||
payload := updateNotePayload{
|
||||
BookUUID: &bookUUID,
|
||||
Body: &content,
|
||||
Public: &public,
|
||||
}
|
||||
b, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func writeNote(ctx context.DnoteCtx, bookLabel string, content string, ts int64)
|
|||
return 0, errors.Wrap(err, "generating uuid")
|
||||
}
|
||||
|
||||
n := database.NewNote(noteUUID, bookUUID, content, ts, 0, 0, false, false, true)
|
||||
n := database.NewNote(noteUUID, bookUUID, content, ts, 0, 0, false, true)
|
||||
|
||||
err = n.Insert(tx)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -280,8 +280,8 @@ func mergeNote(tx *database.DB, serverNote client.SyncFragNote, localNote databa
|
|||
|
||||
// if the local copy is deleted, and it was edited on the server, override with server values and mark it not dirty.
|
||||
if localNote.Deleted {
|
||||
if _, err := tx.Exec("UPDATE notes SET usn = ?, book_uuid = ?, body = ?, edited_on = ?, deleted = ?, public = ?, dirty = ? WHERE uuid = ?",
|
||||
serverNote.USN, serverNote.BookUUID, serverNote.Body, serverNote.EditedOn, serverNote.Deleted, serverNote.Public, false, serverNote.UUID); err != nil {
|
||||
if _, err := tx.Exec("UPDATE notes SET usn = ?, book_uuid = ?, body = ?, edited_on = ?, deleted = ?, dirty = ? WHERE uuid = ?",
|
||||
serverNote.USN, serverNote.BookUUID, serverNote.Body, serverNote.EditedOn, serverNote.Deleted, false, serverNote.UUID); err != nil {
|
||||
return errors.Wrapf(err, "updating local note %s", serverNote.UUID)
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ func stepSyncNote(tx *database.DB, n client.SyncFragNote) error {
|
|||
|
||||
// if note exists in the server and does not exist in the client, insert the note.
|
||||
if err == sql.ErrNoRows {
|
||||
note := database.NewNote(n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Public, n.Deleted, false)
|
||||
note := database.NewNote(n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Deleted, false)
|
||||
|
||||
if err := note.Insert(tx); err != nil {
|
||||
return errors.Wrapf(err, "inserting note with uuid %s", n.UUID)
|
||||
|
|
@ -335,7 +335,7 @@ func fullSyncNote(tx *database.DB, n client.SyncFragNote) error {
|
|||
|
||||
// if note exists in the server and does not exist in the client, insert the note.
|
||||
if err == sql.ErrNoRows {
|
||||
note := database.NewNote(n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Public, n.Deleted, false)
|
||||
note := database.NewNote(n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Deleted, false)
|
||||
|
||||
if err := note.Insert(tx); err != nil {
|
||||
return errors.Wrapf(err, "inserting note with uuid %s", n.UUID)
|
||||
|
|
@ -758,7 +758,7 @@ func sendBooks(ctx context.DnoteCtx, tx *database.DB) (bool, error) {
|
|||
func sendNotes(ctx context.DnoteCtx, tx *database.DB) (bool, error) {
|
||||
isBehind := false
|
||||
|
||||
rows, err := tx.Query("SELECT uuid, book_uuid, body, public, deleted, usn, added_on FROM notes WHERE dirty")
|
||||
rows, err := tx.Query("SELECT uuid, book_uuid, body, deleted, usn, added_on FROM notes WHERE dirty")
|
||||
if err != nil {
|
||||
return isBehind, errors.Wrap(err, "getting syncable notes")
|
||||
}
|
||||
|
|
@ -767,7 +767,7 @@ func sendNotes(ctx context.DnoteCtx, tx *database.DB) (bool, error) {
|
|||
for rows.Next() {
|
||||
var note database.Note
|
||||
|
||||
if err = rows.Scan(¬e.UUID, ¬e.BookUUID, ¬e.Body, ¬e.Public, ¬e.Deleted, ¬e.USN, ¬e.AddedOn); err != nil {
|
||||
if err = rows.Scan(¬e.UUID, ¬e.BookUUID, ¬e.Body, ¬e.Deleted, ¬e.USN, ¬e.AddedOn); err != nil {
|
||||
return isBehind, errors.Wrap(err, "scanning a syncable note")
|
||||
}
|
||||
|
||||
|
|
@ -822,7 +822,7 @@ func sendNotes(ctx context.DnoteCtx, tx *database.DB) (bool, error) {
|
|||
|
||||
respUSN = resp.Result.USN
|
||||
} else {
|
||||
resp, err := client.UpdateNote(ctx, note.UUID, note.BookUUID, note.Body, note.Public)
|
||||
resp, err := client.UpdateNote(ctx, note.UUID, note.BookUUID, note.Body)
|
||||
if err != nil {
|
||||
return isBehind, errors.Wrap(err, "updating a note")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,13 +41,12 @@ type Note struct {
|
|||
AddedOn int64 `json:"added_on"`
|
||||
EditedOn int64 `json:"edited_on"`
|
||||
USN int `json:"usn"`
|
||||
Public bool `json:"public"`
|
||||
Deleted bool `json:"deleted"`
|
||||
Dirty bool `json:"dirty"`
|
||||
}
|
||||
|
||||
// NewNote constructs a note with the given data
|
||||
func NewNote(uuid, bookUUID, body string, addedOn, editedOn int64, usn int, public, deleted, dirty bool) Note {
|
||||
func NewNote(uuid, bookUUID, body string, addedOn, editedOn int64, usn int, deleted, dirty bool) Note {
|
||||
return Note{
|
||||
UUID: uuid,
|
||||
BookUUID: bookUUID,
|
||||
|
|
@ -55,7 +54,6 @@ func NewNote(uuid, bookUUID, body string, addedOn, editedOn int64, usn int, publ
|
|||
AddedOn: addedOn,
|
||||
EditedOn: editedOn,
|
||||
USN: usn,
|
||||
Public: public,
|
||||
Deleted: deleted,
|
||||
Dirty: dirty,
|
||||
}
|
||||
|
|
@ -63,8 +61,8 @@ func NewNote(uuid, bookUUID, body string, addedOn, editedOn int64, usn int, publ
|
|||
|
||||
// Insert inserts a new note
|
||||
func (n Note) Insert(db *DB) error {
|
||||
_, err := db.Exec("INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Public, n.Deleted, n.Dirty)
|
||||
_, err := db.Exec("INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
n.UUID, n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Deleted, n.Dirty)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "inserting note with uuid %s", n.UUID)
|
||||
|
|
@ -75,8 +73,8 @@ func (n Note) Insert(db *DB) error {
|
|||
|
||||
// Update updates the note with the given data
|
||||
func (n Note) Update(db *DB) error {
|
||||
_, err := db.Exec("UPDATE notes SET book_uuid = ?, body = ?, added_on = ?, edited_on = ?, usn = ?, public = ?, deleted = ?, dirty = ? WHERE uuid = ?",
|
||||
n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Public, n.Deleted, n.Dirty, n.UUID)
|
||||
_, err := db.Exec("UPDATE notes SET book_uuid = ?, body = ?, added_on = ?, edited_on = ?, usn = ?, deleted = ?, dirty = ? WHERE uuid = ?",
|
||||
n.BookUUID, n.Body, n.AddedOn, n.EditedOn, n.USN, n.Deleted, n.Dirty, n.UUID)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "updating the note with uuid %s", n.UUID)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ func TestNewNote(t *testing.T) {
|
|||
addedOn int64
|
||||
editedOn int64
|
||||
usn int
|
||||
public bool
|
||||
deleted bool
|
||||
dirty bool
|
||||
}{
|
||||
|
|
@ -45,7 +44,6 @@ func TestNewNote(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 0,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: false,
|
||||
},
|
||||
|
|
@ -56,14 +54,13 @@ func TestNewNote(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 1542058876,
|
||||
usn: 1008,
|
||||
public: true,
|
||||
deleted: true,
|
||||
dirty: true,
|
||||
},
|
||||
}
|
||||
|
||||
for idx, tc := range testCases {
|
||||
got := NewNote(tc.uuid, tc.bookUUID, tc.body, tc.addedOn, tc.editedOn, tc.usn, tc.public, tc.deleted, tc.dirty)
|
||||
got := NewNote(tc.uuid, tc.bookUUID, tc.body, tc.addedOn, tc.editedOn, tc.usn, tc.deleted, tc.dirty)
|
||||
|
||||
assert.Equal(t, got.UUID, tc.uuid, fmt.Sprintf("UUID mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.BookUUID, tc.bookUUID, fmt.Sprintf("BookUUID mismatch for test case %d", idx))
|
||||
|
|
@ -71,7 +68,6 @@ func TestNewNote(t *testing.T) {
|
|||
assert.Equal(t, got.AddedOn, tc.addedOn, fmt.Sprintf("AddedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.EditedOn, tc.editedOn, fmt.Sprintf("EditedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.USN, tc.usn, fmt.Sprintf("USN mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.Public, tc.public, fmt.Sprintf("Public mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.Deleted, tc.deleted, fmt.Sprintf("Deleted mismatch for test case %d", idx))
|
||||
assert.Equal(t, got.Dirty, tc.dirty, fmt.Sprintf("Dirty mismatch for test case %d", idx))
|
||||
}
|
||||
|
|
@ -85,7 +81,6 @@ func TestNoteInsert(t *testing.T) {
|
|||
addedOn int64
|
||||
editedOn int64
|
||||
usn int
|
||||
public bool
|
||||
deleted bool
|
||||
dirty bool
|
||||
}{
|
||||
|
|
@ -96,7 +91,6 @@ func TestNoteInsert(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 0,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: false,
|
||||
},
|
||||
|
|
@ -107,7 +101,6 @@ func TestNoteInsert(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 1542058876,
|
||||
usn: 1008,
|
||||
public: true,
|
||||
deleted: true,
|
||||
dirty: true,
|
||||
},
|
||||
|
|
@ -126,7 +119,6 @@ func TestNoteInsert(t *testing.T) {
|
|||
AddedOn: tc.addedOn,
|
||||
EditedOn: tc.editedOn,
|
||||
USN: tc.usn,
|
||||
Public: tc.public,
|
||||
Deleted: tc.deleted,
|
||||
Dirty: tc.dirty,
|
||||
}
|
||||
|
|
@ -148,10 +140,10 @@ func TestNoteInsert(t *testing.T) {
|
|||
var uuid, bookUUID, body string
|
||||
var addedOn, editedOn int64
|
||||
var usn int
|
||||
var public, deleted, dirty bool
|
||||
var deleted, dirty bool
|
||||
MustScan(t, "getting n1",
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty FROM notes WHERE uuid = ?", tc.uuid),
|
||||
&uuid, &bookUUID, &body, &addedOn, &editedOn, &usn, &public, &deleted, &dirty)
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty FROM notes WHERE uuid = ?", tc.uuid),
|
||||
&uuid, &bookUUID, &body, &addedOn, &editedOn, &usn, &deleted, &dirty)
|
||||
|
||||
assert.Equal(t, uuid, tc.uuid, fmt.Sprintf("uuid mismatch for test case %d", idx))
|
||||
assert.Equal(t, bookUUID, tc.bookUUID, fmt.Sprintf("bookUUID mismatch for test case %d", idx))
|
||||
|
|
@ -159,7 +151,6 @@ func TestNoteInsert(t *testing.T) {
|
|||
assert.Equal(t, addedOn, tc.addedOn, fmt.Sprintf("addedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, editedOn, tc.editedOn, fmt.Sprintf("editedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, usn, tc.usn, fmt.Sprintf("usn mismatch for test case %d", idx))
|
||||
assert.Equal(t, public, tc.public, fmt.Sprintf("public mismatch for test case %d", idx))
|
||||
assert.Equal(t, deleted, tc.deleted, fmt.Sprintf("deleted mismatch for test case %d", idx))
|
||||
assert.Equal(t, dirty, tc.dirty, fmt.Sprintf("dirty mismatch for test case %d", idx))
|
||||
}()
|
||||
|
|
@ -174,14 +165,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
addedOn int64
|
||||
editedOn int64
|
||||
usn int
|
||||
public bool
|
||||
deleted bool
|
||||
dirty bool
|
||||
newBookUUID string
|
||||
newBody string
|
||||
newEditedOn int64
|
||||
newUSN int
|
||||
newPublic bool
|
||||
newDeleted bool
|
||||
newDirty bool
|
||||
}{
|
||||
|
|
@ -192,14 +181,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 0,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: false,
|
||||
newBookUUID: "b1-uuid",
|
||||
newBody: "n1-body edited",
|
||||
newEditedOn: 1542058879,
|
||||
newUSN: 0,
|
||||
newPublic: false,
|
||||
newDeleted: false,
|
||||
newDirty: false,
|
||||
},
|
||||
|
|
@ -210,14 +197,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 0,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: true,
|
||||
newBookUUID: "b2-uuid",
|
||||
newBody: "n1-body",
|
||||
newEditedOn: 1542058879,
|
||||
newUSN: 0,
|
||||
newPublic: true,
|
||||
newDeleted: false,
|
||||
newDirty: false,
|
||||
},
|
||||
|
|
@ -228,14 +213,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 10,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: false,
|
||||
newBookUUID: "",
|
||||
newBody: "",
|
||||
newEditedOn: 1542058879,
|
||||
newUSN: 151,
|
||||
newPublic: false,
|
||||
newDeleted: true,
|
||||
newDirty: false,
|
||||
},
|
||||
|
|
@ -246,14 +229,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
addedOn: 1542058875,
|
||||
editedOn: 0,
|
||||
usn: 0,
|
||||
public: false,
|
||||
deleted: false,
|
||||
dirty: false,
|
||||
newBookUUID: "",
|
||||
newBody: "",
|
||||
newEditedOn: 1542058879,
|
||||
newUSN: 15,
|
||||
newPublic: false,
|
||||
newDeleted: true,
|
||||
newDirty: false,
|
||||
},
|
||||
|
|
@ -272,7 +253,6 @@ func TestNoteUpdate(t *testing.T) {
|
|||
AddedOn: tc.addedOn,
|
||||
EditedOn: tc.editedOn,
|
||||
USN: tc.usn,
|
||||
Public: tc.public,
|
||||
Deleted: tc.deleted,
|
||||
Dirty: tc.dirty,
|
||||
}
|
||||
|
|
@ -283,13 +263,12 @@ func TestNoteUpdate(t *testing.T) {
|
|||
AddedOn: 1542058875,
|
||||
EditedOn: 0,
|
||||
USN: 39,
|
||||
Public: false,
|
||||
Deleted: false,
|
||||
Dirty: false,
|
||||
}
|
||||
|
||||
MustExec(t, fmt.Sprintf("inserting n1 for test case %d", idx), db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.USN, n1.AddedOn, n1.EditedOn, n1.Body, n1.Public, n1.Deleted, n1.Dirty)
|
||||
MustExec(t, fmt.Sprintf("inserting n2 for test case %d", idx), db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.USN, n2.AddedOn, n2.EditedOn, n2.Body, n2.Public, n2.Deleted, n2.Dirty)
|
||||
MustExec(t, fmt.Sprintf("inserting n1 for test case %d", idx), db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.USN, n1.AddedOn, n1.EditedOn, n1.Body, n1.Deleted, n1.Dirty)
|
||||
MustExec(t, fmt.Sprintf("inserting n2 for test case %d", idx), db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.USN, n2.AddedOn, n2.EditedOn, n2.Body, n2.Deleted, n2.Dirty)
|
||||
|
||||
// execute
|
||||
tx, err := db.Begin()
|
||||
|
|
@ -301,7 +280,6 @@ func TestNoteUpdate(t *testing.T) {
|
|||
n1.Body = tc.newBody
|
||||
n1.EditedOn = tc.newEditedOn
|
||||
n1.USN = tc.newUSN
|
||||
n1.Public = tc.newPublic
|
||||
n1.Deleted = tc.newDeleted
|
||||
n1.Dirty = tc.newDirty
|
||||
|
||||
|
|
@ -315,11 +293,11 @@ func TestNoteUpdate(t *testing.T) {
|
|||
// test
|
||||
var n1Record, n2Record Note
|
||||
MustScan(t, "getting n1",
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty FROM notes WHERE uuid = ?", tc.uuid),
|
||||
&n1Record.UUID, &n1Record.BookUUID, &n1Record.Body, &n1Record.AddedOn, &n1Record.EditedOn, &n1Record.USN, &n1Record.Public, &n1Record.Deleted, &n1Record.Dirty)
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty FROM notes WHERE uuid = ?", tc.uuid),
|
||||
&n1Record.UUID, &n1Record.BookUUID, &n1Record.Body, &n1Record.AddedOn, &n1Record.EditedOn, &n1Record.USN, &n1Record.Deleted, &n1Record.Dirty)
|
||||
MustScan(t, "getting n2",
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty FROM notes WHERE uuid = ?", n2.UUID),
|
||||
&n2Record.UUID, &n2Record.BookUUID, &n2Record.Body, &n2Record.AddedOn, &n2Record.EditedOn, &n2Record.USN, &n2Record.Public, &n2Record.Deleted, &n2Record.Dirty)
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty FROM notes WHERE uuid = ?", n2.UUID),
|
||||
&n2Record.UUID, &n2Record.BookUUID, &n2Record.Body, &n2Record.AddedOn, &n2Record.EditedOn, &n2Record.USN, &n2Record.Deleted, &n2Record.Dirty)
|
||||
|
||||
assert.Equal(t, n1Record.UUID, n1.UUID, fmt.Sprintf("n1 uuid mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.BookUUID, tc.newBookUUID, fmt.Sprintf("n1 bookUUID mismatch for test case %d", idx))
|
||||
|
|
@ -327,7 +305,6 @@ func TestNoteUpdate(t *testing.T) {
|
|||
assert.Equal(t, n1Record.AddedOn, n1.AddedOn, fmt.Sprintf("n1 addedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.EditedOn, tc.newEditedOn, fmt.Sprintf("n1 editedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.USN, tc.newUSN, fmt.Sprintf("n1 usn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.Public, tc.newPublic, fmt.Sprintf("n1 public mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.Deleted, tc.newDeleted, fmt.Sprintf("n1 deleted mismatch for test case %d", idx))
|
||||
assert.Equal(t, n1Record.Dirty, tc.newDirty, fmt.Sprintf("n1 dirty mismatch for test case %d", idx))
|
||||
|
||||
|
|
@ -337,7 +314,6 @@ func TestNoteUpdate(t *testing.T) {
|
|||
assert.Equal(t, n2Record.AddedOn, n2.AddedOn, fmt.Sprintf("n2 addedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n2Record.EditedOn, n2.EditedOn, fmt.Sprintf("n2 editedOn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n2Record.USN, n2.USN, fmt.Sprintf("n2 usn mismatch for test case %d", idx))
|
||||
assert.Equal(t, n2Record.Public, n2.Public, fmt.Sprintf("n2 public mismatch for test case %d", idx))
|
||||
assert.Equal(t, n2Record.Deleted, n2.Deleted, fmt.Sprintf("n2 deleted mismatch for test case %d", idx))
|
||||
assert.Equal(t, n2Record.Dirty, n2.Dirty, fmt.Sprintf("n2 dirty mismatch for test case %d", idx))
|
||||
}()
|
||||
|
|
@ -424,7 +400,6 @@ func TestNoteExpunge(t *testing.T) {
|
|||
AddedOn: 1542058874,
|
||||
EditedOn: 0,
|
||||
USN: 22,
|
||||
Public: false,
|
||||
Deleted: false,
|
||||
Dirty: false,
|
||||
}
|
||||
|
|
@ -435,13 +410,12 @@ func TestNoteExpunge(t *testing.T) {
|
|||
AddedOn: 1542058875,
|
||||
EditedOn: 0,
|
||||
USN: 39,
|
||||
Public: false,
|
||||
Deleted: false,
|
||||
Dirty: false,
|
||||
}
|
||||
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.USN, n1.AddedOn, n1.EditedOn, n1.Body, n1.Public, n1.Deleted, n1.Dirty)
|
||||
MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.USN, n2.AddedOn, n2.EditedOn, n2.Body, n2.Public, n2.Deleted, n2.Dirty)
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1.UUID, n1.BookUUID, n1.USN, n1.AddedOn, n1.EditedOn, n1.Body, n1.Deleted, n1.Dirty)
|
||||
MustExec(t, "inserting n2", db, "INSERT INTO notes (uuid, book_uuid, usn, added_on, edited_on, body, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n2.UUID, n2.BookUUID, n2.USN, n2.AddedOn, n2.EditedOn, n2.Body, n2.Deleted, n2.Dirty)
|
||||
|
||||
// execute
|
||||
tx, err := db.Begin()
|
||||
|
|
@ -464,8 +438,8 @@ func TestNoteExpunge(t *testing.T) {
|
|||
|
||||
var n2Record Note
|
||||
MustScan(t, "getting n2",
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty FROM notes WHERE uuid = ?", n2.UUID),
|
||||
&n2Record.UUID, &n2Record.BookUUID, &n2Record.Body, &n2Record.AddedOn, &n2Record.EditedOn, &n2Record.USN, &n2Record.Public, &n2Record.Deleted, &n2Record.Dirty)
|
||||
db.QueryRow("SELECT uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty FROM notes WHERE uuid = ?", n2.UUID),
|
||||
&n2Record.UUID, &n2Record.BookUUID, &n2Record.Body, &n2Record.AddedOn, &n2Record.EditedOn, &n2Record.USN, &n2Record.Deleted, &n2Record.Dirty)
|
||||
|
||||
assert.Equal(t, n2Record.UUID, n2.UUID, "n2 uuid mismatch")
|
||||
assert.Equal(t, n2Record.BookUUID, n2.BookUUID, "n2 bookUUID mismatch")
|
||||
|
|
@ -473,7 +447,6 @@ func TestNoteExpunge(t *testing.T) {
|
|||
assert.Equal(t, n2Record.AddedOn, n2.AddedOn, "n2 addedOn mismatch")
|
||||
assert.Equal(t, n2Record.EditedOn, n2.EditedOn, "n2 editedOn mismatch")
|
||||
assert.Equal(t, n2Record.USN, n2.USN, "n2 usn mismatch")
|
||||
assert.Equal(t, n2Record.Public, n2.Public, "n2 public mismatch")
|
||||
assert.Equal(t, n2Record.Deleted, n2.Deleted, "n2 deleted mismatch")
|
||||
assert.Equal(t, n2Record.Dirty, n2.Dirty, "n2 dirty mismatch")
|
||||
}
|
||||
|
|
@ -817,7 +790,6 @@ func TestNoteFTS(t *testing.T) {
|
|||
AddedOn: 1542058875,
|
||||
EditedOn: 0,
|
||||
USN: 0,
|
||||
Public: false,
|
||||
Deleted: false,
|
||||
Dirty: false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,6 @@ func GetActiveNote(db *DB, rowid int) (Note, error) {
|
|||
added_on,
|
||||
edited_on,
|
||||
usn,
|
||||
public,
|
||||
deleted,
|
||||
dirty
|
||||
FROM notes WHERE rowid = ? AND deleted = false;`, rowid).Scan(
|
||||
|
|
@ -181,7 +180,6 @@ func GetActiveNote(db *DB, rowid int) (Note, error) {
|
|||
&ret.AddedOn,
|
||||
&ret.EditedOn,
|
||||
&ret.USN,
|
||||
&ret.Public,
|
||||
&ret.Deleted,
|
||||
&ret.Dirty,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ func TestGetActiveNote(t *testing.T) {
|
|||
defer TeardownTestDB(t, db)
|
||||
|
||||
n1UUID := "n1-uuid"
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, true, false, true)
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, false, true)
|
||||
|
||||
var n1RowID int
|
||||
MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", n1UUID), &n1RowID)
|
||||
|
|
@ -261,7 +261,6 @@ func TestGetActiveNote(t *testing.T) {
|
|||
assert.Equal(t, got.AddedOn, int64(1542058875), "AddedOn mismatch")
|
||||
assert.Equal(t, got.EditedOn, int64(1542058876), "EditedOn mismatch")
|
||||
assert.Equal(t, got.USN, 1, "USN mismatch")
|
||||
assert.Equal(t, got.Public, true, "Public mismatch")
|
||||
assert.Equal(t, got.Deleted, false, "Deleted mismatch")
|
||||
assert.Equal(t, got.Dirty, true, "Dirty mismatch")
|
||||
})
|
||||
|
|
@ -272,7 +271,7 @@ func TestGetActiveNote(t *testing.T) {
|
|||
defer TeardownTestDB(t, db)
|
||||
|
||||
n1UUID := "n1-uuid"
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, true, true, true)
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", n1UUID, "b1-uuid", "n1 content", 1542058875, 1542058876, 1, true, true)
|
||||
|
||||
var n1RowID int
|
||||
MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", n1UUID), &n1RowID)
|
||||
|
|
@ -296,7 +295,7 @@ func TestUpdateNoteContent(t *testing.T) {
|
|||
defer TeardownTestDB(t, db)
|
||||
|
||||
uuid := "n1-uuid"
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", uuid, "b1-uuid", "n1 content", 1542058875, 0, 1, false, false, false)
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", uuid, "b1-uuid", "n1 content", 1542058875, 0, 1, false, false)
|
||||
|
||||
var rowid int
|
||||
MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", uuid), &rowid)
|
||||
|
|
@ -333,7 +332,7 @@ func TestUpdateNoteBook(t *testing.T) {
|
|||
MustExec(t, "inserting b2", db, "INSERT INTO books (uuid, label, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?)", b2UUID, "b2-label", 9, false, false)
|
||||
|
||||
uuid := "n1-uuid"
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, public, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", uuid, b1UUID, "n1 content", 1542058875, 0, 1, false, false, false)
|
||||
MustExec(t, "inserting n1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on, edited_on, usn, deleted, dirty) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", uuid, b1UUID, "n1 content", 1542058875, 0, 1, false, false)
|
||||
|
||||
var rowid int
|
||||
MustScan(t, "getting rowid", db.QueryRow("SELECT rowid FROM notes WHERE uuid = ?", uuid), &rowid)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ CREATE TABLE IF NOT EXISTS "notes"
|
|||
body text NOT NULL,
|
||||
added_on integer NOT NULL,
|
||||
edited_on integer DEFAULT 0,
|
||||
public bool DEFAULT false,
|
||||
dirty bool DEFAULT false,
|
||||
usn int DEFAULT 0 NOT NULL,
|
||||
deleted bool DEFAULT false
|
||||
|
|
|
|||
|
|
@ -38,13 +38,5 @@ CREATE TRIGGER notes_after_update AFTER UPDATE ON notes BEGIN
|
|||
INSERT INTO note_fts(note_fts, rowid, body) VALUES ('delete', old.rowid, old.body);
|
||||
INSERT INTO note_fts(rowid, body) VALUES (new.rowid, new.body);
|
||||
END;
|
||||
CREATE TABLE actions
|
||||
(
|
||||
uuid text PRIMARY KEY,
|
||||
schema integer NOT NULL,
|
||||
type text NOT NULL,
|
||||
data text NOT NULL,
|
||||
timestamp integer NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_notes_uuid ON notes(uuid);
|
||||
CREATE INDEX idx_notes_book_uuid ON notes(book_uuid);
|
||||
|
|
|
|||
42
pkg/cli/migrate/fixtures/local-14-pre-schema.sql
Normal file
42
pkg/cli/migrate/fixtures/local-14-pre-schema.sql
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
CREATE TABLE books
|
||||
(
|
||||
uuid text PRIMARY KEY,
|
||||
label text NOT NULL
|
||||
, dirty bool DEFAULT false, usn int DEFAULT 0 NOT NULL, deleted bool DEFAULT false);
|
||||
CREATE TABLE system
|
||||
(
|
||||
key string NOT NULL,
|
||||
value text NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_books_label ON books(label);
|
||||
CREATE UNIQUE INDEX idx_books_uuid ON books(uuid);
|
||||
CREATE TABLE IF NOT EXISTS "notes"
|
||||
(
|
||||
uuid text NOT NULL,
|
||||
book_uuid text NOT NULL,
|
||||
body text NOT NULL,
|
||||
added_on integer NOT NULL,
|
||||
edited_on integer DEFAULT 0,
|
||||
public bool DEFAULT false,
|
||||
dirty bool DEFAULT false,
|
||||
usn int DEFAULT 0 NOT NULL,
|
||||
deleted bool DEFAULT false
|
||||
);
|
||||
CREATE VIRTUAL TABLE note_fts USING fts5(content=notes, body, tokenize="porter unicode61 categories 'L* N* Co Ps Pe'")
|
||||
/* note_fts(body) */;
|
||||
CREATE TABLE IF NOT EXISTS 'note_fts_data'(id INTEGER PRIMARY KEY, block BLOB);
|
||||
CREATE TABLE IF NOT EXISTS 'note_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID;
|
||||
CREATE TABLE IF NOT EXISTS 'note_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB);
|
||||
CREATE TABLE IF NOT EXISTS 'note_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID;
|
||||
CREATE TRIGGER notes_after_insert AFTER INSERT ON notes BEGIN
|
||||
INSERT INTO note_fts(rowid, body) VALUES (new.rowid, new.body);
|
||||
END;
|
||||
CREATE TRIGGER notes_after_delete AFTER DELETE ON notes BEGIN
|
||||
INSERT INTO note_fts(note_fts, rowid, body) VALUES ('delete', old.rowid, old.body);
|
||||
END;
|
||||
CREATE TRIGGER notes_after_update AFTER UPDATE ON notes BEGIN
|
||||
INSERT INTO note_fts(note_fts, rowid, body) VALUES ('delete', old.rowid, old.body);
|
||||
INSERT INTO note_fts(rowid, body) VALUES (new.rowid, new.body);
|
||||
END;
|
||||
CREATE UNIQUE INDEX idx_notes_uuid ON notes(uuid);
|
||||
CREATE INDEX idx_notes_book_uuid ON notes(book_uuid);
|
||||
|
|
@ -49,6 +49,7 @@ var LocalSequence = []migration{
|
|||
lm11,
|
||||
lm12,
|
||||
lm13,
|
||||
lm14,
|
||||
}
|
||||
|
||||
// RemoteSequence is a list of remote migrations to be run
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -846,13 +846,13 @@ func TestLocalMigration8(t *testing.T) {
|
|||
var n1AddedOn, n1EditedOn int64
|
||||
var n1USN int
|
||||
var n1Public, n1Dirty, n1Deleted bool
|
||||
database.MustScan(t, "scanning n1", db.QueryRow("SELECT book_uuid, body, added_on, edited_on, usn, public, dirty, deleted FROM notes WHERE uuid = ?", n1UUID), &n1BookUUID, &n1Body, &n1AddedOn, &n1EditedOn, &n1USN, &n1Public, &n1Dirty, &n1Deleted)
|
||||
database.MustScan(t, "scanning n1", db.QueryRow("SELECT book_uuid, body, added_on, edited_on, usn, public, dirty, deleted FROM notes WHERE uuid = ?", n1UUID), &n1BookUUID, &n1Body, &n1AddedOn, &n1EditedOn, &n1USN, &n1Public, &n1Dirty, &n1Deleted)
|
||||
|
||||
var n2BookUUID, n2Body string
|
||||
var n2AddedOn, n2EditedOn int64
|
||||
var n2USN int
|
||||
var n2Public, n2Dirty, n2Deleted bool
|
||||
database.MustScan(t, "scanning n2", db.QueryRow("SELECT book_uuid, body, added_on, edited_on, usn, public, dirty, deleted FROM notes WHERE uuid = ?", n2UUID), &n2BookUUID, &n2Body, &n2AddedOn, &n2EditedOn, &n2USN, &n2Public, &n2Dirty, &n2Deleted)
|
||||
database.MustScan(t, "scanning n2", db.QueryRow("SELECT book_uuid, body, added_on, edited_on, usn, public, dirty, deleted FROM notes WHERE uuid = ?", n2UUID), &n2BookUUID, &n2Body, &n2AddedOn, &n2EditedOn, &n2USN, &n2Public, &n2Dirty, &n2Deleted)
|
||||
|
||||
assert.Equal(t, n1BookUUID, b1UUID, "n1 BookUUID mismatch")
|
||||
assert.Equal(t, n1Body, "n1 Body", "n1 Body mismatch")
|
||||
|
|
@ -1150,6 +1150,56 @@ func TestLocalMigration13(t *testing.T) {
|
|||
assert.Equal(t, cf.EnableUpgradeCheck, true, "enableUpgradeCheck mismatch")
|
||||
}
|
||||
|
||||
func TestLocalMigration14(t *testing.T) {
|
||||
// set up
|
||||
opts := database.TestDBOptions{SchemaSQLPath: "./fixtures/local-14-pre-schema.sql", SkipMigration: true}
|
||||
ctx := context.InitTestCtx(t, paths, &opts)
|
||||
defer context.TeardownTestCtx(t, ctx)
|
||||
|
||||
db := ctx.DB
|
||||
|
||||
b1UUID := testutils.MustGenerateUUID(t)
|
||||
database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", b1UUID, "b1")
|
||||
|
||||
n1UUID := testutils.MustGenerateUUID(t)
|
||||
database.MustExec(t, "inserting note", db, `INSERT INTO notes
|
||||
(uuid, book_uuid, body, added_on, edited_on, public, dirty, usn, deleted) VALUES
|
||||
(?, ?, ?, ?, ?, ?, ?, ?, ?)`, n1UUID, b1UUID, "test note", 1, 2, true, false, 0, false)
|
||||
|
||||
// Execute
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "beginning a transaction"))
|
||||
}
|
||||
|
||||
err = lm14.run(ctx, tx)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
t.Fatal(errors.Wrap(err, "failed to run"))
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
|
||||
// Test - verify public column was dropped by checking column names
|
||||
rows, err := db.Query("SELECT name FROM pragma_table_info('notes')")
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "getting table info"))
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var name string
|
||||
err := rows.Scan(&name)
|
||||
if err != nil {
|
||||
t.Fatal(errors.Wrap(err, "scanning column name"))
|
||||
}
|
||||
|
||||
if name == "public" {
|
||||
t.Fatal("public column still exists after migration")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteMigration1(t *testing.T) {
|
||||
// set up
|
||||
opts := database.TestDBOptions{SchemaSQLPath: "./fixtures/remote-1-pre-schema.sql", SkipMigration: true}
|
||||
|
|
|
|||
|
|
@ -572,6 +572,18 @@ var lm13 = migration{
|
|||
},
|
||||
}
|
||||
|
||||
var lm14 = migration{
|
||||
name: "drop-public-from-notes",
|
||||
run: func(ctx context.DnoteCtx, tx *database.DB) error {
|
||||
_, err := tx.Exec(`ALTER TABLE notes DROP COLUMN public;`)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dropping public column from notes")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var rm1 = migration{
|
||||
name: "sync-book-uuids-from-server",
|
||||
run: func(ctx context.DnoteCtx, tx *database.DB) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue