Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.
Draft

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Kyle
Kyle <kthprog@gmail.com>
Kyle <kthprog@gmail.com> <Kyle.Hooks@LUXinteractive.com>

# Shane
Shane <chown_tee@proton.me>
Shane <chown_tee@proton.me> <mathmuncher11@gmail.com>
Shane <chown_tee@proton.me> <nutratracker@protonmail.com>
Shane <chown_tee@proton.me> <shane.jaroch@centurylink.com>
Shane <chown_tee@proton.me> <sjj.lumen@gmail.com>

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion sql/init-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

Expand All @@ -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";'
43 changes: 30 additions & 13 deletions sql/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SET search_path TO nt;

SET client_min_messages TO WARNING;

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

---------------------------
-- Versioning table
---------------------------
Expand All @@ -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),
Expand All @@ -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)
Expand All @@ -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
);
Expand All @@ -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
);

Expand All @@ -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 (
Expand All @@ -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,
Expand All @@ -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)
);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
Expand Down