allow for custom user options in the database

This commit is contained in:
Ted Unangst 2019-06-27 22:15:59 -04:00
parent a90e5f1766
commit 5e59b3ecef
4 changed files with 8 additions and 4 deletions

View File

@ -235,7 +235,8 @@ func showrss(w http.ResponseWriter, r *http.Request) {
func butwhatabout(name string) (*WhatAbout, error) { func butwhatabout(name string) (*WhatAbout, error) {
row := stmtWhatAbout.QueryRow(name) row := stmtWhatAbout.QueryRow(name)
var user WhatAbout var user WhatAbout
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key) var options string
err := row.Scan(&user.ID, &user.Name, &user.Display, &user.About, &user.Key, &options)
user.URL = fmt.Sprintf("https://%s/u/%s", serverName, user.Name) user.URL = fmt.Sprintf("https://%s/u/%s", serverName, user.Name)
return &user, err return &user, err
} }
@ -1525,7 +1526,7 @@ func prepareStatements(db *sql.DB) {
stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?") stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?")
stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1") stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1")
stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, local, content) values (?, ?, ?, ?, ?, ?)") stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, local, content) values (?, ?, ?, ?, ?, ?)")
stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey from users where username = ?") stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey, options from users where username = ?")
stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)")
stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)")
stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers") stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers")

View File

@ -18,7 +18,7 @@ create index idx_filesurl on files(url);
create table config (key text, value text); create table config (key text, value text);
create table users (userid integer primary key, username text, hash text, displayname text, about text, pubkey text, seckey text); create table users (userid integer primary key, username text, hash text, displayname text, about text, pubkey text, seckey text, options text);
create table auth (authid integer primary key, userid integer, hash text); create table auth (authid integer primary key, userid integer, hash text);
CREATE index idxusers_username on users(username); CREATE index idxusers_username on users(username);
CREATE index idxauth_userid on auth(userid); CREATE index idxauth_userid on auth(userid);

View File

@ -102,6 +102,9 @@ func upgradedb() {
doordie(db, "update zonkers set wherefore = 'zord' where wherefore = 'zword'") doordie(db, "update zonkers set wherefore = 'zord' where wherefore = 'zword'")
doordie(db, "update config set value = 11 where key = 'dbversion'") doordie(db, "update config set value = 11 where key = 'dbversion'")
case 11: case 11:
doordie(db, "alter table users add column options text")
doordie(db, "update users set options = ''")
doordie(db, "update config set value = 12 where key = 'dbversion'")
default: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)
} }

View File

@ -71,7 +71,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 = 11 var myVersion = 12
func initdb() { func initdb() {
schema, err := ioutil.ReadFile("schema.sql") schema, err := ioutil.ReadFile("schema.sql")