-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* core: Added database schemas * fix: Fix github actions * chore: Added pnpm in github actions
- Loading branch information
Showing
9 changed files
with
134 additions
and
44 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 |
---|---|---|
@@ -1,21 +1,45 @@ | ||
name: Format | ||
on: | ||
pull_request: | ||
branches: [master] | ||
branches: ["*"] | ||
|
||
env: | ||
DB_URL: fake | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- uses: actions/setup-node@v3 | ||
|
||
- name: Setup Node 20 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: latest | ||
- run: npm ci | ||
- run: npm run format | ||
- name: Commit changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
node-version: 20 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v2.2.4 | ||
with: | ||
commit_message: Apply formatting changes | ||
branch: ${{ github.head_ref }} | ||
version: 8.6.1 | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache | ||
run: | | ||
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
- name: Setup pnpm cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install deps (with cache) | ||
run: pnpm install | ||
|
||
- name: Run Format Check | ||
run: pnpm format:check |
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,16 +1,45 @@ | ||
name: Lint | ||
on: | ||
pull_request: | ||
branches: [master] | ||
branches: ["*"] | ||
|
||
env: | ||
DB_URL: fake | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- uses: actions/setup-node@v3 | ||
|
||
- name: Setup Node 20 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: latest | ||
- run: npm ci | ||
- run: npm run lint | ||
node-version: 20 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v2.2.4 | ||
with: | ||
version: 8.6.1 | ||
|
||
- name: Get pnpm store directory | ||
id: pnpm-cache | ||
run: | | ||
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
- name: Setup pnpm cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} | ||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-store- | ||
- name: Install deps (with cache) | ||
run: pnpm install | ||
|
||
- name: Run lint | ||
run: pnpm lint |
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,11 +1,11 @@ | ||
import "dotenv/config"; | ||
import type { Config } from "drizzle-kit"; | ||
import { env } from "@src/env.mjs"; | ||
|
||
export default { | ||
schema: "./src/db/schemas/*", | ||
schema: "./src/db/schema.ts", | ||
out: "./src/db/migrations", | ||
driver: "pg", | ||
dbCredentials: { | ||
connectionString: process.env.DB_URL!, | ||
connectionString: env.DB_URL, | ||
}, | ||
} satisfies Config; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 +1,6 @@ | ||
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js"; | ||
// import { migrate } from "drizzle-orm/postgres-js/migrator"; | ||
import postgres from "postgres"; | ||
import { env } from "@src/env.mjs"; | ||
|
||
// const migrationClient = postgres(env.DB_URL, { max: 1 }); | ||
// void migrate(drizzle(migrationClient), { migrationsFolder: "./migrations" }); | ||
|
||
const queryClient = postgres(env.DB_URL); | ||
export const db: PostgresJsDatabase = drizzle(queryClient); |
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,58 @@ | ||
import { boolean, index, integer, pgEnum, pgTable, serial, varchar } from "drizzle-orm/pg-core"; | ||
|
||
// Users table | ||
export const users = pgTable("users", { | ||
id: serial("id").primaryKey().notNull(), | ||
email: varchar("email").notNull(), | ||
password: varchar("password").notNull(), | ||
admin: boolean("admin").default(false).notNull(), | ||
}); | ||
|
||
export const difficultyEnum = pgEnum("difficulty", ["easy", "medium", "hard"]); | ||
export const typeEnum = pgEnum("type", ["qcm", "program", "personality"]); | ||
|
||
// Questions table | ||
export const questions = pgTable("questions", { | ||
id: serial("id").primaryKey().notNull(), | ||
statement: varchar("statement").notNull(), | ||
difficulty: difficultyEnum("difficulty").notNull(), | ||
type: typeEnum("type").notNull(), | ||
}); | ||
|
||
// Game table | ||
export const games = pgTable( | ||
"games", | ||
{ | ||
id: serial("id").primaryKey().notNull(), | ||
userId: integer("user_id") | ||
.references(() => users.id) | ||
.notNull(), | ||
progress: integer("progress").default(0).notNull(), // -1 if done else X where X is the question number | ||
}, | ||
(table) => { | ||
return { | ||
userIdx: index("user_idx").on(table.userId), | ||
}; | ||
}, | ||
); | ||
|
||
// Answers table | ||
export const answers = pgTable( | ||
"answers", | ||
{ | ||
id: serial("id").primaryKey().notNull(), | ||
answer: varchar("answer").notNull(), | ||
grade: integer("grade"), // Between 0 and 100 & null if personality question | ||
questionId: integer("question_id") | ||
.references(() => questions.id) | ||
.notNull(), | ||
gameId: integer("game_id") | ||
.references(() => games.id) | ||
.notNull(), | ||
}, | ||
(table) => { | ||
return { | ||
gameId: index("game_idx").on(table.gameId), | ||
}; | ||
}, | ||
); |
This file was deleted.
Oops, something went wrong.
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