| 1 | package mapa |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // The Notion import's tables (its spec §15). Plaintext only where the |
| 6 | // file must answer without the key; plaintext_test.go holds the list. |
| 7 | |
| 8 | // NotionConnection is the one Notion connection, while one exists: the |
| 9 | // token and the workspace it is bound to, both sealed (spec §6). |
| 10 | type NotionConnection struct { |
| 11 | ID int64 |
| 12 | CreatedBy int64 `gorm:"not null"` |
| 13 | CreatedAt time.Time `gorm:"autoCreateTime:false"` |
| 14 | VerifiedAt time.Time |
| 15 | SealedToken []byte |
| 16 | SealedWorkspace []byte |
| 17 | } |
| 18 | |
| 19 | // NotionRun is one run: who started it, its state, its lease and its |
| 20 | // clocks, and its counters (spec §8). Nothing in it is sealed: it says |
| 21 | // when imports ran and how many pages each wrote, and no more. |
| 22 | type NotionRun struct { |
| 23 | ID int64 |
| 24 | Actor int64 `gorm:"not null"` |
| 25 | State string `gorm:"size:16;not null;index"` |
| 26 | // Lease is random, redrawn on start, resume and Stop. Every write a |
| 27 | // run makes checks it (spec §8.3). |
| 28 | Lease int64 `gorm:"not null"` |
| 29 | StartedAt time.Time |
| 30 | HeartbeatAt time.Time |
| 31 | ProgressAt time.Time |
| 32 | FinishedAt *time.Time |
| 33 | Surveyed int `gorm:"not null;default:0"` |
| 34 | Total int `gorm:"not null;default:0"` |
| 35 | Written int `gorm:"not null;default:0"` |
| 36 | Created int `gorm:"not null;default:0"` |
| 37 | Updated int `gorm:"not null;default:0"` |
| 38 | Unchanged int `gorm:"not null;default:0"` |
| 39 | Kept int `gorm:"not null;default:0"` |
| 40 | Failed int `gorm:"not null;default:0"` |
| 41 | ErrorCode string `gorm:"size:32"` |
| 42 | } |
| 43 | |
| 44 | // NotionPage is one row of the map: a Notion id the import has seen, |
| 45 | // for the life of the import (spec §13.1). Its coordinate says which |
| 46 | // Mapa page it became; its staged tree is what Survey read, until the |
| 47 | // run is done. |
| 48 | type NotionPage struct { |
| 49 | ID int64 |
| 50 | NotionPrint string `gorm:"uniqueIndex;size:64;not null"` |
| 51 | State string `gorm:"size:16;not null"` |
| 52 | ErrorCode string `gorm:"size:32"` |
| 53 | // SurveyedRun is the run that last staged this row's tree, and |
| 54 | // SeenRun the last run whose survey reached it. |
| 55 | SurveyedRun int64 `gorm:"not null;default:0"` |
| 56 | SeenRun int64 `gorm:"not null;default:0"` |
| 57 | SealedCoordinate []byte |
| 58 | SealedStaged []byte |
| 59 | } |
| 60 | |
| 61 | // NotionImage is one Notion-hosted image as the import placed it (spec |
| 62 | // §12, §15): which Mapa image a Notion block became on a page, or why it |
| 63 | // was refused. place_print is the block on a page; block_print the |
| 64 | // block alone, to find it again on another page. Both are HMACs. |
| 65 | type NotionImage struct { |
| 66 | ID int64 |
| 67 | PlacePrint string `gorm:"uniqueIndex;size:64;not null"` |
| 68 | BlockPrint string `gorm:"index;size:64;not null"` |
| 69 | State string `gorm:"size:16;not null"` |
| 70 | SealedRecord []byte |
| 71 | } |
| 72 | |