Skip to content

Commit

Permalink
chore: 🔧 use pgTable
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed May 7, 2024
1 parent bc77537 commit 045a64a
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/lib/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { relations } from "drizzle-orm";
import {
text,
uuid,
pgSchema,
timestamp,
index,
smallint,
Expand All @@ -11,21 +10,20 @@ import {
pgEnum,
boolean,
json,
pgTable,
} from "drizzle-orm/pg-core";

export const zotMeet = pgSchema("zotmeet");

export const attendanceEnum = pgEnum("attendance", ["accepted", "maybe", "declined"]);
export const memberEnum = pgEnum("member_type", ["guest", "user"]);

// Members encompasses anyone who uses ZotMeet, regardless of guest or user status.
export const members = zotMeet.table("members", {
export const members = pgTable("members", {
id: text("id").primaryKey(),
type: memberEnum("type").notNull().default("guest"),
});

// Users encompasses Members who have created an account.
export const users = zotMeet.table("users", {
export const users = pgTable("users", {
id: text("id")
.primaryKey()
.references(() => members.id, { onDelete: "cascade" }),
Expand All @@ -38,7 +36,7 @@ export const users = zotMeet.table("users", {

// Guests are Members who do not have an account and are bound to one specific meeting.

export const guests = zotMeet.table(
export const guests = pgTable(
"guests",
{
id: text("id").unique().notNull(),
Expand All @@ -50,7 +48,7 @@ export const guests = zotMeet.table(
}),
);

export const meetings = zotMeet.table("meetings", {
export const meetings = pgTable("meetings", {
id: uuid("id").defaultRandom().primaryKey(),
title: text("title").notNull(),
description: text("description"),
Expand All @@ -62,7 +60,7 @@ export const meetings = zotMeet.table("meetings", {
host_id: text("host_id").references(() => members.id),
});

export const meetingDates = zotMeet.table(
export const meetingDates = pgTable(
"meeting_dates",
{
id: uuid("id").unique().defaultRandom(),
Expand All @@ -74,15 +72,15 @@ export const meetingDates = zotMeet.table(
}),
);

export const groups = zotMeet.table("groups", {
export const groups = pgTable("groups", {
id: uuid("id").defaultRandom().primaryKey(),
name: text("name").notNull(),
description: text("description"),
created_at: timestamp("created_at"),
created_by: text("user_id").references(() => users.id),
});

export const availabilities = zotMeet.table(
export const availabilities = pgTable(
"availabilities",
{
day: date("day").notNull(),
Expand All @@ -101,7 +99,7 @@ export const availabilities = zotMeet.table(
);

// meeting_day
export const oauthAccountsTable = zotMeet.table(
export const oauthAccountsTable = pgTable(
"oauth_accounts",
{
userId: text("user_id")
Expand All @@ -117,7 +115,7 @@ export const oauthAccountsTable = zotMeet.table(
}),
);

export const sessions = zotMeet.table(
export const sessions = pgTable(
"sessions",
{
id: text("id").primaryKey(),
Expand All @@ -136,7 +134,7 @@ export const sessions = zotMeet.table(
},
);

export const usersInGroup = zotMeet.table(
export const usersInGroup = pgTable(
"users_in_group",
{
userId: text("user_id")
Expand All @@ -151,7 +149,7 @@ export const usersInGroup = zotMeet.table(
}),
);

export const membersInMeeting = zotMeet.table(
export const membersInMeeting = pgTable(
"members_in_meeting",
{
memberId: text("member_id")
Expand Down

0 comments on commit 045a64a

Please sign in to comment.