This commit is contained in:
parent
d32818af09
commit
cfa0566c6d
39 changed files with 2276 additions and 183 deletions
45
storage-new/models/NoteEditLog.go
Normal file
45
storage-new/models/NoteEditLog.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gen"
|
||||
)
|
||||
|
||||
// NoteEdit denotes one edit done to one known note.
|
||||
// The table is (within this application) append only
|
||||
// (Except for the case where a note is hard deleted,
|
||||
// where the edits for it also need to be deleted.
|
||||
// Direct access to the db also circumvents this).
|
||||
// Every edit will append one entry per edited field, denoting
|
||||
// the field and how it was changed, in chronological order
|
||||
type NoteEdit struct {
|
||||
Note Note
|
||||
NoteId string `gorm:"primaryKey;autoIncrement:false;<-:create"`
|
||||
EditNr uint64 `gorm:"primaryKey;autoIncrement:false;<-:create"`
|
||||
CreatedAt time.Time `gorm:"<-:create"`
|
||||
Before string `gorm:"<-:create"`
|
||||
After string `gorm:"<-:create"`
|
||||
Field string `gorm:"<-:create"` // What was edited
|
||||
}
|
||||
|
||||
type INoteEdit interface {
|
||||
// Append a new edit to a note
|
||||
//
|
||||
// INSERT INTO @@table
|
||||
// (note_id, edit_nr, created_at, before, after, field)
|
||||
// VALUES (
|
||||
// @note_id,
|
||||
// (SELECT COUNT(*) FROM @@table WHERE note_id = @noteId)+1,
|
||||
// NOW(),
|
||||
// @before,
|
||||
// @after,
|
||||
// @field
|
||||
// )
|
||||
AppendEdit(noteId, before, after, field string) error
|
||||
|
||||
// Find all edits for a field
|
||||
//
|
||||
// SELECT * FROM @@table WHERE note_id = @noteId AND field = @field
|
||||
FindEditsForField(noteId, field string) ([]gen.T, error)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue