Skip to content

Commit

Permalink
fix: 修复用户账户未初始化的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
besscroft committed May 5, 2024
1 parent fcb0508 commit e7e3eef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrismaClient } from '@prisma/client'
import cuid from 'cuid'

export async function register() {
try {
Expand All @@ -8,6 +9,11 @@ export async function register() {
const prisma = new PrismaClient()
if (prisma) {
await prisma.$transaction(async (tx) => {
await tx.$executeRaw`
INSERT INTO "public"."User" (id, name, email, password, image)
VALUES (${cuid()}, 'admin', '[email protected]', '51630b15b0cec2da9926af7015db33b7809f9d24959a0d48665b83e9d19216cd5601d08a622a8b2c48709d5bbb62eef6ae76addce5d18703b28965eef62d491b', 'https://bbs-static.miyoushe.com/communityweb/upload/97734c89374997c7c87d5af5f7442171.png')
ON CONFLICT (name) DO NOTHING;
`
await tx.configs.createMany({
data: [
{ config_key: 'accesskey_id', config_value: '', detail: '阿里 OSS / AWS S3 AccessKey_ID' },
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"crypto-js": "^4.2.0",
"cuid": "^3.0.0",
"dayjs": "^1.11.11",
"exifreader": "^4.22.1",
"framer-motion": "^11.1.7",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions prisma/migrations/20240505050304_v2/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[name]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "User_name_key" ON "User"("name");
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ model Session {

model User {
id String @id @default(cuid())
name String?
name String? @unique
email String? @unique
password String?
emailVerified DateTime?
Expand Down

0 comments on commit e7e3eef

Please sign in to comment.