From 6115c446547951ee48ea7f4825786ee7633a8225 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sat, 9 Jul 2022 10:27:30 -0400 Subject: [PATCH 1/8] slight correction for macOS setup --- README.rst | 2 +- sql/init-ubuntu.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 5781e1f..4200216 100644 --- a/README.rst +++ b/README.rst @@ -40,7 +40,7 @@ https://stackoverflow.com/questions/7975556/how-can-i-start-postgresql-server-on Postgres installed with ``brew`` will already create a user under your name with appropriate permissions. -You can skip to **Step 4** of the shell Ubuntu init script. +You can skip to **Step 3.b.** of the shell Ubuntu init script. The brew install script will output more useful information, I recommend reading it and deciding if any of it is important or relevant to diff --git a/sql/init-ubuntu.sh b/sql/init-ubuntu.sh index fb676e5..78da5d2 100755 --- a/sql/init-ubuntu.sh +++ b/sql/init-ubuntu.sh @@ -25,10 +25,11 @@ sudo systemctl enable postgresql sudo update-rc.d postgresql enable sudo systemctl start postgresql -# STEP 3 +# STEP 3.a. # Set up your default user sudo -u postgres psql -c "CREATE USER $LOGNAME" sudo -u postgres psql -c "ALTER USER $LOGNAME WITH LOGIN SUPERUSER CREATEROLE CREATEDB REPLICATION BYPASSRLS" +# STEP 3.b. psql -d template1 -c "ALTER USER $LOGNAME PASSWORD 'password'" psql -d template1 -c "ALTER USER $LOGNAME VALID UNTIL 'infinity'" From b9326d5e9139db207cc803603a980e61dc2bef8f Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sat, 9 Jul 2022 18:55:54 -0400 Subject: [PATCH 2/8] quote reserved keywords, expand msg table, add app --- sql/tables.sql | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/sql/tables.sql b/sql/tables.sql index ac250e0..64d27cf 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -38,7 +38,7 @@ CREATE TABLE "version" ( CREATE TABLE country ( id int PRIMARY KEY, code text NOT NULL, - name text NOT NULL, + "name" text NOT NULL, has_zip boolean NOT NULL, requires_state boolean NOT NULL, UNIQUE (code), @@ -49,7 +49,7 @@ CREATE TABLE state ( id int PRIMARY KEY, country_id int NOT NULL, code text NOT NULL, - name text NOT NULL, + "name" text NOT NULL, UNIQUE (country_id, name), -- UNIQUE(country_id, code), FOREIGN KEY (country_id) REFERENCES country (id) @@ -76,10 +76,10 @@ CREATE TABLE email ( user_id int NOT NULL, email text NOT NULL, -- TODO: limit to 5 emails, purge old ones - main boolean NOT NULL, + "main" boolean NOT NULL, activated boolean DEFAULT FALSE, created int DEFAULT extract(epoch FROM NOW()), - UNIQUE (user_id, main), + UNIQUE (user_id, "main"), UNIQUE (email), FOREIGN KEY (user_id) REFERENCES "user" (id) ON UPDATE CASCADE ); @@ -106,11 +106,11 @@ CREATE TABLE token ( id bigserial PRIMARY KEY, user_id int NOT NULL, token text NOT NULL, - type text NOT NULL, + "type" text NOT NULL, created int DEFAULT extract(epoch FROM NOW()), expires int, UNIQUE (token), - UNIQUE (user_id, TYPE), + UNIQUE (user_id, "type"), FOREIGN KEY (user_id) REFERENCES "user" (id) ON UPDATE CASCADE ); @@ -122,12 +122,12 @@ CREATE TABLE token ( --++++++++++++++++++++++++++++ CREATE TABLE bmr_eq ( id serial PRIMARY KEY, - name text NOT NULL + "name" text NOT NULL ); CREATE TABLE bf_eq ( id serial PRIMARY KEY, - name text NOT NULL + "name" text NOT NULL ); CREATE TABLE profile ( @@ -139,7 +139,7 @@ CREATE TABLE profile ( updated int DEFAULT extract(epoch FROM NOW()), eula int DEFAULT 0, gender text, - name text, + "name" text, dob date, activity_level smallint, -- [1, 2, 3, 4, 5] goal_weight real, @@ -157,7 +157,7 @@ CREATE TABLE recipe ( user_id int NOT NULL, created int DEFAULT extract(epoch FROM NOW()), updated int DEFAULT extract(epoch FROM NOW()), - name text NOT NULL, + "name" text NOT NULL, FOREIGN KEY (user_id) REFERENCES "user" (id) ); @@ -206,7 +206,7 @@ CREATE TABLE nutr_def ( -- .. based on user upvotes/reporting?-- CREATE TABLE rec_id ( id serial PRIMARY KEY, - name text, + "name" text, serving_size text, -- NULL == "per rec.serving_size" source_urls text[] NOT NULL, UNIQUE (name) @@ -260,10 +260,24 @@ CREATE TABLE rec_dat ( -- FOREIGN KEY (user_id) REFERENCES "user" (id) ON UPDATE CASCADE -- ); -- NOTE: wip +CREATE TABLE client_app ( + id serial PRIMARY KEY, + "name" text NOT NULL UNIQUE +); + +INSERT INTO client_app + VALUES (1, 'cli'), (2, 'android'), (3, 'web'); + CREATE TABLE bug ( id bigserial PRIMARY KEY, guid uuid UNIQUE NOT NULL, - client_info jsonb NOT NULL + created int DEFAULT extract(epoch FROM NOW()), + client_app_name text, + "version" text, + "release" text, + client_info jsonb NOT NULL, + stack text, + FOREIGN KEY (client_app_name) REFERENCES client_app ("name") ON UPDATE CASCADE ON DELETE CASCADE ); CREATE TABLE msg ( From 0b68e1e67ce8608f58901e2a586db4fff2db9e6c Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Wed, 13 Jul 2022 10:19:29 -0400 Subject: [PATCH 3/8] add TODO about inserts vs. csv in tables.sql --- sql/tables.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/tables.sql b/sql/tables.sql index 64d27cf..224a38d 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -265,6 +265,7 @@ CREATE TABLE client_app ( "name" text NOT NULL UNIQUE ); +-- TODO: ? maintain other tables in SQL too, not CSV: bf_eq, bmr_eq, "version" INSERT INTO client_app VALUES (1, 'cli'), (2, 'android'), (3, 'web'); From 5cde12c612062992ab6d30ed786143d251b1bae8 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sat, 16 Jul 2022 22:02:52 -0400 Subject: [PATCH 4/8] update reqs --- requirements-lint.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements-lint.txt b/requirements-lint.txt index 00c2152..4788efc 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1,10 +1,10 @@ autopep8==1.6.0 bandit==1.7.4 -black==22.3.0 +black==22.6.0 doc8==0.11.2 flake8==4.0.1 isort==5.10.1 mypy==0.961 pycodestyle==2.8.0 -pylint==2.14.3 -yamllint==1.26.3 +pylint==2.14.4 +yamllint==1.27.1 From 7ac03f19a8c209dde6f6ae3046377d8c145b5c10 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sun, 17 Jul 2022 15:45:45 -0400 Subject: [PATCH 5/8] add mailmap --- .mailmap | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .mailmap diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..a8d540e --- /dev/null +++ b/.mailmap @@ -0,0 +1,11 @@ +# Kyle +Kyle +Kyle + +# Shane +Shane +Shane +Shane +Shane +Shane + From 69232340e29a40c77f994f48cff2e79f9ef69dda Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 7 Oct 2022 11:41:15 -0400 Subject: [PATCH 6/8] add uuid-ossp & uuid_generate_v4() --- sql/init-ubuntu.sh | 4 ++++ sql/tables.sql | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/init-ubuntu.sh b/sql/init-ubuntu.sh index 78da5d2..7b66d28 100755 --- a/sql/init-ubuntu.sh +++ b/sql/init-ubuntu.sh @@ -39,3 +39,7 @@ psql -d template1 -c "CREATE DATABASE $DB" psql -d $DB -c "CREATE SCHEMA $SCHEMA" psql -d $DB -c "DROP SCHEMA public" psql -d $DB -c "ALTER DATABASE $DB SET search_path TO $SCHEMA" + +# STEP 5 +# Install extensions and further configurations +psql -d $DB -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' diff --git a/sql/tables.sql b/sql/tables.sql index 224a38d..90f5d6d 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -271,7 +271,7 @@ INSERT INTO client_app CREATE TABLE bug ( id bigserial PRIMARY KEY, - guid uuid UNIQUE NOT NULL, + guid uuid UNIQUE DEFAULT uuid_generate_v4 () ::uuid, created int DEFAULT extract(epoch FROM NOW()), client_app_name text, "version" text, From c0e1fca639cff196847ab561132f498def26128a Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 7 Oct 2022 11:41:21 -0400 Subject: [PATCH 7/8] not null on those --- sql/tables.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sql/tables.sql b/sql/tables.sql index 90f5d6d..25678a6 100644 --- a/sql/tables.sql +++ b/sql/tables.sql @@ -22,6 +22,8 @@ SET search_path TO nt; SET client_min_messages TO WARNING; +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + --------------------------- -- Versioning table --------------------------- @@ -271,8 +273,8 @@ INSERT INTO client_app CREATE TABLE bug ( id bigserial PRIMARY KEY, - guid uuid UNIQUE DEFAULT uuid_generate_v4 () ::uuid, - created int DEFAULT extract(epoch FROM NOW()), + guid uuid NOT NULL UNIQUE DEFAULT uuid_generate_v4 () ::uuid, + created int NOT NULL DEFAULT extract(epoch FROM NOW()), client_app_name text, "version" text, "release" text, From b16fe7cfef7887057a276053c4f840537339ad2a Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Mon, 26 Feb 2024 14:10:18 -0500 Subject: [PATCH 8/8] add git tag msg to editorconfig --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 3d71ca5..093250a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -43,5 +43,5 @@ trim_trailing_whitespace = false max_line_length = 79 -[{COMMIT_EDITMSG,MERGE_MSG,SQUASH_MSG,git-rebase-todo}] +[{COMMIT_EDITMSG,MERGE_MSG,SQUASH_MSG,TAG_EDITMSG,git-rebase-todo}] max_line_length = 72