-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from TigerAppsOrg/staging
Begin drizzle setup
- Loading branch information
Showing
27 changed files
with
210 additions
and
1,724 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"bocovo.dbml-erd-visualizer", | ||
"1yib.svelte-bundle", | ||
"oven.bun-vscode", | ||
"bradlc.vscode-tailwindcss", | ||
] | ||
} |
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 @@ | ||
PUBLIC_SUPABASE_URL= | ||
PUBLIC_SUPABASE_ANON_KEY= | ||
REDIS_PASSWORD= | ||
API_ACCESS_TOKEN= | ||
SERVICE_ROLE_KEY= | ||
DATABASE_URL= |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
pnpm-lock.yaml | ||
package-lock.json | ||
package.json | ||
yarn.lock | ||
*.config.* | ||
*.json | ||
|
File renamed without changes.
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,9 @@ | ||
# TigerJunction Database | ||
|
||
This is where the Drizzle database schema is defined and where the scripts that update the course data are located. This is separated from the main web app in order to maintain a clean separation of concerns. Additionally, as we are migrating off Supabase, this will keep the migration process as clean and simple as possible. | ||
|
||
## Getting Started | ||
|
||
Make sure to have [Bun](https://bun.sh) installed and the environment variables set according to the `.env.example` file. Run `bun install` to install the dependencies. Check the `package.json` file for the available scripts. | ||
|
||
There are 2 main directories. `db` contains the Drizzle database schema. `scripts` contains a collection of scripts used to keep course data up to date. |
Binary file not shown.
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,10 @@ | ||
services: | ||
db: | ||
image: postgres | ||
restart: always | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: mysecretpassword | ||
POSTGRES_DB: local |
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,13 @@ | ||
import { defineConfig } from "drizzle-kit"; | ||
|
||
if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is not set"); | ||
|
||
export default defineConfig({ | ||
dialect: "postgresql", | ||
schema: "./src/db/schema.ts", | ||
dbCredentials: { | ||
url: process.env.DATABASE_URL | ||
}, | ||
verbose: true, | ||
strict: true | ||
}); |
File renamed without changes.
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,36 @@ | ||
{ | ||
"name": "tiger-junction-server", | ||
"module": "index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"lint": "prettier --check . && eslint src/", | ||
"format": "prettier --write .", | ||
"update-supabase": "bun src/scripts/supabase/index.ts", | ||
"ratings-supabase": "bun src/scripts/supabase/ratings.ts", | ||
"db:start": "docker compose up", | ||
"db:schema": "bun src/db/generate-dbml.ts", | ||
"db:push": "drizzle-kit push", | ||
"db:migrate": "drizzle-kit migrate", | ||
"db:studio": "drizzle-kit studio" | ||
}, | ||
"devDependencies": { | ||
"@types/jsdom": "^21.1.7", | ||
"bun-types": "latest", | ||
"drizzle-kit": "^0.27.0", | ||
"eslint": "^9.9.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"prettier": "^3.3.3", | ||
"typescript-eslint": "^8.2.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@supabase/supabase-js": "^2.45.1", | ||
"drizzle-dbml-generator": "^0.9.0", | ||
"drizzle-orm": "^0.36.0", | ||
"jsdom": "^25.0.1", | ||
"postgres": "^3.4.5", | ||
"redis": "^4.7.0" | ||
} | ||
} |
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 @@ | ||
/** | ||
* @file db/generate-dbml.ts | ||
* @description Used to create a schema.dbml file from the Drizzle ORM schema. | ||
* This is useful for visualization. The schema.dbml file can be opened with | ||
* the VSCode extension "bocovo.dbml-erd-visualizer" | ||
* @link https://github.com/drizzle-team/drizzle-orm/discussions/1480 | ||
*/ | ||
|
||
import * as schema from "./schema"; | ||
import { pgGenerate } from "drizzle-dbml-generator"; | ||
|
||
const out = "./schema.dbml"; | ||
const relational = true; | ||
|
||
pgGenerate({ schema, out, relational }); | ||
console.log("Successfully created the schema.dbml file."); |
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,66 @@ | ||
/** | ||
* @file db/schema.ts | ||
* @description This file contains the Drizzle ORM schema for the database. | ||
* @author Joshua Lau | ||
*/ | ||
|
||
import { relations } from "drizzle-orm"; | ||
import { | ||
pgTable, | ||
text, | ||
smallint, | ||
integer, | ||
real, | ||
pgEnum, | ||
boolean, | ||
serial | ||
} from "drizzle-orm/pg-core"; | ||
|
||
//---------------------------------------------------------------------- | ||
// Enums | ||
//---------------------------------------------------------------------- | ||
|
||
export const statusEnum = pgEnum("status", ["open", "closed", "cancelled"]); | ||
|
||
//---------------------------------------------------------------------- | ||
// Tables | ||
//---------------------------------------------------------------------- | ||
|
||
export const listings = pgTable("listings", { | ||
id: text("id").notNull().primaryKey(), | ||
code: text("code").notNull(), | ||
title: text("title").notNull(), | ||
aka: text("aka").array(), | ||
recentTerm: smallint("recent_term"), | ||
terms: smallint("terms").array() | ||
}); | ||
|
||
export const listingsRelations = relations(listings, ({ many }) => ({ | ||
courses: many(courses) | ||
})); | ||
|
||
export const courses = pgTable("courses", { | ||
id: serial("id").primaryKey().notNull(), | ||
listingId: text("listing_id") | ||
.notNull() | ||
.references(() => listings.id, { | ||
onDelete: "cascade" | ||
}), | ||
term: smallint("term").notNull(), | ||
code: text("code").notNull(), | ||
title: text("title").notNull(), | ||
gradingBasis: text("grading_basis").notNull(), | ||
dists: text("dists").array(), | ||
rating: real("rating"), | ||
status: statusEnum("status").notNull().default("open"), | ||
numEvals: integer("num_evals"), | ||
instructors: text("instructors").array(), | ||
hasFinal: boolean("has_final") | ||
}); | ||
|
||
export const coursesRelations = relations(courses, ({ one }) => ({ | ||
listing: one(listings, { | ||
fields: [courses.listingId], | ||
references: [listings.id] | ||
}) | ||
})); |
13 changes: 11 additions & 2 deletions
13
apps/server/src/fetchers.ts → apps/database/src/scripts/reg-fetchers.ts
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
7 changes: 7 additions & 0 deletions
7
apps/server/src/types.ts → apps/database/src/scripts/reg-types.ts
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
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
4 changes: 2 additions & 2 deletions
4
apps/server/src/listings.ts → ...database/src/scripts/supabase/listings.ts
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
2 changes: 1 addition & 1 deletion
2
apps/server/src/ratings.ts → .../database/src/scripts/supabase/ratings.ts
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.