Skip to content

Commit

Permalink
add external_id to tables
Browse files Browse the repository at this point in the history
Also reverts primary keys to integer values
  • Loading branch information
calebbourg committed Feb 18, 2024
1 parent afdfed5 commit 4083400
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 37 deletions.
44 changes: 26 additions & 18 deletions docs/db/refactor_platform_rs.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Docs: https://dbml.dbdiagram.io/docs

Table refactor_platform.organizations {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
name varchar [note: 'The name of the organization that the coach <--> coachee belong to']
logo varchar [note: 'A URI pointing to the organization\'s logo icon file']
created_at timestamptz [default: `now()`]
Expand All @@ -12,16 +13,18 @@ Table refactor_platform.organizations {
// Coaching relationship type belonging to the refactor_platform schema
// from the perspective of the coach
Table refactor_platform.coaching_relationships {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
organization_id uuid [not null, note: 'The organization associated with this coaching relationship']
coach_id uuid [not null, note: 'The coach associated with this coaching relationship']
coachee_id uuid [not null, note: 'The coachee associated with this coaching relationship']
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
organization_id integer [not null, note: 'The organization associated with this coaching relationship']
coach_id integer [not null, note: 'The coach associated with this coaching relationship']
coachee_id integer [not null, note: 'The coachee associated with this coaching relationship']
created_at timestamptz [default: `now()`]
updated_at timestamptz [default: `now()`, note: 'The last date and time fields were changed']
}

Table refactor_platform.users {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
email varchar [unique, not null]
first_name varchar
last_name varchar
Expand All @@ -34,17 +37,19 @@ Table refactor_platform.users {
}

Table refactor_platform.coaching_sessions {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
coaching_relationship_id uuid [not null, note: 'The coaching relationship (i.e. what coach & coachee under what organization) associated with this coaching session']
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
coaching_relationship_id integer [not null, note: 'The coaching relationship (i.e. what coach & coachee under what organization) associated with this coaching session']
date timestamp [note: 'The date and time of a session']
timezone varchar [note: 'The baseline timezone used for the `date` field']
created_at timestamptz [default: `now()`]
updated_at timestamptz [default: `now()`, note: 'The last date and time fields were changed']
}

Table refactor_platform.overarching_goals {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
coaching_session_id uuid [note: 'The coaching session that an overarching goal is associated with']
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
coaching_session_id integer [note: 'The coaching session that an overarching goal is associated with']
title varchar [note: 'A short description of an overarching goal']
details varchar [note: 'A long description of an overarching goal']
completed_at timestamptz [note: 'The date and time an overarching goal was completed']
Expand All @@ -53,29 +58,32 @@ Table refactor_platform.overarching_goals {
}

Table refactor_platform.notes {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
coaching_session_id uuid [not null]
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
coaching_session_id integer [not null]
body varchar [note: 'Main text of the note supporting Markdown']
user_id uuid [not null, note: 'User that created (owns) the note']
user_id integer [not null, note: 'User that created (owns) the note']
created_at timestamptz [default: `now()`]
updated_at timestamptz [default: `now()`, note: 'The last date and time an overarching note\'s fields were changed']
}

Table refactor_platform.agreements {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
coaching_session_id uuid [not null]
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
coaching_session_id integer [not null]
details varchar [note: 'Either a short or long description of an agreement reached between coach and coachee in a coaching session']
user_id uuid [not null, note: 'User that created (owns) the agreement']
user_id integer [not null, note: 'User that created (owns) the agreement']
created_at timestamptz [default: `now()`]
updated_at timestamptz [default: `now()`, note: 'The last date and time an overarching agreement\'s fields were changed']
}

Table refactor_platform.actions {
id uuid [primary key, unique, not null, default: `gen_random_uuid()`]
id integer [primary key, unique, not null, increment]
external_id uuid [unique, not null, default: `gen_random_uuid()`, note: 'The publicly visible identifier for a record']
// The first session where this action was created
// It will carry forward to every future session until
// its due_by is passed or it was completed by the coachee
coaching_session_id uuid [not null]
coaching_session_id integer [not null]
due_by timestamptz
completed boolean // May be unnecessary if there's a valid completed_at timestamp
completed_at timestamptz
Expand Down
62 changes: 43 additions & 19 deletions migration/src/refactor_platform_rs.sql
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
-- SQL dump generated using DBML (dbml-lang.org)
-- Database: PostgreSQL
-- Generated at: 2024-02-18T01:30:26.059Z
-- Generated at: 2024-02-18T13:46:48.698Z


CREATE TABLE "refactor_platform"."organizations" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"name" varchar,
"logo" varchar,
"created_at" timestamptz DEFAULT (now()),
"updated_at" timestamptz DEFAULT (now())
);

CREATE TABLE "refactor_platform"."coaching_relationships" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"organization_id" uuid NOT NULL,
"coach_id" uuid NOT NULL,
"coachee_id" uuid NOT NULL,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"organization_id" integer NOT NULL,
"coach_id" integer NOT NULL,
"coachee_id" integer NOT NULL,
"created_at" timestamptz DEFAULT (now()),
"updated_at" timestamptz DEFAULT (now())
);

CREATE TABLE "refactor_platform"."users" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"email" varchar UNIQUE NOT NULL,
"first_name" varchar,
"last_name" varchar,
Expand All @@ -34,17 +37,19 @@ CREATE TABLE "refactor_platform"."users" (
);

CREATE TABLE "refactor_platform"."coaching_sessions" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"coaching_relationship_id" uuid NOT NULL,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"coaching_relationship_id" integer NOT NULL,
"date" timestamp,
"timezone" varchar,
"created_at" timestamptz DEFAULT (now()),
"updated_at" timestamptz DEFAULT (now())
);

CREATE TABLE "refactor_platform"."overarching_goals" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" uuid,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" integer,
"title" varchar,
"details" varchar,
"completed_at" timestamptz,
Expand All @@ -53,39 +58,46 @@ CREATE TABLE "refactor_platform"."overarching_goals" (
);

CREATE TABLE "refactor_platform"."notes" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" uuid NOT NULL,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" integer NOT NULL,
"body" varchar,
"user_id" uuid NOT NULL,
"user_id" integer NOT NULL,
"created_at" timestamptz DEFAULT (now()),
"updated_at" timestamptz DEFAULT (now())
);

CREATE TABLE "refactor_platform"."agreements" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" uuid NOT NULL,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" integer NOT NULL,
"details" varchar,
"user_id" uuid NOT NULL,
"user_id" integer NOT NULL,
"created_at" timestamptz DEFAULT (now()),
"updated_at" timestamptz DEFAULT (now())
);

