Updated DB models

This commit is contained in:
Dennis Postma 2024-07-25 04:05:05 +02:00
parent 3f4e9fa36e
commit ec4a9904f4
4 changed files with 14 additions and 16 deletions

View File

@ -20,10 +20,9 @@ CREATE TABLE `Sprite` (
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `SpriteImage` (
CREATE TABLE `SpriteAction` (
`id` VARCHAR(191) NOT NULL,
`spriteId` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`action` VARCHAR(191) NOT NULL,
`origin_x` DECIMAL(65, 30) NOT NULL DEFAULT 0,
`origin_y` DECIMAL(65, 30) NOT NULL DEFAULT 0,
@ -173,7 +172,7 @@ ALTER TABLE `Chat` ADD CONSTRAINT `Chat_characterId_fkey` FOREIGN KEY (`characte
ALTER TABLE `Chat` ADD CONSTRAINT `Chat_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `SpriteImage` ADD CONSTRAINT `SpriteImage_spriteId_fkey` FOREIGN KEY (`spriteId`) REFERENCES `Sprite`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `SpriteAction` ADD CONSTRAINT `SpriteAction_spriteId_fkey` FOREIGN KEY (`spriteId`) REFERENCES `Sprite`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `CharacterType` ADD CONSTRAINT `CharacterType_spriteId_fkey` FOREIGN KEY (`spriteId`) REFERENCES `Sprite`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,17 +1,16 @@
model Sprite {
id String @id @default(uuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
spriteImages SpriteImage[]
id String @id @default(uuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
spriteActions SpriteAction[]
characterTypes CharacterType[]
}
model SpriteImage {
model SpriteAction {
id String @id @default(uuid())
spriteId String
sprite Sprite @relation(fields: [spriteId], references: [id], onDelete: Cascade)
name String
action String
origin_x Decimal @default(0)
origin_y Decimal @default(0)

View File

@ -1,18 +1,18 @@
import { Server } from 'socket.io'
import { TSocket } from '../../../utilities/Types'
import prisma from '../../../utilities/Prisma'
import type { SpriteImage } from '@prisma/client'
import type { SpriteAction } from '@prisma/client'
import path from 'path'
import fs from 'fs'
type uploadSpriteImage = SpriteImage & {
type uploadSpriteAction = SpriteAction & {
base64?: string
}
type Payload = {
id: string
name: string
spriteImages: uploadSpriteImage[]
spriteActions: uploadSpriteAction[]
}
/**
@ -33,11 +33,11 @@ export default function (socket: TSocket, io: Server) {
},
data: {
name: data.name,
spriteImages: {
spriteActions: {
deleteMany: {
spriteId: data.id
},
create: data.spriteImages
create: data.spriteActions
}
}
})

View File

@ -6,7 +6,7 @@ class SpriteRepository {
return prisma.sprite.findUnique({
where: { id },
include: {
spriteImages: true
spriteActions: true
}
})
}