schema updates for future changes. xonkers, zonkers, and convoys, oh my.
Ted Unangst tedu@tedunangst.com
Fri, 19 Apr 2019 11:08:22 -0400
6 files changed,
39 insertions(+),
16 deletions(-)
M
activity.go
→
activity.go
@@ -254,7 +254,7 @@ return
} dt := x.Date.UTC().Format(dbtimeformat) aud := strings.Join(x.Audience, " ") - res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud, x.Noise) + res, err := stmtSaveHonk.Exec(x.UserID, x.What, x.Honker, x.XID, x.RID, dt, x.URL, aud, x.Noise, x.Convoy) if err != nil { log.Printf("err saving xonk: %s", err) return
M
fun.go
→
fun.go
@@ -260,7 +260,7 @@ if key != nil {
return } db := opendatabase() - row := db.QueryRow("select pubkey from honkers where flavor = 'key' and xid = ?", keyname) + row := db.QueryRow("select pubkey from xonkers where xid = ?", keyname) var data string err := row.Scan(&data) savekey := false@@ -293,8 +293,8 @@ ziggylock.Lock()
zaggies[keyname] = key ziggylock.Unlock() if savekey { - db.Exec("insert into honkers (name, xid, flavor, pubkey) values (?, ?, ?, ?)", - "", keyname, "key", data) + db.Exec("insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)", + keyname, "", "", "", data) } return }
M
honk.go
→
honk.go
@@ -65,6 +65,7 @@ RID string
Date time.Time URL string Noise string + Convoy string Audience []string HTML template.HTML Donks []*Donk@@ -561,7 +562,7 @@ var h Honk
var dt, aud string row := stmtOneXonk.QueryRow(xid) err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise) + &dt, &h.URL, &aud, &h.Noise, &h.Convoy) if err != nil { log.Printf("error scanning xonk: %s", err) return nil@@ -605,7 +606,7 @@ for rows.Next() {
var h Honk var dt, aud string err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise) + &dt, &h.URL, &aud, &h.Noise, &h.Convoy) if err != nil { log.Printf("error scanning honks: %s", err) return nil@@ -662,6 +663,7 @@ }
if xonk.Honker == "" { xonk.XID = fmt.Sprintf("https://%s/u/%s/h/%s", serverName, xonk.Username, xonk.XID) } + convoy := "" userinfo := GetUserInfo(r)@@ -674,13 +676,14 @@ What: "bonk",
XID: xonk.XID, Date: dt, Noise: xonk.Noise, + Convoy: convoy, Donks: xonk.Donks, Audience: oneofakind(prepend(thewholeworld, xonk.Audience)), } aud := strings.Join(bonk.Audience, " ") res, err := stmtSaveHonk.Exec(userinfo.UserID, "bonk", "", xid, "", - dt.Format(dbtimeformat), "", aud, bonk.Noise) + dt.Format(dbtimeformat), "", aud, bonk.Noise, bonk.Convoy) if err != nil { log.Printf("error saving bonk: %s", err) return@@ -720,6 +723,7 @@ what := "honk"
if rid != "" { what = "tonk" } + convoy := "" honk := Honk{ UserID: userinfo.UserID, Username: userinfo.Username,@@ -727,6 +731,7 @@ What: "honk",
XID: xid, RID: rid, Date: dt, + Convoy: convoy, } if noise[0] == '@' { honk.Audience = append(grapevine(noise), thewholeworld)@@ -813,7 +818,7 @@ }
aud := strings.Join(honk.Audience, " ") res, err := stmtSaveHonk.Exec(userinfo.UserID, what, "", xid, rid, - dt.Format(dbtimeformat), "", aud, noise) + dt.Format(dbtimeformat), "", aud, noise, convoy) if err != nil { log.Printf("error saving honk: %s", err) return@@ -1050,12 +1055,12 @@
func prepareStatements(db *sql.DB) { stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'sub' or flavor = 'peep'") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") - stmtOneXonk = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise from honks join users on honks.userid = users.userid where xid = ?") - stmtHonks = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise from honks join users on honks.userid = users.userid where honker = '' order by honkid desc limit 50") - stmtUserHonks = preparetodie(db, "select honkid, honks.userid, username, what, honker, xid, rid, dt, url, audience, noise from honks join users on honks.userid = users.userid where honker = '' and username = ? order by honkid desc limit 50") - stmtHonksForUser = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? order by honkid desc limit 250") - stmtHonksByHonker = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, honks.xid, rid, dt, url, audience, noise from honks join users on honks.userid = users.userid join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ? order by honkid desc limit 50") - stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise) values (?, ?, ?, ?, ?, ?, ?, ?, ?)") + stmtOneXonk = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where xid = ?") + stmtHonks = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' order by honkid desc limit 50") + stmtUserHonks = preparetodie(db, "select honkid, honks.userid, username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honker = '' and username = ? order by honkid desc limit 50") + stmtHonksForUser = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid where honks.userid = ? and dt > ? order by honkid desc limit 250") + stmtHonksByHonker = preparetodie(db, "select honkid, honks.userid, users.username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.name = ? order by honkid desc limit 50") + stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtFileData = preparetodie(db, "select media, content from files where xid = ?") stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?") stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
M
schema.sql
→
schema.sql
@@ -1,13 +1,19 @@
-create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text); +create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text); create table donks (honkid integer, fileid integer); create table files(fileid integer primary key, xid text, name text, url text, media text, content blob); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, pubkey text); +create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text); +create table zonkers (zonkerid integer primary key, name text, wherefore text); create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob); create index idx_honksxid on honks(xid); +create index idx_honksconvoy on honks(convoy); create index idx_honkshonker on honks(honker); create index idx_honkerxid on honkers(xid); +create index idx_xonkerxid on xonkers(xid); +create index idx_xonkerxid on xonkers(xid); +create index idx_zonkersname on zonkers(name); create index idx_filesxid on files(xid); create index idx_filesurl on files(url);
M
upgradedb.go
→
upgradedb.go
@@ -42,6 +42,18 @@ doordie(db, "create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob)")
doordie(db, "update config set value = 2 where key = 'dbversion'") fallthrough case 2: + doordie(db, "alter table honks add column convoy text") + doordie(db, "update honks set convoy = ''") + doordie(db, "create index idx_honksconvoy on honks(convoy)") + doordie(db, "create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text)") + doordie(db, "insert into xonkers (xid, ibox, obox, sbox, pubkey) select xid, '', '', '', pubkey from honkers where flavor = 'key'") + doordie(db, "delete from honkers where flavor = 'key'") + doordie(db, "create index idx_xonkerxid on xonkers(xid)") + doordie(db, "create table zonkers (zonkerid integer primary key, name text, wherefore text)") + doordie(db, "create index idx_zonkersname on zonkers(name)") + doordie(db, "update config set value = 3 where key = 'dbversion'") + fallthrough + case 3: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }