database upgrade to fixup the subject lines
Ted Unangst tedu@tedunangst.com
Fri, 24 Feb 2023 13:09:45 -0500
2 files changed,
33 insertions(+),
3 deletions(-)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -4,8 +4,6 @@ === next
+ Fix double htmlization of subject lines. -- Some existing posts will now have duplicated subjects. - + Remove the wonk support. Fun's over, back to work. + All inclusive danger zone spoiler alerts.
M
upgradedb.go
→
upgradedb.go
@@ -22,7 +22,7 @@ "strings"
"time" ) -var myVersion = 41 +var myVersion = 42 type dbexecer interface { Exec(query string, args ...interface{}) (sql.Result, error)@@ -206,6 +206,38 @@ doordie(blobdb, "PRAGMA journal_mode=WAL")
doordie(db, "update config set value = 41 where key = 'dbversion'") fallthrough case 41: + tx, err := db.Begin() + if err != nil { + elog.Fatal(err) + } + rows, err := tx.Query("select honkid, noise from honks where format = 'markdown' and precis <> ''") + if err != nil { + elog.Fatal(err) + } + m := make(map[int64]string) + var dummy Honk + for rows.Next() { + err = rows.Scan(&dummy.ID, &dummy.Noise) + if err != nil { + elog.Fatal(err) + } + precipitate(&dummy) + m[dummy.ID] = dummy.Noise + } + rows.Close() + for id, noise := range m { + _, err = tx.Exec("update honks set noise = ? where honkid = ?", noise, id) + if err != nil { + elog.Fatal(err) + } + } + err = tx.Commit() + if err != nil { + elog.Fatal(err) + } + doordie(db, "update config set value = 42 where key = 'dbversion'") + fallthrough + case 42: default: elog.Fatalf("can't upgrade unknown version %d", dbversion)