Skip to content

Commit

Permalink
refactor: split db tables (#36)
Browse files Browse the repository at this point in the history
* split db tables
* add 90% of the carewallet peeps to a group
  • Loading branch information
MattCMcCoy authored Feb 23, 2024
1 parent 4c2985b commit 9066bb0
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 181 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/BackendCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ jobs:
uses: actions/checkout@v4

- name: Import DB seed data
run: psql -d postgresql://user:[email protected]:5432/carewallet -f init.sql
run: |
for file in $(ls -1 ./ | sort); do
psql -d postgresql://user:[email protected]:5432/carewallet -f "$file"
done
working-directory: ./backend/db/migrations

- name: Set up Go
Expand Down
32 changes: 32 additions & 0 deletions backend/db/migrations/1.user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
DROP TABLE IF EXISTS users;

CREATE TABLE IF NOT EXISTS users (
user_id varchar NOT NULL UNIQUE,
first_name varchar NOT NULL,
last_name varchar NOT NULL,
email varchar NOT NULL,
phone varchar, --potentially make phone/address required (NOT NULL)
address varchar,
pfp_s3_url varchar, --for profile picture if we implement that
device_id varchar, --expoPushToken for push notifications
push_notification_enabled BOOLEAN DEFAULT FALSE,
PRIMARY KEY (user_id)
);

INSERT INTO users (user_id, first_name, last_name, email, phone, address)
VALUES
('user1', 'John', 'Smith', '[email protected]', '123-456-7890', '123 Main St'),
('user2', 'Jane', 'Doe', '[email protected]', '987-654-3210', '456 Elm St'),
('user3', 'Bob', 'Johnson', '[email protected]', NULL, NULL),
('user4', 'Emily', 'Garcia', '[email protected]', '555-1212', '789 Oak Ave'),

-- Care-Wallet Team
('fIoFY26mJnYWH8sNdfuVoxpnVnr1', 'Matt', 'McCoy', '[email protected]', '', ''),
('BLq3MXk4rVg4RKuYiMd7aEmMhsz1', 'Ansh', 'Patel', '[email protected]', '', ''),
('mPeo3d3MiXfnpPJADWgFD9ZcB2M2', 'Olivia', 'Sedarski', '[email protected]', '', ''),
('onrQs8HVGBVMPNz4Fk1uE94bSxg1', 'Danny', 'Rollo', '[email protected]', '', ''),
('8Sy7xBkGiGQv4ZKphcQfY8PxAqw1', 'Narayan', 'Sharma', '[email protected]', '', ''),
('iL7PnjS4axQffmlPceobjUUZ9DF2', 'Caitlin', 'Flynn', '[email protected]', '', ''),
('5JgN2PQxCRM9VoCiiFPlQPNqkL32', 'Linwood', 'Blaisdell', '[email protected]', '', '')
-- End Care-Wallet Team
;
53 changes: 53 additions & 0 deletions backend/db/migrations/2.group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
DROP TABLE IF EXISTS care_group;
DROP TABLE IF EXISTS group_roles;

CREATE TYPE role AS ENUM ('PATIENT', 'PRIMARY', 'SECONDARY');

CREATE TABLE IF NOT EXISTS care_group (
group_id serial NOT NULL UNIQUE,
group_name varchar NOT NULL,
date_created timestamp NOT NULL, --do we default current time?
PRIMARY KEY (group_id)
);

CREATE TABLE IF NOT EXISTS group_roles (
group_id integer NOT NULL,
user_id varchar NOT NULL,
role role NOT NULL,
PRIMARY KEY (group_id, user_id),
FOREIGN KEY (group_id) REFERENCES care_group (group_id),
FOREIGN KEY (user_id) REFERENCES users (user_id)
);

INSERT INTO care_group (group_name, date_created)
VALUES
('Smith Family', NOW()),
('Johnson Support Network', NOW()),
('Williams Care Team', NOW()),
('Brown Medical Group', NOW()),

-- Care-Wallet Team
('We <3 Old People', NOW())
-- End Care-Wallet Team
;

INSERT INTO group_roles (group_id, user_id, role)
VALUES
(1, 'user1', 'PATIENT'),
(1, 'user2', 'PRIMARY'),
(2, 'user3', 'PRIMARY'),
(2, 'user4', 'SECONDARY'),
(3, 'user4', 'PATIENT'),
(4, 'user1', 'SECONDARY'),
(4, 'user3', 'SECONDARY'),

-- Care-Wallet Team
(5, 'fIoFY26mJnYWH8sNdfuVoxpnVnr1', 'PRIMARY'),
(5, '5JgN2PQxCRM9VoCiiFPlQPNqkL32', 'PATIENT'),
(5, 'BLq3MXk4rVg4RKuYiMd7aEmMhsz1', 'SECONDARY'),
(5, 'mPeo3d3MiXfnpPJADWgFD9ZcB2M2', 'SECONDARY'),
(5, 'onrQs8HVGBVMPNz4Fk1uE94bSxg1', 'SECONDARY'),
(5, '8Sy7xBkGiGQv4ZKphcQfY8PxAqw1', 'SECONDARY'),
(5, 'iL7PnjS4axQffmlPceobjUUZ9DF2', 'SECONDARY')
-- End Care-Wallet Team
;
55 changes: 55 additions & 0 deletions backend/db/migrations/3.task.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
DROP TABLE IF EXISTS task;
DROP TABLE IF EXISTS task_assignees;
DROP TABLE IF EXISTS task_labels;

CREATE TYPE task_assignment_status AS ENUM ('ACCEPTED', 'DECLINED', 'NOTIFIED');
CREATE TYPE task_status AS ENUM ('INCOMPLETE', 'COMPLETE', 'PARTIAL');
CREATE TYPE task_type AS ENUM ('med_mgmt', 'dr_appt', 'financial', 'other');

CREATE TABLE IF NOT EXISTS task (
task_id serial NOT NULL,
group_id integer NOT NULL,
created_by varchar NOT NULL,
created_date timestamp NOT NULL, -- add default val with current timestamp?
start_date timestamp,
end_date timestamp,
notes varchar,
repeating BOOLEAN DEFAULT FALSE,
repeating_interval varchar,
repeating_end_date timestamp,
task_status task_status NOT NULL,
task_type task_type NOT NULL, -- (eg. medication management, dr appointment, etc.)
task_info json,
PRIMARY KEY (task_id),
FOREIGN KEY (group_id) REFERENCES care_group (group_id),
FOREIGN KEY (created_by) REFERENCES users (user_id)
);

CREATE TABLE IF NOT EXISTS task_assignees (
task_id integer NOT NULL,
user_id varchar NOT NULL,
assignment_status task_assignment_status NOT NULL,
assigned_by varchar NOT NULL,
assigned_date timestamp NOT NULL, -- add default val with current timestamp?
last_notified timestamp,
PRIMARY KEY (task_id, user_id),
FOREIGN KEY (task_id) REFERENCES task (task_id),
FOREIGN KEY (user_id) REFERENCES users (user_id),
FOREIGN KEY (assigned_by) REFERENCES users (user_id)
);

INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type)
VALUES
(1, 'user2', '2024-02-03 10:45:00', '2024-02-05 10:00:00', '2024-02-05 11:00:00', 'Pick up medication from pharmacy', 'INCOMPLETE', 'med_mgmt'),
(2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other'),
(3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial'),
(4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other')
;

INSERT INTO task_assignees (task_id, user_id, assignment_status, assigned_by, assigned_date)
VALUES
(1, 'user1', 'ACCEPTED', 'user2', NOW()),
(2, 'user3', 'NOTIFIED', 'user3', NOW()),
(3, 'user4', 'DECLINED', 'user4', NOW()),
(4, 'user2', 'DECLINED', 'user1', NOW())
;
35 changes: 35 additions & 0 deletions backend/db/migrations/4.label.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
DROP TABLE IF EXISTS label;

CREATE TABLE If NOT EXISTS label (
group_id integer NOT NULL,
label_name varchar NOT NULL,
label_color varchar NOT NULL,
PRIMARY KEY (group_id, label_name),
FOREIGN KEY (group_id) REFERENCES care_group (group_id)
);

CREATE TABLE If NOT EXISTS task_labels (
task_id integer NOT NULL,
group_id integer NOT NULL,
label_name varchar NOT NULL,
PRIMARY KEY (task_id, label_name),
FOREIGN KEY (task_id) REFERENCES task (task_id) ON UPDATE CASCADE,
FOREIGN KEY (group_id, label_name) REFERENCES label (group_id, label_name) ON UPDATE CASCADE
);

INSERT INTO label (group_id, label_name, label_color)
VALUES
(1, 'Medication', 'blue'),
(2, 'Appointments', 'green'),
(3, 'Financial', 'orange'),
(4, 'Household', 'purple'),
(1, 'Household', 'purple')
;

INSERT INTO task_labels (task_id, group_id, label_name)
VALUES
(1, 1, 'Medication'),
(2, 2, 'Appointments'),
(3, 3, 'Financial'),
(4, 4, 'Household')
;
15 changes: 15 additions & 0 deletions backend/db/migrations/5.files.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DROP TABLE IF EXISTS files;

CREATE TABLE IF NOT EXISTS files (
file_id serial NOT NULL UNIQUE,
file_name varchar NOT NULL,
group_id integer NOT NULL,
upload_by varchar NOT NULL,
upload_date timestamp,
file_size integer NOT NULL,
task_id integer,
PRIMARY KEY (file_id),
FOREIGN KEY (group_id) REFERENCES care_group (group_id),
FOREIGN KEY (upload_by) REFERENCES users (user_id),
FOREIGN KEY (task_id) REFERENCES task (task_id)
);
Loading

0 comments on commit 9066bb0

Please sign in to comment.