all repos — honk @ 6efd4cb5d646e926f486e660ec1e59120fb64bfe

my fork of honk

upgradedb.go (view raw)

 1//
 2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
 3//
 4// Permission to use, copy, modify, and distribute this software for any
 5// purpose with or without fee is hereby granted, provided that the above
 6// copyright notice and this permission notice appear in all copies.
 7//
 8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16package main
17
18import (
19	"log"
20	"os"
21)
22
23func upgradedb() {
24	db := opendatabase()
25	dbversion := 0
26	getconfig("dbversion", &dbversion)
27
28	var err error
29	switch dbversion {
30	case 0:
31		_, err = db.Exec("insert into config (key, value) values ('dbversion', 1)")
32		if err != nil {
33			log.Fatal(err)
34		}
35		fallthrough
36	case 1:
37	default:
38		log.Fatalf("can't upgrade unknown version %d", dbversion)
39	}
40	os.Exit(0)
41}