Skip to content

Commit a36cde4

Browse files
committed
fixup
1 parent e2f9632 commit a36cde4

File tree

6 files changed

+308
-66
lines changed

6 files changed

+308
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/target
2+
dbml-error.log

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,46 @@ The platform itself is useful for professional independent coaches, informal men
1111

1212
## Basic Local DB Setup and Management
1313

14-
### Set Up Database
14+
## Running the Database Setup Script
15+
16+
1. Ensure you have PostgreSQL installed and running on your machine. If you're using macOS, you can install it with Homebrew:
17+
18+
```shell
19+
brew install postgresql
20+
brew services start postgresql
21+
```
22+
23+
2. Make sure you have the `dbml2sql` tool installed. You can install it with npm:
24+
25+
```shell
26+
npm install -g dbml2sql
27+
```
28+
29+
3. Make the script executable:
30+
31+
```shell
32+
chmod +x rebuild_db.sh
33+
```
34+
35+
4. Run the script with default settings:
36+
37+
```shell
38+
./rebuild_db.sh
39+
```
40+
41+
This will create a database named `refactor_platform`, a user named `refactor`, and a schema named `refactor_platform`.
42+
43+
5. If you want to use different settings, you can provide them as arguments to the script:
44+
45+
```shell
46+
./rebuild_db.sh my_database my_user my_schema
47+
```
48+
49+
This will create a database named `my_database`, a user named `my_user`, and a schema named `my_schema`.
50+
51+
Please note that the script assumes that the password for the new PostgreSQL user is `password`. If you want to use a different password, you'll need to modify the script accordingly.
52+
53+
### Set Up Database Manually
1554
1655
Note: these are commands meant to run against a real Postgresql server with an admin level user.
1756

docs/db/refactor_platform_rs.dbml

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,106 @@
22
// Docs: https://dbml.dbdiagram.io/docs
33

44
Table refactor_platform.organizations {
5-
id integer [primary key, unique, not null, increment]
5+
id uuid [primary key, unique, not null]
66
name varchar [note: 'The name of the organization that the coach <--> coachee belong to']
77
logo varchar [note: 'A URI pointing to the organization\'s logo icon file']
8-
created_at timestamp
8+
created_at timestamp
9+
updated_at timestamp [note: 'The last date and time fields were changed']
910
}
1011

