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 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 + 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/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 diff --git a/sql/init-ubuntu.sh b/sql/init-ubuntu.sh index fb676e5..7b66d28 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'" @@ -38,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 ac250e0..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 --------------------------- @@ -38,7 +40,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 +51,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 +78,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 +108,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 +124,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 +141,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 +159,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 +208,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 +262,25 @@ 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 +); + +-- 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'); + CREATE TABLE bug ( id bigserial PRIMARY KEY, - guid uuid UNIQUE NOT NULL, - client_info jsonb NOT NULL + 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, + 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 (