diff --git a/instrumentation.ts b/instrumentation.ts index 2accae6..b8563ff 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -1,4 +1,5 @@ import { PrismaClient } from '@prisma/client' +import cuid from 'cuid' export async function register() { try { @@ -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', 'admin@qq.com', '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' }, diff --git a/package.json b/package.json index 25084be..82aa0c1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1ea759c..ad96dd4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,6 +47,9 @@ dependencies: crypto-js: specifier: ^4.2.0 version: 4.2.0 + cuid: + specifier: ^3.0.0 + version: 3.0.0 dayjs: specifier: ^1.11.11 version: 1.11.11 @@ -5830,6 +5833,11 @@ packages: /csstype@3.1.3: resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + /cuid@3.0.0: + resolution: {integrity: sha512-WZYYkHdIDnaxdeP8Misq3Lah5vFjJwGuItJuV+tvMafosMzw0nF297T7mrm8IOWiPJkV6gc7sa8pzx27+w25Zg==} + deprecated: Cuid and other k-sortable and non-cryptographic ids (Ulid, ObjectId, KSUID, all UUIDs) are all insecure. Use @paralleldrive/cuid2 instead. + dev: false + /damerau-levenshtein@1.0.8: resolution: {integrity: sha512-sdQSFB7+llfUcQHUQO3+B8ERRj0Oa4w9POWMI/puGtuf7gFywGmkaLCElnudfTiKZV+NvHqL0ifzdrI8Ro7ESA==} dev: true diff --git a/prisma/migrations/20240505050304_v2/migration.sql b/prisma/migrations/20240505050304_v2/migration.sql new file mode 100644 index 0000000..e083f15 --- /dev/null +++ b/prisma/migrations/20240505050304_v2/migration.sql @@ -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"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1bf76b0..6609dae 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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?