diff --git a/README.md b/README.md index f1f69a4..2954371 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,32 @@ The supervisor script will handle the rest, including auto-updating. ## Development -### Creating a new migration +### Migrations -Make sure you have [`golang-migrate`](https://github.com/golang-migrate/migrate) -installed via the Go toolchain, as the Homebrew installation doesn't come -compiled with the SQLite3 driver. +Prerequisites: Install +[`golang-migrate`](https://github.com/golang-migrate/migrate) with the +[`sqlite`](https://modernc.org/sqlite) driver. ```sh +go install -tags 'sqlite' github.com/golang-migrate/migrate/v4/cmd/migrate@latest +``` + +[`sqlite3`][https://github.com/mattn/go-sqlite3] would probably work too, but is +less friendly to cross-compiling. + +**WARNING:** Do not install `golang-migrate` from Homebrew, as that version does +not include any SQLite drivers. + +#### Creating a new migration + +```sh + migrate -path db/migrations create -seq -ext sql name_of_migration $EDITOR db/migrations/*name_of_migration.{up,down}.sql ``` + +#### Running migrations + +```sh +migrate -path db/migrations -database sqlite://mainframe.db up +``` diff --git a/calendar/calendar.go b/calendar/calendar.go index e3aa3a1..ebcb2d0 100644 --- a/calendar/calendar.go +++ b/calendar/calendar.go @@ -30,7 +30,7 @@ func Run(logger *log.Logger, _ string, db *sql.DB, mux *http.ServeMux, gcpClient err, ) } - fmt.Println("Upcoming events:") + logger.Println("Upcoming events:") if len(events.Items) == 0 { return fmt.Errorf("no upcoming events found") } else { @@ -39,7 +39,7 @@ func Run(logger *log.Logger, _ string, db *sql.DB, mux *http.ServeMux, gcpClient if date == "" { date = item.Start.Date } - fmt.Printf("%v (%v)\n", item.Summary, date) + logger.Printf("%v (%v)\n", item.Summary, date) } } diff --git a/db/migrations/000006_make_gcp_token_expiry_nullable.down.sql b/db/migrations/000006_make_gcp_token_expiry_nullable.down.sql new file mode 100644 index 0000000..351eea4 --- /dev/null +++ b/db/migrations/000006_make_gcp_token_expiry_nullable.down.sql @@ -0,0 +1,5 @@ +ALTER TABLE google_links +DROP COLUMN expires_at; + +ALTER TABLE google_links +ADD COLUMN expires_at TEXT NOT NULL CHECK (DATETIME(expires_at) IS NOT NULL); diff --git a/db/migrations/000006_make_gcp_token_expiry_nullable.up.sql b/db/migrations/000006_make_gcp_token_expiry_nullable.up.sql new file mode 100644 index 0000000..854d62e --- /dev/null +++ b/db/migrations/000006_make_gcp_token_expiry_nullable.up.sql @@ -0,0 +1,5 @@ +ALTER TABLE google_links +DROP COLUMN expires_at; + +ALTER TABLE google_links +ADD COLUMN expires_at TEXT CHECK (DATETIME(expires_at) IS NOT NULL); diff --git a/supervisor.sh b/supervisor.sh index 6198e91..20ee346 100755 --- a/supervisor.sh +++ b/supervisor.sh @@ -20,7 +20,7 @@ function boot () { done TMUX_WINDOW_NAME=mainframe tmux new-window -d -n $TMUX_WINDOW_NAME - tmux unlink-window -k -t $THROWAWAY_WINDOW_NAME > /dev/null 2>&1 || echo " No throwaway session to delete" + tmux unlink-window -k -t $THROWAWAY_WINDOW_NAME > /dev/null 2>&1 || echo " Throwaway session: gone" tmux send-keys -t $TMUX_WINDOW_NAME mainframe C-m sleep 2