redo tag upgrade

This commit is contained in:
Ted Unangst 2019-08-28 11:51:44 -04:00
parent 2b8a6ddd20
commit 86167991e5
2 changed files with 17 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"regexp"
"strings" "strings"
) )
@ -122,14 +123,19 @@ func upgradedb() {
fallthrough fallthrough
case 14: case 14:
doordie(db, "alter table honks add column onts text") 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 table onts (ontology text, honkid integer)")
doordie(db, "create index idx_ontology on onts(ontology)") 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) ontmap := make(map[int64][]string)
rows, err := db.Query("select honkid, noise from honks") rows, err := db.Query("select honkid, noise from honks")
if err != nil { if err != nil {
log.Fatalf("can't query honks: %s", err) log.Fatalf("can't query honks: %s", err)
} }
re_more := regexp.MustCompile(`#<span>[[:alpha:]][[:alnum:]-]*`)
for rows.Next() { for rows.Next() {
var honkid int64 var honkid int64
var noise string var noise string
@ -137,9 +143,13 @@ func upgradedb() {
if err != nil { if err != nil {
log.Fatalf("can't scan honks: %s", err) log.Fatalf("can't scan honks: %s", err)
} }
o := ontologies(noise) onts := ontologies(noise)
if len(o) > 0 { mo := re_more.FindAllString(noise, -1)
ontmap[honkid] = o for _, o := range mo {
onts = append(onts, o[7:])
}
if len(onts) > 0 {
ontmap[honkid] = oneofakind(onts)
} }
} }
rows.Close() rows.Close()
@ -171,9 +181,9 @@ func upgradedb() {
if err != nil { if err != nil {
log.Fatalf("can't commit: %s", err) 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 fallthrough
case 15: case 16:
default: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)
} }

View File

@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05"
var alreadyopendb *sql.DB var alreadyopendb *sql.DB
var dbname = "honk.db" var dbname = "honk.db"
var stmtConfig *sql.Stmt var stmtConfig *sql.Stmt
var myVersion = 15 var myVersion = 16
func initdb() { func initdb() {
schema, err := ioutil.ReadFile("schema.sql") schema, err := ioutil.ReadFile("schema.sql")