chore: init
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
client
|
||||
schemas
|
||||
zod
|
||||
dist
|
||||
dbml
|
||||
@@ -0,0 +1,7 @@
|
||||
declare global {
|
||||
namespace PrismaJson {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export { }
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import './global'
|
||||
|
||||
export * from './client'
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "database",
|
||||
"exports": {
|
||||
".": "./client/index.js",
|
||||
"./zod": {
|
||||
"types": "./zod/index.d.ts",
|
||||
"import": "./dist/zod/index.js",
|
||||
"require": "./dist/zod/index.js"
|
||||
},
|
||||
"./global": "./global.ts"
|
||||
},
|
||||
"main": "./client/index.js",
|
||||
"scripts": {
|
||||
"db:generate": "rimraf dist client && prisma generate && tsc && cp -r client dist/client",
|
||||
"db:push": "prisma db push --skip-generate",
|
||||
"migrate:dev": "prisma migrate dev",
|
||||
"migrate:dev:create": "prisma migrate dev --create-only",
|
||||
"migrate:deploy": "prisma migrate deploy",
|
||||
"prisma:migrate:deploy": "prisma migrate deploy",
|
||||
"prisma:migrate:status": "prisma migrate status --preview-feature",
|
||||
"prisma:migrate:resolve": "prisma migrate resolve --preview-feature",
|
||||
"prisma:studio": "prisma studio",
|
||||
"prisma:seed": "prisma db seed"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "5.10.2",
|
||||
"zod": "3.22.4",
|
||||
"zod-prisma-types": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prisma": "5.10.2",
|
||||
"prisma-dbml-generator": "^0.10.0",
|
||||
"prisma-json-types-generator": "3.0.3"
|
||||
},
|
||||
"prisma": {
|
||||
"seed": "npx ts-node seed.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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"
|
||||
output = "./client"
|
||||
}
|
||||
|
||||
generator dbml {
|
||||
provider = "prisma-dbml-generator"
|
||||
}
|
||||
|
||||
generator json {
|
||||
provider = "prisma-json-types-generator"
|
||||
namespace = "PrismaJson"
|
||||
|
||||
allowAny = false
|
||||
}
|
||||
|
||||
generator zod {
|
||||
provider = "zod-prisma-types"
|
||||
output = "./zod" // default is ./generated/zod
|
||||
useMultipleFiles = true // default is false
|
||||
writeBarrelFiles = true // default is true
|
||||
createInputTypes = false // default is true
|
||||
createModelTypes = true // default is true
|
||||
addInputTypeValidation = false // default is true
|
||||
addIncludeType = false // default is true
|
||||
addSelectType = false // default is true
|
||||
validateWhereUniqueInput = false // default is false
|
||||
createOptionalDefaultValuesTypes = true // default is false
|
||||
createRelationValuesTypes = false // default is false
|
||||
createPartialTypes = false // default is false
|
||||
useDefaultValidators = true // default is true
|
||||
coerceDate = true // default is true
|
||||
writeNullishInModelTypes = false // default is false
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default("")
|
||||
username String @unique() @db.VarChar(80)
|
||||
password String @db.VarChar(80)
|
||||
/// @zod.string.url()
|
||||
avatar String @db.VarChar(1024)
|
||||
/// @zod.string.email()
|
||||
email String? @unique() @db.VarChar(80)
|
||||
status Int? @default(1) @db.SmallInt
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
role Role @default(User)
|
||||
todos Todo[]
|
||||
}
|
||||
|
||||
model Todo {
|
||||
id String @id @default("")
|
||||
value String
|
||||
status Boolean @default(false)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId String
|
||||
}
|
||||
|
||||
enum Role {
|
||||
Admin
|
||||
User
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { PrismaClient, Prisma } from '.';
|
||||
import { hashSync } from 'bcrypt'
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log('Seeding...');
|
||||
|
||||
await prisma.user.upsert({
|
||||
where: { username: 'admin' },
|
||||
create: {
|
||||
id: '23900561662304251',
|
||||
username: 'admin',
|
||||
password: hashSync('Aa123456', 10),
|
||||
role: "Admin",
|
||||
avatar: 'https://api.dicebear.com/7.x/identicon/svg?seed=Muffin',
|
||||
email: 'admin@example.com',
|
||||
},
|
||||
update: {}
|
||||
})
|
||||
|
||||
const userId = '23900561662304252'
|
||||
await prisma.user.upsert({
|
||||
where: { username: 'user' },
|
||||
create: {
|
||||
id: '23900561662304252',
|
||||
username: 'user',
|
||||
password: hashSync('Aa123456', 10),
|
||||
role: "User",
|
||||
avatar: 'https://kuizuo.cn/img/logo.png',
|
||||
email: 'hi@example.cn',
|
||||
},
|
||||
update: {}
|
||||
})
|
||||
|
||||
const todos = ['code', 'sleep', 'eat']
|
||||
|
||||
await prisma.todo.createMany({
|
||||
data: todos.map((todo, i) => ({
|
||||
id: '2390056166230000' + i,
|
||||
userId: userId,
|
||||
value: todo
|
||||
}))
|
||||
})
|
||||
|
||||
console.log('Seeding done!');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => console.error(e))
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"target": "es2021",
|
||||
"experimentalDecorators": true,
|
||||
"module": "CommonJS",
|
||||
"paths": {},
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"removeComments": true,
|
||||
"sourceMap": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"./zod",
|
||||
"./global.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user