Rename to diary

Also, this should be in a separate commit, but update the initial
migration
pull/8/head
isthisnagee 3 years ago
parent 42a61dcddb
commit 4994ecf63c

@ -2,7 +2,7 @@ package main
import ( import (
"errors" "errors"
"isthisnagee.com/tools/eng-log/db" "isthisnagee.com/tools/diary/db"
"log" "log"
"os" "os"
"path" "path"
@ -15,7 +15,7 @@ func main() {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
var db_path = path.Join(home_dir, ".dev-log.sql") var db_path = path.Join(home_dir, ".diary.sql")
if _, err := os.Stat(db_path); errors.Is(err, os.ErrNotExist) { if _, err := os.Stat(db_path); errors.Is(err, os.ErrNotExist) {
_, err := os.Create(db_path) _, err := os.Create(db_path)

@ -13,8 +13,8 @@ import (
var __version = 1 var __version = 1
type DbCtx struct { type DbCtx struct {
db *sql.DB Db *sql.DB
version int Version int
} }
func initVersion(tx *sql.Tx) (int, error) { func initVersion(tx *sql.Tx) (int, error) {
@ -40,19 +40,16 @@ func initVersion(tx *sql.Tx) (int, error) {
} }
func migration0(tx *sql.Tx) error { func migration0(tx *sql.Tx) error {
// Optionally add the version table
if _, err := tx.Exec(` if _, err := tx.Exec(`
create table if not exists eng_log_version (id integer not null); create table if not exists diary_log (
`); err != nil { id integer not null primary key,
tx.Rollback() title text,
return fmt.Errorf("Could not create eng_log_version. %w", err) created_at int not null default (strftime('%s','now')),
} version int not null default 0
// Optionally add the log table )
if _, err := tx.Exec(`
create table if not exists log (id integer not null primary key, title string)
`); err != nil { `); err != nil {
tx.Rollback() tx.Rollback()
return fmt.Errorf("Could not create log. %w", err) return fmt.Errorf("Could not create diary_log. %w", err)
} }
return nil return nil
} }

@ -29,15 +29,15 @@ func TestInitBasic(t *testing.T) {
// check that the tables exist // check that the tables exist
var table_name string var table_name string
ctx.db.QueryRow( ctx.Db.QueryRow(
"SELECT name FROM sqlite_master WHERE type='table' AND name='log';", "SELECT name FROM sqlite_master WHERE type='table' AND name='diary_log';",
).Scan(&table_name) ).Scan(&table_name)
assert_string(t, "log", table_name) assert_string(t, "diary_log", table_name)
// Check that the version stored is correct // Check that the version stored is correct
var version int var version int
ctx.db.QueryRow("PRAGMA user_version").Scan(&version) ctx.Db.QueryRow("PRAGMA user_version").Scan(&version)
assert_int(t, __version, ctx.version) assert_int(t, __version, ctx.Version)
assert_int(t, __version, version) assert_int(t, __version, version)
} }

@ -1,4 +1,4 @@
module isthisnagee.com/tools/eng-log module isthisnagee.com/tools/diary
go 1.17 go 1.17

Loading…
Cancel
Save