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 (
"errors"
"isthisnagee.com/tools/eng-log/db"
"isthisnagee.com/tools/diary/db"
"log"
"os"
"path"
@ -15,7 +15,7 @@ func main() {
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) {
_, err := os.Create(db_path)

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

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

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

Loading…
Cancel
Save