feat: replicate thread membership and record merges (#46)
feat: replicate thread membership and record merges (#46) Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #46.
This commit is contained in:
+17
-16
@@ -27,15 +27,16 @@ const threadSourceID = "thread"
|
||||
// ThreadDoc is the replicated form of a thread. Field names are part of the
|
||||
// wire format: older nodes ignore unknown keys, newer ones default missing ones.
|
||||
type ThreadDoc struct {
|
||||
UID string `json:"uid"`
|
||||
ClusterKey string `json:"cluster_key,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Motivation string `json:"motivation,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Priority string `json:"priority"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
ResolvedAt string `json:"resolved_at,omitempty"`
|
||||
UID string `json:"uid"`
|
||||
ClusterKey string `json:"cluster_key,omitempty"`
|
||||
Title string `json:"title"`
|
||||
Motivation string `json:"motivation,omitempty"`
|
||||
Status string `json:"status"`
|
||||
Priority string `json:"priority"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
ResolvedAt string `json:"resolved_at,omitempty"`
|
||||
SupersededBy string `json:"superseded_by,omitempty"`
|
||||
}
|
||||
|
||||
// NewThreadUID returns an opaque node-generated identity. Opaque on purpose:
|
||||
@@ -62,9 +63,9 @@ func (k *KnoxDB) ThreadDocFor(id int64) (*ThreadDoc, error) {
|
||||
err := k.db.QueryRow(
|
||||
`SELECT COALESCE(uid,''), COALESCE(cluster_key,''), title, COALESCE(motivation,''),
|
||||
COALESCE(status,'active'), COALESCE(priority,'medium'), COALESCE(tags,'[]'),
|
||||
COALESCE(summary,''), COALESCE(resolved_at,'')
|
||||
COALESCE(summary,''), COALESCE(resolved_at,''), COALESCE(superseded_by,'')
|
||||
FROM threads WHERE id=?`, id,
|
||||
).Scan(&d.UID, &d.ClusterKey, &d.Title, &d.Motivation, &d.Status, &d.Priority, &d.Tags, &d.Summary, &d.ResolvedAt)
|
||||
).Scan(&d.UID, &d.ClusterKey, &d.Title, &d.Motivation, &d.Status, &d.Priority, &d.Tags, &d.Summary, &d.ResolvedAt, &d.SupersededBy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -226,9 +227,9 @@ func (k *KnoxDB) upsertThreadDoc(d ThreadDoc, hcl int64) error {
|
||||
|
||||
if id == 0 {
|
||||
_, err := k.db.Exec(
|
||||
`INSERT INTO threads (uid, title, motivation, status, priority, tags, cluster_key, summary, resolved_at, hcl, provenance)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
d.UID, d.Title, d.Motivation, status, priority, d.Tags, d.ClusterKey, d.Summary, d.ResolvedAt, hcl,
|
||||
`INSERT INTO threads (uid, title, motivation, status, priority, tags, cluster_key, summary, resolved_at, superseded_by, hcl, provenance)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)`,
|
||||
d.UID, d.Title, d.Motivation, status, priority, d.Tags, d.ClusterKey, d.Summary, d.ResolvedAt, d.SupersededBy, hcl,
|
||||
fmt.Sprintf(`{"replicated":true}`))
|
||||
if err != nil {
|
||||
return fmt.Errorf("insert replicated thread %s: %w", d.UID, err)
|
||||
@@ -242,9 +243,9 @@ func (k *KnoxDB) upsertThreadDoc(d ThreadDoc, hcl int64) error {
|
||||
`UPDATE threads
|
||||
SET uid=?, title=?, motivation=?, status=?, priority=?, tags=?,
|
||||
cluster_key=COALESCE(NULLIF(?, ''), cluster_key),
|
||||
summary=?, resolved_at=?, hcl=?, updated_at=datetime('now')
|
||||
summary=?, resolved_at=?, superseded_by=?, hcl=?, updated_at=datetime('now')
|
||||
WHERE id=?`,
|
||||
d.UID, d.Title, d.Motivation, status, priority, d.Tags, d.ClusterKey, d.Summary, d.ResolvedAt, hcl, id)
|
||||
d.UID, d.Title, d.Motivation, status, priority, d.Tags, d.ClusterKey, d.Summary, d.ResolvedAt, d.SupersededBy, hcl, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update replicated thread %s: %w", d.UID, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user