From 4994ecf63c338fa5d00e1c8893bb51364efcd8d2 Mon Sep 17 00:00:00 2001 From: isthisnagee Date: Sat, 25 Dec 2021 21:13:41 -0800 Subject: [PATCH] Rename to diary Also, this should be in a separate commit, but update the initial migration --- cmd/diary/main.go | 4 ++-- db/db.go | 21 +++++++++------------ db/db_test.go | 10 +++++----- go.mod | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmd/diary/main.go b/cmd/diary/main.go index 904d279..f9f483a 100644 --- a/cmd/diary/main.go +++ b/cmd/diary/main.go @@ -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) diff --git a/db/db.go b/db/db.go index 710a683..42bd429 100644 --- a/db/db.go +++ b/db/db.go @@ -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); + 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 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) - `); 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 } diff --git a/db/db_test.go b/db/db_test.go index 643391e..67361b0 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -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) } diff --git a/go.mod b/go.mod index 45a8fc0..0d25432 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module isthisnagee.com/tools/eng-log +module isthisnagee.com/tools/diary go 1.17