From 23117ad450b54fb1838d5e1365057f0e318e372f Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 24 Feb 2023 13:09:45 -0500 Subject: [PATCH] database upgrade to fixup the subject lines --- docs/changelog.txt | 2 -- upgradedb.go | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index d1a3350..5f76b58 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -4,8 +4,6 @@ changelog + 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. diff --git a/upgradedb.go b/upgradedb.go index 533ff9c..c7d4004 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -22,7 +22,7 @@ import ( "time" ) -var myVersion = 41 +var myVersion = 42 type dbexecer interface { Exec(query string, args ...interface{}) (sql.Result, error) @@ -206,6 +206,38 @@ func upgradedb() { 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)