-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
12 changed files
with
320 additions
and
4 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 |
---|---|---|
|
@@ -36,3 +36,5 @@ yarn-error.log* | |
# Misc | ||
.DS_Store | ||
*.pem | ||
|
||
migrations |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
MONGODB_DATABASE_URL="mongodb+srv://user:pass@url/database?retryWrites=true&w=majority&appName=main" | ||
POSTGRESQL_DATABASE_URL="postgresql://postgres:postgresql@192.168.122.2:5432/imp?schema=public" |
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,28 @@ | ||
{ | ||
"name": "@repo/database", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"build": "tsup src/index.ts --minify --dts --out-dir dist", | ||
"dev": "tsup src/index.ts --watch --dts --out-dir dist", | ||
"prisma:generate": "prisma generate --schema ./prisma/schema_mongo.prisma & prisma generate --schema ./prisma/schema_pg.prisma", | ||
"prisma:migrate:pg": "prisma migrate dev --schema ./prisma/schema_pg.prisma" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"exports": { | ||
".": { | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@prisma/client": "^5.20.0", | ||
"@repo/typescript-config": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20", | ||
"prisma": "^5.20.0", | ||
"tsup": "^8.3.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,76 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
output = "../node_modules/@prisma/mongo_client" | ||
} | ||
|
||
datasource db { | ||
provider = "mongodb" | ||
url = env("MONGODB_DATABASE_URL") | ||
} | ||
|
||
model idea { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
title String | ||
description String | ||
author_username String | ||
author_user_Id String | ||
media Json? | ||
upvotes_count Int @default(0) | ||
downvotes_count Int @default(0) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
idea_comments idea_comments[] | ||
upvotes upvotes[] | ||
downvotes downvotes[] | ||
} | ||
|
||
model idea_comments { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
author_username String | ||
author_user_Id String | ||
content String | ||
upvotes_count Int @default(0) | ||
downvotes_count Int @default(0) | ||
media Json? | ||
idea idea @relation(fields: [ideaId], references: [id]) | ||
ideaId String @db.ObjectId | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
upvotes upvotes[] | ||
downvotes downvotes[] | ||
} | ||
|
||
enum POST_TYPE { | ||
COMMON_POST | ||
COMMENT_POST | ||
} | ||
|
||
model upvotes { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
author_username String | ||
author_user_Id String | ||
POST_TYPE POST_TYPE | ||
createdAt DateTime @default(now()) | ||
idea idea? @relation(fields: [ideaId], references: [id]) | ||
ideaId String? @db.ObjectId | ||
comment idea_comments? @relation(fields: [commentId], references: [id]) | ||
commentId String? @db.ObjectId | ||
} | ||
|
||
model downvotes { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
author_username String | ||
author_user_Id String | ||
POST_TYPE POST_TYPE | ||
createdAt DateTime @default(now()) | ||
idea idea? @relation(fields: [ideaId], references: [id]) | ||
ideaId String? @db.ObjectId | ||
comment idea_comments? @relation(fields: [commentId], references: [id]) | ||
commentId String? @db.ObjectId | ||
} |
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,85 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
output = "../node_modules/@prisma/pg_client" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("POSTGRESQL_DATABASE_URL") | ||
} | ||
|
||
model User { | ||
id String @id @default(cuid()) | ||
name String? | ||
email String @unique | ||
emailVerified DateTime? | ||
image String? | ||
accounts Account[] | ||
sessions Session[] | ||
// Optional for WebAuthn support | ||
Authenticator Authenticator[] | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} | ||
|
||
model Account { | ||
userId String | ||
type String | ||
provider String | ||
providerAccountId String | ||
refresh_token String? | ||
access_token String? | ||
expires_at Int? | ||
token_type String? | ||
scope String? | ||
id_token String? | ||
session_state String? | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
@@id([provider, providerAccountId]) | ||
} | ||
|
||
model Session { | ||
sessionToken String @unique | ||
userId String | ||
expires DateTime | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} | ||
|
||
model VerificationToken { | ||
identifier String | ||
token String | ||
expires DateTime | ||
@@id([identifier, token]) | ||
} | ||
|
||
// Optional for WebAuthn support | ||
model Authenticator { | ||
credentialID String @unique | ||
userId String | ||
providerAccountId String | ||
credentialPublicKey String | ||
counter Int | ||
credentialDeviceType String | ||
credentialBackedUp Boolean | ||
transports String? | ||
user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
@@id([userId, credentialID]) | ||
} |
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,2 @@ | ||
export { PG_PRISMA_CLIENT } from "./lib/pg_db"; | ||
export { MONGO_PRISMA_CLIENT } from "./lib/mongo_db"; |
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,15 @@ | ||
import { PrismaClient } from "@prisma/mongo_client"; | ||
|
||
const prismaClientSingleton = () => { | ||
return new PrismaClient(); | ||
}; | ||
|
||
declare const globalThis: { | ||
mongo_prismaGlobal: ReturnType<typeof prismaClientSingleton>; | ||
} & typeof global; | ||
|
||
export const MONGO_PRISMA_CLIENT = | ||
globalThis.mongo_prismaGlobal ?? prismaClientSingleton(); | ||
|
||
if (process.env.NODE_ENV !== "production") | ||
globalThis.mongo_prismaGlobal = MONGO_PRISMA_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,15 @@ | ||
import { PrismaClient } from "@prisma/pg_client"; | ||
|
||
const prismaClientSingleton = () => { | ||
return new PrismaClient(); | ||
}; | ||
|
||
declare const globalThis: { | ||
PG_prismaGlobal: ReturnType<typeof prismaClientSingleton>; | ||
} & typeof global; | ||
|
||
export const PG_PRISMA_CLIENT = | ||
globalThis.PG_prismaGlobal ?? prismaClientSingleton(); | ||
|
||
if (process.env.NODE_ENV !== "production") | ||
globalThis.PG_prismaGlobal = PG_PRISMA_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,13 @@ | ||
{ | ||
"extends": "@repo/typescript-config/base.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": [ | ||
"./*" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.