all repos — honk @ 7c1ab40bfe33c42d3221a8b1c15dd282db59d7ca

my fork of honk

redo tag upgrade
Ted Unangst tedu@tedunangst.com
Wed, 28 Aug 2019 11:51:44 -0400
commit

7c1ab40bfe33c42d3221a8b1c15dd282db59d7ca

parent

3604c44d14b13b7bed79d24303ecc164b1414faf

2 files changed, 17 insertions(+), 7 deletions(-)

jump to
M upgradedb.goupgradedb.go

@@ -20,6 +20,7 @@ "database/sql"

"fmt" "log" "os" + "regexp" "strings" )

@@ -122,14 +123,19 @@ doordie(db, "update config set value = 14 where key = 'dbversion'")

fallthrough case 14: doordie(db, "alter table honks add column onts text") - doordie(db, "update honks set onts = ''") doordie(db, "create table onts (ontology text, honkid integer)") doordie(db, "create index idx_ontology on onts(ontology)") + doordie(db, "update config set value = 15 where key = 'dbversion'") + fallthrough + case 15: + doordie(db, "update honks set onts = ''") + doordie(db, "delete from onts") ontmap := make(map[int64][]string) rows, err := db.Query("select honkid, noise from honks") if err != nil { log.Fatalf("can't query honks: %s", err) } + re_more := regexp.MustCompile(`#<span>[[:alpha:]][[:alnum:]-]*`) for rows.Next() { var honkid int64 var noise string

@@ -137,9 +143,13 @@ err := rows.Scan(&honkid, &noise)

if err != nil { log.Fatalf("can't scan honks: %s", err) } - o := ontologies(noise) - if len(o) > 0 { - ontmap[honkid] = o + onts := ontologies(noise) + mo := re_more.FindAllString(noise, -1) + for _, o := range mo { + onts = append(onts, o[7:]) + } + if len(onts) > 0 { + ontmap[honkid] = oneofakind(onts) } } rows.Close()

@@ -171,9 +181,9 @@ err = tx.Commit()

if err != nil { log.Fatalf("can't commit: %s", err) } - doordie(db, "update config set value = 15 where key = 'dbversion'") + doordie(db, "update config set value = 16 where key = 'dbversion'") fallthrough - case 15: + case 16: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -72,7 +72,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 15 +var myVersion = 16 func initdb() { schema, err := ioutil.ReadFile("schema.sql")