-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11bc822
commit 54a0644
Showing
11 changed files
with
805 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { drizzle } from 'drizzle-orm/postgres-js'; | ||
import postgres from 'postgres'; | ||
|
||
export const client = postgres('postgres://postgres:postgres@localhost:5432/antalmanac'); | ||
|
||
export const db = drizzle(client); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { primaryKey, pgTable, text } from 'drizzle-orm/pg-core'; | ||
|
||
import { user } from './user'; | ||
|
||
export const account = pgTable( | ||
'account', | ||
{ | ||
userId: text('user_id') | ||
.references(() => user.id, { onDelete: 'cascade' }) | ||
.notNull(), | ||
|
||
providerId: text('provider').notNull(), | ||
|
||
providerAccountId: text('provider_account_id').notNull(), | ||
|
||
providerAccountCredential: text('provider_account_credential'), | ||
|
||
providerType: text('provider_type'), | ||
}, | ||
(table) => { | ||
return { | ||
primaryKey: primaryKey({ | ||
columns: [table.userId, table.providerId, table.providerAccountId], | ||
}), | ||
}; | ||
} | ||
); | ||
|
||
export type Account = typeof account.$inferSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './account' | ||
export * from './session' | ||
export * from './user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createId } from '@paralleldrive/cuid2'; | ||
import { integer, pgTable, text } from 'drizzle-orm/pg-core'; | ||
|
||
import { user } from './user'; | ||
|
||
export const session = pgTable('session', { | ||
id: text('id').primaryKey().$defaultFn(createId), | ||
|
||
userId: text('user_id') | ||
.references(() => user.id, { onDelete: 'cascade' }) | ||
.notNull(), | ||
|
||
expires: integer('expires').notNull(), | ||
|
||
status: text('status').default('ACTIVE'), | ||
|
||
refreshToken: text('refresh_token').$defaultFn(createId), | ||
}); | ||
|
||
export type Session = typeof session.$inferSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createId } from '@paralleldrive/cuid2'; | ||
import { integer, pgTable, text } from 'drizzle-orm/pg-core'; | ||
|
||
/** | ||
* User entity is analogous to a person. | ||
*/ | ||
export const user = pgTable('user', { | ||
/** | ||
* Unique ID (CUID) to represent the entity. | ||
*/ | ||
id: text('id').primaryKey().$defaultFn(createId), | ||
|
||
/** | ||
* Phone number for subscribing to notifications. | ||
*/ | ||
phone: text('phone'), | ||
|
||
/** | ||
* Display name. | ||
*/ | ||
name: text('name'), | ||
|
||
/** | ||
* Profile picture.. | ||
*/ | ||
avatar: text('avatar'), | ||
|
||
/** | ||
* Whether the email has been verified. | ||
*/ | ||
verified: integer('verified'), | ||
}); | ||
|
||
export type User = typeof user.$inferSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { integer, pgTable, primaryKey, text } from 'drizzle-orm/pg-core'; | ||
import { schedule } from './schedule'; | ||
|
||
/** | ||
* Courses have a N:1 relation with schedules. | ||
* | ||
* Schedules can't have duplicate courses. i.e. courses with the same section code and term. | ||
* | ||
* Once a schedule and its courses have been loaded, additional context can be retrieved | ||
* for the courses by querying PPA with the section code and term. | ||
*/ | ||
export const course = pgTable( | ||
'course', | ||
{ | ||
scheduleId: text('scheduleId').references(() => schedule.id, { onDelete: 'cascade' }), | ||
|
||
/** | ||
* The course's section code. | ||
*/ | ||
sectionCode: integer('sectionCode'), | ||
|
||
/** | ||
* @example Winter 2024. | ||
*/ | ||
term: text('term'), | ||
|
||
/** | ||
* Color that the course has when displayed on calendar. | ||
*/ | ||
color: text('color'), | ||
}, | ||
(table) => { | ||
return { | ||
primaryKey: primaryKey({ | ||
columns: [table.scheduleId, table.sectionCode, table.term], | ||
}), | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { integer, pgEnum, pgTable, serial, uniqueIndex, varchar } from 'drizzle-orm/pg-core'; | ||
|
||
export const user = pgTable( | ||
'user', | ||
{ | ||
id: serial('id').primaryKey(), | ||
name: varchar('name', { length: 256 }), | ||
}, | ||
); | ||
|
||
export const cities = pgTable('cities', { | ||
id: serial('id').primaryKey(), | ||
name: varchar('name', { length: 256 }), | ||
countryId: integer('country_id').references(() => countries.id), | ||
popularity: popularityEnum('popularity'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createId } from '@paralleldrive/cuid2'; | ||
import { boolean, pgTable, text } from 'drizzle-orm/pg-core'; | ||
import { user } from './auth/user'; | ||
|
||
export const schedule = pgTable('schedule', { | ||
id: text('id').primaryKey().$defaultFn(createId), | ||
|
||
/** | ||
* A schedule is owned by a user. | ||
*/ | ||
userId: text('user_id') | ||
.references(() => user.id, { onDelete: 'cascade' }) | ||
.notNull(), | ||
|
||
/** | ||
* Whether this schedule was the most recently focused. | ||
*/ | ||
active: boolean('active'), | ||
|
||
/** | ||
* Name of the schedule. | ||
*/ | ||
name: text('name'), | ||
|
||
/** | ||
* Any custom notes. | ||
*/ | ||
notes: text('notes'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { integer, pgTable, primaryKey, text } from 'drizzle-orm/pg-core'; | ||
import { user } from './auth/user'; | ||
|
||
export const subscription = pgTable( | ||
'subscription', | ||
{ | ||
/** | ||
* The user that is subscribing to course updates for the specified section. | ||
*/ | ||
userId: text('userId').references(() => user.id, { onDelete: 'cascade' }), | ||
|
||
/** | ||
* Section code. | ||
*/ | ||
sectionCode: integer('sectionCode'), | ||
|
||
/** | ||
* @example "OPEN" could indicate that the user wants to be notified when this | ||
* section changes from "WAITLISTED" to "OPEN". | ||
*/ | ||
status: text('status'), | ||
}, | ||
(table) => { | ||
return { | ||
primaryKey: primaryKey({ | ||
columns: [table.userId, table.sectionCode], | ||
}), | ||
}; | ||
} | ||
); |
Oops, something went wrong.