diff options
author | Matthew Lemon <y@yulqen.org> | 2024-12-12 12:17:24 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-12-12 12:17:24 +0000 |
commit | 60ef12ed6bbc34f7b7d0c0eb16a10a68be7786ee (patch) | |
tree | d03c4c9f9ca5e858287177687f85397e3dabd2b7 | |
parent | a3858f85de6cb1e486b6be0256affd29fd49f821 (diff) |
Logging to postgres!
-rwxr-xr-x | tjp.sh | 112 |
1 files changed, 112 insertions, 0 deletions
@@ -0,0 +1,112 @@ +#!/bin/sh + +# Tool to add entries to journal on postgres on rimsky. +# Requires server to be up, ~/.pgpass to be in place. + +# Database connection details +HOST="postgres.banded-neon.ts.net" +USER="postgresql" +DB="journal" +DB_CONTACTS="contacts" + +# Add MOD contact +add_MOD_contact() { + echo "Enter first name:" + read mod_first_name + echo "Enter last name:" + read mod_last_name + contact_id=$(psql -h "$HOST" -U "$USER" -d "$DB_CONTACTS" -c "INSERT INTO contacts (first_name, last_name, contact_type) VALUES ('$mod_first_name', '$mod_last_name', 3) RETURNING id;") + echo "MOD contact added with ID: $contact_id. Feel free to go in and add comments, email and phone number separately." +} + +# Function to add a personal entry +add_personal_entry() { + echo "Enter your personal journal entry:" + read entry + psql -h "$HOST" -U "$USER" -d "$DB" -c "INSERT INTO journal_entries (entry, type) VALUES ('$entry', 2);" +} + +# Function to add a MOD entry +add_MOD_entry() { + echo "Enter your MOD journal entry:" + read entry + psql -h "$HOST" -U "$USER" -d "$DB" -c "INSERT INTO journal_entries (entry, type) VALUES ('$entry', 1);" +} + +# Function to select all personal entries +list_personal_entries() { + psql -h "$HOST" -U "$USER" -d "$DB" -c "SELECT * FROM journal_entries WHERE type = 2;" +} + +# Function to select all MOD entries +list_MOD_entries() { + psql -h "$HOST" -U "$USER" -d "$DB" -c "\x" -c "SELECT * FROM journal_entries WHERE type = 1;" +} + +# Function to list all MOD contacts +list_MOD_contacts() { + psql -h "$HOST" -U "$USER" -d "$DB_CONTACTS" -c "SELECT * FROM contacts WHERE contact_type = 3;" +} + +# Function to add a new meeting +add_meeting() { + echo "Enter meeting name:" + read meeting_name + echo "Enter date (ISO):" + read meeting_date + echo "Enter meeting subject:" + read meeting_subject + meeting_id=$(psql -h "$HOST" -U "$USER" -d "$DB" -t -c "INSERT INTO meetings (name, date, subject) VALUES ('$meeting_name', '$meeting_date', '$meeting_subject') RETURNING id;") + echo "Meeting added with ID: $meeting_id" +} + +# Function to add a journal entry for an existing meeting +add_entry_to_meeting() { + meeting_id=$1 + echo "Enter your journal entry for meeting ID $meeting_id:" + read entry + psql -h "$HOST" -U "$USER" -d "$DB" -c "INSERT INTO journal_entries (entry, meeting_id) VALUES ('$entry', $meeting_id);" +} + +# Main script logic +case "$1" in + -p) + add_personal_entry + ;; + -m) + add_MOD_entry + ;; + -C) + add_MOD_contact + ;; + -y) list_MOD_contacts + ;; + -l) + list_personal_entries + ;; + -M) + list_MOD_entries + ;; + -e) + add_meeting + ;; + -E) + if [ -n "$2" ]; then + add_entry_to_meeting "$2" + else + echo "Error: Meeting ID required." + fi + ;; + *) + echo "Usage:" + echo " jlp -p - Add personal entry" + echo " jlp -m - Add MOD entry" + echo " jlp -C - Add MOD contact" + echo " jlp -y - Select all MOD contacts" + echo " jlp -l - Select all personal entries" + echo " jlp -M - Select all MOD entries" + echo " jlp -e - Add new meeting (returns meeting ID)" + echo " jlp -E ID - Add new journal entry for meeting whose ID is ID" + ;; +esac + |