CREATE TABLE "refactor_platform"."actions" (
"id" uuid UNIQUE PRIMARY KEY NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" uuid NOT NULL,
"id" INTEGER GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY NOT NULL,
"external_id" uuid UNIQUE NOT NULL DEFAULT (gen_random_uuid()),
"coaching_session_id" integer NOT NULL,
"due_by" timestamptz,
"completed" boolean,
"completed_at" timestamptz,
"created_at" timestamp DEFAULT (now()),
"updated_at" timestamp DEFAULT (now())
);

COMMENT ON COLUMN "refactor_platform"."organizations"."external_id" IS 'The publicly visible identifier for a record';

COMMENT ON COLUMN "refactor_platform"."organizations"."name" IS 'The name of the organization that the coach <--> coachee belong to';

COMMENT ON COLUMN "refactor_platform"."organizations"."logo" IS 'A URI pointing to the organization''s logo icon file';

COMMENT ON COLUMN "refactor_platform"."organizations"."updated_at" IS 'The last date and time fields were changed';

COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."external_id" IS 'The publicly visible identifier for a record';

COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."organization_id" IS 'The organization associated with this coaching relationship';

COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coach_id" IS 'The coach associated with this coaching relationship';
Expand All @@ -94,10 +106,14 @@ COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."coachee_id" IS '

COMMENT ON COLUMN "refactor_platform"."coaching_relationships"."updated_at" IS 'The last date and time fields were changed';

COMMENT ON COLUMN "refactor_platform"."users"."external_id" IS 'The publicly visible identifier for a record';

COMMENT ON COLUMN "refactor_platform"."users"."display_name" IS 'If a user wants to go by something other than first & last names';

COMMENT ON COLUMN "refactor_platform"."users"."updated_at" IS 'The last date and time fields were changed';

COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."external_id" IS 'The publicly visible identifier for a record';

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';

COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."date" IS 'The date and time of a session';
Expand All @@ -106,6 +122,8 @@ COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."timezone" IS 'The bas

COMMENT ON COLUMN "refactor_platform"."coaching_sessions"."updated_at" IS 'The last date and time fields were changed';

COMMENT ON COLUMN "refactor_platform"."overarching_goals"."external_id" IS 'The publicly visible identifier for a record';

COMMENT ON COLUMN "refactor_platform"."overarching_goals"."coaching_session_id" IS 'The coaching session that an overarching goal is associated with';

COMMENT ON COLUMN "refactor_platform"."overarching_goals"."title" IS 'A short description of an overarching goal';
Expand All @@ -116,18 +134,24 @@ COMMENT ON COLUMN "refactor_platform"."overarching_goals"."completed_at" IS 'The

COMMENT ON COLUMN "refactor_platform"."overarching_goals"."updated_at" IS 'The last date and time fields were changed';

COMMENT ON COLUMN "refactor_platform"."notes"."external_id" IS 'The publicly visible identifier for a record';

COMMENT ON COLUMN "refactor_platform"."notes"."body" IS 'Main text of the note supporting Markdown';

COMMENT ON COLUMN "refactor_platform"."notes"."user_id" IS 'User that created (owns) the note';

COMMENT ON COLUMN "refactor_platform"."notes"."updated_at" IS 'The last date and time an overarching note''s fields were changed';

COMMENT ON COLUMN "refactor_platform"."agreements"."external_id" IS 'The publicly visible identifier for a record';

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';

COMMENT ON COLUMN "refactor_platform"."agreements"."user_id" IS 'User that created (owns) the agreement';

COMMENT ON COLUMN "refactor_platform"."agreements"."updated_at" IS 'The last date and time an overarching agreement''s fields were changed';

COMMENT ON COLUMN "refactor_platform"."actions"."external_id" IS 'The publicly visible identifier for a record';

ALTER TABLE "refactor_platform"."coaching_relationships" ADD FOREIGN KEY ("organization_id") REFERENCES "refactor_platform"."organizations" ("id");

ALTER TABLE "refactor_platform"."coaching_relationships" ADD FOREIGN KEY ("coachee_id") REFERENCES "refactor_platform"."users" ("id");
Expand Down

0 comments on commit 4083400

Please sign in to comment.