mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 13:00:25 +02:00
Update scanner (server)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `name` on the `Task` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `progress` on the `Task` table. All the data in the column will be lost.
|
||||
- Made the column `isError` on table `Task` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Task" DROP COLUMN "name",
|
||||
DROP COLUMN "progress",
|
||||
ADD COLUMN "userId" UUID,
|
||||
ALTER COLUMN "isError" SET NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Task" ADD CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -75,12 +75,12 @@ model User {
|
||||
|
||||
serverFolderPermissions ServerFolderPermission[]
|
||||
serverPermissions ServerPermission[]
|
||||
// serverCredentials ServerCredential[]
|
||||
albumArtistFavorites AlbumArtistFavorite[]
|
||||
artistFavorites ArtistFavorite[]
|
||||
albumFavorites AlbumFavorite[]
|
||||
songFavorites SongFavorite[]
|
||||
userServerUrls UserServerUrl[]
|
||||
tasks Task[]
|
||||
}
|
||||
|
||||
model History {
|
||||
@@ -112,26 +112,10 @@ model Server {
|
||||
serverUrls ServerUrl[]
|
||||
folders Folder[]
|
||||
serverPermissions ServerPermission[]
|
||||
// serverCredentials ServerCredential[]
|
||||
tasks Task[]
|
||||
userServerUrls UserServerUrl[]
|
||||
}
|
||||
|
||||
// model ServerCredential {
|
||||
// id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
// username String
|
||||
// enabled Boolean @default(false)
|
||||
// credential String
|
||||
// createdAt DateTime @default(now())
|
||||
// updatedAt DateTime @updatedAt
|
||||
|
||||
// server Server @relation(fields: [serverId], references: [id], onDelete: Cascade)
|
||||
// serverId String @db.Uuid
|
||||
|
||||
// user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
// userId String @db.Uuid
|
||||
// }
|
||||
|
||||
model Folder {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
@@ -518,15 +502,16 @@ model Song {
|
||||
|
||||
model Task {
|
||||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
|
||||
name String
|
||||
type TaskType
|
||||
message String?
|
||||
progress String?
|
||||
completed Boolean @default(false)
|
||||
isError Boolean? @default(false)
|
||||
isError Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
server Server @relation(fields: [serverId], references: [id], onDelete: Cascade)
|
||||
serverId String @db.Uuid
|
||||
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
userId String? @db.Uuid
|
||||
}
|
||||
|
||||
+25
-15
@@ -1,24 +1,34 @@
|
||||
/* eslint-disable promise/catch-or-return */
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { PrismaClient, Prisma } from '@prisma/client';
|
||||
import { randomString } from '../utils';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const hashedPassword = await bcrypt.hash('admin', 12);
|
||||
const hashedPassword =
|
||||
'$2y$12$icIH42ono1yTBypZ34V/PuDMXIbMD04GtSB6pgYpcwbjjIvujzv2y';
|
||||
|
||||
await prisma.user.upsert({
|
||||
create: {
|
||||
deviceId: `admin_${randomString(10)}`,
|
||||
enabled: true,
|
||||
isAdmin: true,
|
||||
password: hashedPassword,
|
||||
username: 'admin',
|
||||
},
|
||||
update: {},
|
||||
where: { username: 'admin' },
|
||||
});
|
||||
let error;
|
||||
do {
|
||||
try {
|
||||
await prisma.user.upsert({
|
||||
create: {
|
||||
deviceId: `admin_${randomString(10)}`,
|
||||
enabled: true,
|
||||
isAdmin: true,
|
||||
password: hashedPassword,
|
||||
username: 'admin',
|
||||
},
|
||||
update: {},
|
||||
where: { username: 'admin' },
|
||||
});
|
||||
} catch (e) {
|
||||
if (e instanceof Prisma.PrismaClientInitializationError) {
|
||||
error = 'retry';
|
||||
}
|
||||
|
||||
error = undefined;
|
||||
}
|
||||
} while (error === 'retry');
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user