Setup app

This commit is contained in:
KMKoushik
2024-03-19 09:34:23 +11:00
parent 7ee4e89e5f
commit 9032efa9b2
71 changed files with 3199 additions and 5419 deletions

3
packages/db/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env

1
packages/db/client.ts Normal file
View File

@@ -0,0 +1 @@
export * from "@prisma/client";

21
packages/db/index.ts Normal file
View File

@@ -0,0 +1,21 @@
import { PrismaClient } from "@prisma/client";
declare global {
// We need `var` to declare a global variable in TypeScript
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
if (!globalThis.prisma) {
globalThis.prisma = new PrismaClient({
datasourceUrl: process.env.DATABASE_URL,
});
}
export const prisma =
globalThis.prisma ||
new PrismaClient({
datasourceUrl: process.env.DATABASE_URL,
});
export const getPrismaClient = () => prisma;

18
packages/db/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "@unsend/db",
"version": "0.0.0",
"main": "./index.ts",
"types": "./index.ts",
"dependencies": {
"@prisma/client": "^5.11.0",
"prisma": "^5.11.0"
},
"scripts": {
"post-install": "prisma generate",
"generate": "prisma generate",
"push": "prisma db push --skip-generate",
"migrate-dev": "prisma migrate dev",
"migrate-deploy": "prisma migrate deploy",
"studio": "prisma studio"
}
}

View File

@@ -0,0 +1,73 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
// NOTE: When using mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy User @relation(fields: [createdById], references: [id])
createdById String
@@index([name])
}
// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
posts Post[]
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}