1112
// Coaching relationship type belonging to the refactor_platform schema
1213
// from the perspective of the coach
13-
enum refactor_platform.coaching_relationship {
14-
client
15-
direct_report
16-
}
17-
18-
// Declares a coach <--> coachee coaching relationship
19-
// E.g. Manager <--> Software Engineer direct report
20-
// E.g. Independent coach <--> Software Engineer client
21-
Table refactor_platform.coaches_coachees {
22-
id integer [primary key, unique, not null, increment]
23-
organization_id integer [note: 'The organization associated with this coaching relationship']
24-
coach_id integer [note: 'The coach associated with this coaching relationship']
25-
coachee_id integer [note: 'The coachee associated with this coaching relationship']
26-
relationship coaching_relationship
14+
Table refactor_platform.coaching_relationships {
15+
id uuid [primary key, unique, not null]
16+
organization_id uuid [not null, note: 'The organization associated with this coaching relationship']
17+
coach_id uuid [not null, note: 'The coach associated with this coaching relationship']
18+
coachee_id uuid [not null, note: 'The coachee associated with this coaching relationship']
19+
created_at timestamp
20+
updated_at timestamp [note: 'The last date and time fields were changed']
2721
}
2822

2923
Table refactor_platform.users {
30-
id integer [primary key, unique, not null, increment]
24+
id uuid [primary key, unique, not null]
3125
email varchar
3226
first_name varchar
3327
last_name varchar
3428
display_name varchar [note: 'If a user wants to go by something other than first & last names']
3529
password varchar
36-
timezone timezone
30+
timezone varchar
3731
github_username varchar // Specifically GH for now, can generalize later
3832
github_profile_url varchar
3933
created_at timestamp
40-
}
41-
42-
Table refactor_platform.coachees {
43-
id integer [primary key, unique, not null, increment]
44-
user_id integer
45-
organization_id integer
46-
}
47-
48-
Table refactor_platform.coaches {
49-
id integer [primary key, unique, not null, increment]
50-
user_id integer
51-
organization_id integer
34+
updated_at timestamp [note: 'The last date and time fields were changed']
5235
}
5336

5437
Table refactor_platform.coaching_sessions {
55-
id integer [primary key, unique, not null, increment]
56-
coaches_coachees_id integer [note: 'The coaching relationship (i.e. what coach & coachee under what organization) associated with this coaching session']
38+
id uuid [primary key, unique, not null]
39+
coaching_relationship_id uuid [not null, note: 'The coaching relationship (i.e. what coach & coachee under what organization) associated with this coaching session']
5740
date timestamp [note: 'The date and time of a session']
58-
timezone timezone [note: 'The baseline timezone used for the `date` field']
41+
timezone varchar [note: 'The baseline timezone used for the `date` field']
5942
created_at timestamp
43+
updated_at timestamp [note: 'The last date and time fields were changed']
6044
}
6145

6246
Table refactor_platform.overarching_goals {
63-
id integer [primary key, unique, not null, increment]
64-
coaching_session_id integer [note: 'The coaching session that an overarching goal is associated with']
47+
id uuid [primary key, unique, not null]
48+
coaching_session_id uuid [note: 'The coaching session that an overarching goal is associated with']
6549
title varchar [note: 'A short description of an overarching goal']
6650
details varchar [note: 'A long description of an overarching goal']
67-
completed boolean // May be unnecessary if there's a valid completed_at timestamp
6851
completed_at timestamp [note: 'The date and time an overarching goal was completed']
69-
completed_by_id integer [note: 'The user that successfully completed an overarching goal']
7052
created_at timestamp
71-
updated_at timestamp [note: 'The last date and time an overarching goal\'s fields were changed']
53+
updated_at timestamp [note: 'The last date and time fields were changed']
7254
}
7355

7456
Table refactor_platform.notes {
75-
id integer [primary key, unique, not null, increment]
76-
coaching_session_id integer
57+
id uuid [primary key, unique, not null]
58+
coaching_session_id uuid [not null]
7759
body varchar [note: 'Main text of the note supporting Markdown']
60+
user_id uuid [not null, note: 'User that created (owns) the note']
7861
created_at timestamp
7962
updated_at timestamp [note: 'The last date and time an overarching note\'s fields were changed']
8063
}
8164

8265
Table refactor_platform.agreements {
83-
id integer [primary key, unique, not null, increment]
84-
coaching_session_id integer
66+
id uuid [primary key, unique, not null]
67+
coaching_session_id uuid [not null]
8568
details varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
69+
user_id uuid [not null, note: 'User that created (owns) the agreement']
8670
created_at timestamp
8771
updated_at timestamp [note: 'The last date and time an overarching agreement\'s fields were changed']
8872
}
8973

9074
Table refactor_platform.actions {
91-
id integer [primary key, unique, not null, increment]
75+
id uuid [primary key, unique, not null]
9276
// The first session where this action was created
9377
// It will carry forward to every future session until
9478
// its due_by is passed or it was completed by the coachee
95-
coaching_session_id integer
79+
coaching_session_id uuid [not null]
9680
due_by timestamp
9781
completed boolean // May be unnecessary if there's a valid completed_at timestamp
9882
completed_at timestamp
9983
created_at timestamp
10084
updated_at timestamp
10185
}
10286

103-
// coaches_coachees relationships
104-
Ref: refactor_platform.coaches_coachees.organization_id - refactor_platform.organizations.id
105-
Ref: refactor_platform.coaches_coachees.coachee_id - refactor_platform.coachees.id
106-
Ref: refactor_platform.coaches_coachees.coach_id - refactor_platform.coaches.id
107-
108-
// coachees relationships
109-
Ref: refactor_platform.coachees.user_id - refactor_platform.users.id
110-
Ref: refactor_platform.coachees.organization_id > refactor_platform.organizations.id
87+
// coaching_relationships relationships
88+
Ref: refactor_platform.coaching_relationships.organization_id > refactor_platform.organizations.id
89+
Ref: refactor_platform.coaching_relationships.coachee_id > refactor_platform.users.id
90+
Ref: refactor_platform.coaching_relationships.coach_id > refactor_platform.users.id
11191

112-
// coaches relationships
113-
Ref: refactor_platform.coaches.user_id - refactor_platform.users.id
114-
Ref: refactor_platform.coaches.organization_id > refactor_platform.organizations.id
92+
// coaching_sessions relationships
93+
Ref: refactor_platform.coaching_sessions.coaching_relationship_id > refactor_platform.coaching_relationships.id
11594

11695
// overarching_goals relationships
117-
Ref: refactor_platform.overarching_goals.coaching_session_id - refactor_platform.coaching_sessions.id
118-
Ref: refactor_platform.overarching_goals.completed_by_id - refactor_platform.users.id
96+
Ref: refactor_platform.overarching_goals.coaching_session_id > refactor_platform.coaching_sessions.id
11997

12098
// notes relationships
121-
Ref: refactor_platform.notes.coaching_session_id - refactor_platform.coaching_sessions.id
122-
123-
// coaching_sessions relationships
124-
Ref: refactor_platform.coaching_sessions.coaches_coachees_id > refactor_platform.coaches_coachees.id
99+
Ref: refactor_platform.notes.coaching_session_id > refactor_platform.coaching_sessions.id
100+
Ref: refactor_platform.notes.user_id > refactor_platform.users.id
125101

126102
// agreements relationships
127103
Ref: refactor_platform.agreements.coaching_session_id > refactor_platform.coaching_sessions.id
104+
Ref: refactor_platform.agreements.user_id > refactor_platform.users.id
128105

129106
// actions relationships
130107
Ref: refactor_platform.actions.coaching_session_id > refactor_platform.coaching_sessions.id

migration/src/m20240211_174355_base_migration.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,23 @@ impl MigrationTrait for Migration {
2121

2222
file.read_to_string(&mut sql).map_err(stringify_err)?;
2323

24-
// format sql as valid sql statements
25-
sql = sql.replace(";", ";\n");
24+
process_sql(&sql);
2625

2726
db.execute_unprepared(&sql).await?;
2827

2928
Ok(())
3029
}
3130

3231
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
33-
// Replace the sample below with your own migration scripts
34-
todo!();
32+
Ok(())
3533
}
3634
}
35+
36+
// format sql as valid sql statements
37+
fn process_sql(sql: &str) -> String {
38+
sql.replace(";", ";\n")
39+
.lines()
40+
.filter(|line| !line.trim().starts_with("--"))
41+
.collect::<Vec<_>>()
42+
.join("\n")
43+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
-- SQL dump generated using DBML (dbml-lang.org)
2+
-- Database: PostgreSQL
3+
-- Generated at: 2024-02-17T18:41:48.352Z
4+
5+
6+
CREATE TABLE "refactor_platform"."organizations" (
7+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
8+
"name" varchar,
9+
"logo" varchar,
10+
"created_at" timestamp,
11+
"updated_at" timestamp
12+
);
13+
14+
CREATE TABLE "refactor_platform"."coaching_relationships" (
15+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
16+
"organization_id" uuid NOT NULL,
17+
"coach_id" uuid NOT NULL,
18+
"coachee_id" uuid NOT NULL,
19+
"created_at" timestamp,
20+
"updated_at" timestamp
21+
);
22+
23+
CREATE TABLE "refactor_platform"."users" (
24+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
25+
"email" varchar,
26+
"first_name" varchar,
27+
"last_name" varchar,
28+
"display_name" varchar,
29+
"password" varchar,
30+
"timezone" varchar,
31+
"github_username" varchar,
32+
"github_profile_url" varchar,
33+
"created_at" timestamp,
34+
"updated_at" timestamp
35+
);
36+
37+
CREATE TABLE "refactor_platform"."coaching_sessions" (
38+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
39+
"coaching_relationship_id" uuid NOT NULL,
40+
"date" timestamp,
41+
"timezone" varchar,
42+
"created_at" timestamp,
43+
"updated_at" timestamp
44+
);
45+
46+
CREATE TABLE "refactor_platform"."overarching_goals" (
47+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
48+
"coaching_session_id" uuid,
49+
"title" varchar,
50+
"details" varchar,
51+
"completed_at" timestamp,
52+
"created_at" timestamp,
53+
"updated_at" timestamp
54+
);
55+
56+
CREATE TABLE "refactor_platform"."notes" (
57+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
58+
"coaching_session_id" uuid NOT NULL,
59+
"body" varchar,
60+
"user_id" uuid NOT NULL,
61+
"created_at" timestamp,
62+
"updated_at" timestamp
63+
);
64+
65+
CREATE TABLE "refactor_platform"."agreements" (
66+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
67+
"coaching_session_id" uuid NOT NULL,
68+
"details" varchar,
69+
"user_id" uuid NOT NULL,
70+
"created_at" timestamp,
71+
"updated_at" timestamp
72+
);
73+
74+
CREATE TABLE "refactor_platform"."actions" (
75+
"id" uuid UNIQUE PRIMARY KEY NOT NULL,
76+
"coaching_session_id" uuid NOT NULL,
77+
"due_by" timestamp,
78+
"completed" boolean,
79+
"completed_at" timestamp,
80+
"created_at" timestamp,
81+
"updated_at" timestamp
82+
);
83+
84+
COMMENT ON COLUMN "refactor_platform"."organizations"."name" IS 'The name of the organization that the coach <--> coachee belong to';
85+
86+
COMMENT ON COLUMN "refactor_platform"."organizations"."logo" IS 'A URI pointing to the organization''s logo icon file';
87+
88+
COMMENT ON COLUMN "refactor_platform"."organizations"."updated_at" IS 'The last date and time fields were changed';
89+
90+
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."organization_id" IS 'The organization associated with this coaching relationship';
91+
92+
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coach_id" IS 'The coach associated with this coaching relationship';
93+
94+
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coachee_id" IS 'The coachee associated with this coaching relationship';
95+
96+
COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."updated_at" IS 'The last date and time fields were changed';
97+
98+
COMMENT ON COLUMN "refactor_platform"."users"."display_name" IS 'If a user wants to go by something other than first & last names';
99+
100+
COMMENT ON COLUMN "refactor_platform"."users"."updated_at" IS 'The last date and time fields were changed';
101+
102+
COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."coaching_relationship_id" IS 'The coaching relationship (i.e. what coach & coachee under what organization) associated with this coaching session';
103+
104+
COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."date" IS 'The date and time of a session';
105+
106+
COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."timezone" IS 'The baseline timezone used for the `date` field';
107+
108+
COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."updated_at" IS 'The last date and time fields were changed';
109+
110+
COMMENT ON COLUMN "refactor_platform"."overarching_goals"."coaching_session_id" IS 'The coaching session that an overarching goal is associated with';
111+
112+
COMMENT ON COLUMN "refactor_platform"."overarching_goals"."title" IS 'A short description of an overarching goal';
113+
114+
COMMENT ON COLUMN "refactor_platform"."overarching_goals"."details" IS 'A long description of an overarching goal';
115+
116+
COMMENT ON COLUMN "refactor_platform"."overarching_goals"."completed_at" IS 'The date and time an overarching goal was completed';
117+
118+
COMMENT ON COLUMN "refactor_platform"."overarching_goals"."updated_at" IS 'The last date and time fields were changed';
119+
120+
COMMENT ON COLUMN "refactor_platform"."notes"."body" IS 'Main text of the note supporting Markdown';
121+
122+
COMMENT ON COLUMN "refactor_platform"."notes"."user_id" IS 'User that created (owns) the note';
123+
124+
COMMENT ON COLUMN "refactor_platform"."notes"."updated_at" IS 'The last date and time an overarching note''s fields were changed';
125+
126+
COMMENT ON COLUMN "refactor_platform"."agreements"."details" IS 'Either a short or long description of an agreement reached between coach and coachee in a coaching session';
127+
128+
COMMENT ON COLUMN "refactor_platform"."agreements"."user_id" IS 'User that created (owns) the agreement';
129+
130+
COMMENT ON COLUMN "refactor_platform"."agreements"."updated_at" IS 'The last date and time an overarching agreement''s fields were changed';
131+
132+
ALTER TABLE "refactor_platform"."coaching_relationships" ADD FOREIGN KEY ("organization_id") REFERENCES "refactor_platform"."organizations" ("id");
133+
134+
ALTER TABLE "refactor_platform"."coaching_relationships" ADD FOREIGN KEY ("coachee_id") REFERENCES "refactor_platform"."users" ("id");
135+
136+
ALTER TABLE "refactor_platform"."coaching_relationships" ADD FOREIGN KEY ("coach_id") REFERENCES "refactor_platform"."users" ("id");
137+
138+
ALTER TABLE "refactor_platform"."coaching_sessions" ADD FOREIGN KEY ("coaching_relationship_id") REFERENCES "refactor_platform"."coaching_relationships" ("id");
139+
140+
ALTER TABLE "refactor_platform"."overarching_goals" ADD FOREIGN KEY ("coaching_session_id") REFERENCES "refactor_platform"."coaching_sessions" ("id");
141+
142+
ALTER TABLE "refactor_platform"."notes" ADD FOREIGN KEY ("coaching_session_id") REFERENCES "refactor_platform"."coaching_sessions" ("id");
143+
144+
ALTER TABLE "refactor_platform"."notes" ADD FOREIGN KEY ("user_id") REFERENCES "refactor_platform"."users" ("id");
145+
146+
ALTER TABLE "refactor_platform"."agreements" ADD FOREIGN KEY ("coaching_session_id") REFERENCES "refactor_platform"."coaching_sessions" ("id");
147+
148+
ALTER TABLE "refactor_platform"."agreements" ADD FOREIGN KEY ("user_id") REFERENCES "refactor_platform"."users" ("id");
149+
150+
ALTER TABLE "refactor_platform"."actions" ADD FOREIGN KEY ("coaching_session_id") REFERENCES "refactor_platform"."coaching_sessions" ("id");

0 commit comments

Comments
 (0)