feat: use prisma and postgresql

This commit is contained in:
DIYgod 2023-03-29 01:35:23 +01:00
parent c0eace8efe
commit 0f2abe9e44
No known key found for this signature in database
7 changed files with 2749 additions and 2375 deletions

View File

@ -13,4 +13,38 @@ NEXT_PUBLIC_CSB_SCAN="https://scan.crossbell.io"
NEXT_PUBLIC_IPFS_GATEWAY="https://ipfs.4everland.xyz/ipfs/"
NEXT_PUBLIC_MIRA_LINK="https://mira.crossbell.io"
REDIS_URL=
# NFT
MORALIS_WEB3_API_KEY=
ALCHEMY_ETHEREUM_API_KEY=
ALCHEMY_POLYGON_API_KEY=
NFTSCAN_API_KEY=
OPENSEA_API_KEY=
POAP_API_KEY=
# OPENAI
OPENAI_API_KEY=
# POSTGRES
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=indexer
# Nest run locally
DB_HOST=localhost
# DB_HOST=postgres
DB_PORT=5432
DB_SCHEMA=public
# Prisma database connection
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}?schema=${DB_SCHEMA}&sslmode=prefer&connection_limit=400&pool_timeout=30
# Redis database connection
REDIS_URL=redis://localhost:6379

27
docker-compose.db.yml Normal file
View File

@ -0,0 +1,27 @@
version: "3.7"
services:
postgres:
image: postgres:latest
container_name: postgres
restart: always
ports:
- 5432:5432
env_file:
- .env
volumes:
- postgres:/var/lib/postgresql/data
redis:
image: redis/redis-stack:latest
container_name: redis-stack
restart: always
ports:
- 6379:6379
- 8001:8001
volumes:
- redis:/var/lib/redis/data
volumes:
postgres:
name: xlog-db
redis:
name: xlog-redis

View File

@ -11,7 +11,10 @@
"test-e2e": "playwright test",
"start": "node server.js",
"uno-generate": "unocss \"src/**/*.{ts,tsx}\" -o src/generated/uno.css",
"prepare": "husky install"
"prepare": "husky install",
"prisma:generate": "prisma generate",
"prisma:studio": "prisma studio",
"docker:db": "docker-compose -f docker-compose.db.yml up -d"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
@ -36,6 +39,7 @@
"@iconify-json/mingcute": "^1.1.5",
"@mantine/core": "^6.0.4",
"@monaco-editor/react": "4.4.6",
"@prisma/client": "^4.12.0",
"@tanstack/react-query": "4.28.0",
"@tanstack/react-query-devtools": "4.28.0",
"@tanstack/react-query-persist-client": "4.28.0",
@ -142,6 +146,7 @@
"next-pwa": "^5.6.0",
"postcss-import": "15.1.0",
"prettier": "2.8.6",
"prisma": "^4.12.0",
"tailwindcss": "3.2.7",
"typescript": "5.0.2",
"unocss": "0.50.6",

File diff suppressed because it is too large Load Diff

19
prisma/schema.prisma Normal file
View File

@ -0,0 +1,19 @@
// 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"
url = env("DATABASE_URL")
}
model Metadata {
uri String
aiSummary String?
aiScore Int?
@@id([uri])
@@index([uri])
}

14
src/lib/prisma.server.ts Normal file
View File

@ -0,0 +1,14 @@
import { PrismaClient } from "@prisma/client"
let prisma: PrismaClient
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient()
} else {
if (!global.prisma) {
global.prisma = new PrismaClient()
}
prisma = global.prisma
}
export default prisma

4
types/global.d.ts vendored
View File

@ -1,3 +1,5 @@
import { PrismaClient } from "@prisma/client"
export {}
declare global {
@ -7,4 +9,6 @@ declare global {
thisArg?: any,
): number
}
var prisma: PrismaClient | undefined
}