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; ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable -- CreateTable
CREATE TABLE `SpriteImage` ( CREATE TABLE `SpriteAction` (
`id` VARCHAR(191) NOT NULL, `id` VARCHAR(191) NOT NULL,
`spriteId` VARCHAR(191) NOT NULL, `spriteId` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`action` VARCHAR(191) NOT NULL, `action` VARCHAR(191) NOT NULL,
`origin_x` DECIMAL(65, 30) NOT NULL DEFAULT 0, `origin_x` DECIMAL(65, 30) NOT NULL DEFAULT 0,
`origin_y` 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; ALTER TABLE `Chat` ADD CONSTRAINT `Chat_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey -- 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 -- AddForeignKey
ALTER TABLE `CharacterType` ADD CONSTRAINT `CharacterType_spriteId_fkey` FOREIGN KEY (`spriteId`) REFERENCES `Sprite`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; 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 { model Sprite {
id String @id @default(uuid()) id String @id @default(uuid())
name String name String
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
spriteImages SpriteImage[] spriteActions SpriteAction[]
characterTypes CharacterType[] characterTypes CharacterType[]
} }
model SpriteImage { model SpriteAction {
id String @id @default(uuid()) id String @id @default(uuid())
spriteId String spriteId String
sprite Sprite @relation(fields: [spriteId], references: [id], onDelete: Cascade) sprite Sprite @relation(fields: [spriteId], references: [id], onDelete: Cascade)
name String
action String action String
origin_x Decimal @default(0) origin_x Decimal @default(0)
origin_y Decimal @default(0) origin_y Decimal @default(0)

View File

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

View File

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