Skip to content

Commit

Permalink
데이터베이스 스키마 및 ORM 연결 (#23)
Browse files Browse the repository at this point in the history
* feat: DB scheme 작성 및 ORM 생성

* feat: db table 생성 스크립트 작성

* fix: ts-node 실행되도록 수정

* fix: 불필요 nodemon 삭제 및 스크립트 종료 수정
  • Loading branch information
howons authored May 28, 2024
1 parent 6f73f4d commit 7a9d3b6
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 290 deletions.
58 changes: 58 additions & 0 deletions app/lib/database/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This adapter exports a wrapper of the original `Kysely` class called `KyselyAuth`,
// that can be used to provide additional type-safety.
// While using it isn't required, it is recommended as it will verify
// that the database interface has all the fields that Auth.js expects.
import { Platform, PostCommentStatus } from "@lib/types/property";
import { createKysely } from "@vercel/postgres-kysely";
import type { GeneratedAlways } from "kysely";

interface Database {
User: {
id: GeneratedAlways<string>;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
};
Account: {
id: GeneratedAlways<string>;
userId: string;
type: string;
provider: string;
providerAccountId: string;
refresh_token: string | null;
access_token: string | null;
expires_at: number | null;
token_type: string | null;
scope: string | null;
id_token: string | null;
session_state: string | null;
};
Post: {
id: GeneratedAlways<string>;
userId: string | null;
platform: Platform;
targetNickname: string;
tags: string[];
imageUrls: string[];
content: string;
status: PostCommentStatus;
createdAt: Date;
updatedAt: Date;
anonymousUserNickname: string | null;
etcPlatformName: string | null;
};
Comment: {
id: GeneratedAlways<string>;
userId: string;
postId: string;
imageUrls: string[];
content: string;
status: PostCommentStatus;
createdAt: Date;
updatedAt: Date;
};
}

export const db = createKysely<Database>();
export { sql } from "kysely";
2 changes: 2 additions & 0 deletions app/lib/types/property.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type Platform = "daangn" | "bunjang" | "joongna" | "etc";

export type CategoryDirection = "up" | "down" | "left";

export type PostCommentStatus = "normal" | "debate" | "deleted";
Loading

0 comments on commit 7a9d3b6

Please sign in to comment.