Skip to content
Merged
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
51 changes: 51 additions & 0 deletions docs/schema-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,60 @@ erDiagram
timestamp updated_at
}

children {
uuid id PK
uuid parent_id FK
gender gender
text first_name
text last_name
date dob
text allergies
text medical_conditions
text medications
timestamp created_at
timestamp updated_at
}

emergency_contacts {
uuid id PK
uuid child_id FK
text full_name
text email_address
text phone_number
text relationship
timestamp created_at
timestamp updated_at
}

extra_questions {
uuid id PK
uuid service_id FK
extra_question_type type
text prompt
jsonb options
timestamp created_at
timestamp updated_at
}

extra_question_answers {
uuid id PK
uuid extra_question_id FK
uuid child_id FK
text answer "text[]"
timestamp created_at
timestamp updated_at
}

profiles ||--o{ service_bookings : "books"
services ||--o{ service_bookings : "booked via"
profiles ||--o{ coaching_sessions : "coaches"
profiles ||--o{ coaching_sessions : "attends"
services ||--o{ coaching_sessions : "fulfilled by"
profiles ||--o{ children : "parent of"
children ||--o{ emergency_contacts : "has"
services ||--o{ extra_questions : "defines"
extra_questions ||--o{ extra_question_answers : "answered via"
children ||--o{ extra_question_answers : "submits"
```

## Enums
Expand All @@ -78,3 +127,5 @@ erDiagram
| `booking_status` | `pending`, `confirmed`, `cancelled` |
| `webinar_tier` | `free`, `premium` |
| `session_status` | `pending`, `confirmed`, `cancelled`, `completed` |
| `gender` | `male`, `female`, `prefer_not_to_say` |
| `extra_question_type` | `text`, `multiple_choices`, `checkboxes`, `user_agreement` |
67 changes: 67 additions & 0 deletions lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import {

export type ProgramSlot = { dayOfWeek: number; time: string };

export type ExtraQuestionOption = {
id: string;
title: string;
description?: string;
};

export const roleEnum = pgEnum("role", ["user", "admin", "coach"]);
export const serviceTypeEnum = pgEnum("service_type", [
"private_lessons",
Expand All @@ -35,6 +41,13 @@ export const serviceStatusEnum = pgEnum("service_status", [
"deleted",
"disabled",
]);
export const genderEnum = pgEnum("gender", ["male", "female", "prefer_not_to_say"]);
export const extraQuestionTypeEnum = pgEnum("extra_question_type", [
"text",
"multiple_choices",
"checkboxes",
"user_agreement",
]);

export const profiles = pgTable("profiles", {
id: uuid("id").primaryKey(),
Expand Down Expand Up @@ -136,3 +149,57 @@ export const purchases = pgTable("purchases", {
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});

export const children = pgTable("children", {
id: uuid("id").primaryKey().defaultRandom(),
parentId: uuid("parent_id")
.references(() => profiles.id, { onDelete: "cascade" })
.notNull(),
gender: genderEnum("gender").notNull(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
dob: date("dob", { mode: "string" }).notNull(),
allergies: text("allergies"),
medicalConditions: text("medical_conditions"),
medications: text("medications"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});

export const emergencyContacts = pgTable("emergency_contacts", {
id: uuid("id").primaryKey().defaultRandom(),
childId: uuid("child_id")
.references(() => children.id, { onDelete: "cascade" })
.notNull(),
Comment on lines +171 to +173
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

childId FK with no uniqueness means contacts are duplicated per sibling.
if a family has 3 kids the same grandparent gets 3 rows.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems fine? if it is unique then we can't have multiple emergency contacts per child unless its some composite, idk it seems kinda overkill. What are you suggesting exactly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked with Mattia. You're right Alex, we're keeping it like this.

fullName: text("full_name").notNull(),
emailAddress: text("email_address").notNull(),
phoneNumber: text("phone_number").notNull(),
relationship: text("relationship").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});

export const extraQuestions = pgTable("extra_questions", {
id: uuid("id").primaryKey().defaultRandom(),
serviceId: uuid("service_id")
.references(() => services.id, { onDelete: "cascade" })
.notNull(),
type: extraQuestionTypeEnum("type").notNull(),
prompt: text("prompt").notNull(),
options: jsonb("options").$type<ExtraQuestionOption[]>(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});

export const extraQuestionAnswers = pgTable("extra_question_answers", {
id: uuid("id").primaryKey().defaultRandom(),
extraQuestionId: uuid("extra_question_id")
.references(() => extraQuestions.id, { onDelete: "cascade" })
.notNull(),
childId: uuid("child_id")
.references(() => children.id, { onDelete: "cascade" })
.notNull(),
answer: text("answer").array().notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
Comment thread
martin0024 marked this conversation as resolved.
Loading