DB adjustments

This commit is contained in:
Dennis Postma 2024-07-20 22:53:02 +02:00
parent be2d7ca7f8
commit fe437aa331
3 changed files with 48 additions and 27 deletions

View File

@ -0,0 +1,20 @@
/*
Warnings:
- You are about to drop the column `isEnemy` on the `Sprite` table. All the data in the column will be lost.
- You are about to drop the column `isPlayableCharacter` on the `Sprite` table. All the data in the column will be lost.
- You are about to drop the column `type` on the `Sprite` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `Object` ADD COLUMN `frameHeight` INTEGER NOT NULL DEFAULT 0,
ADD COLUMN `frameSpeed` INTEGER NOT NULL DEFAULT 0,
ADD COLUMN `frameWidth` INTEGER NOT NULL DEFAULT 0,
ADD COLUMN `isAnimated` BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE `Sprite` DROP COLUMN `isEnemy`,
DROP COLUMN `isPlayableCharacter`,
DROP COLUMN `type`,
ADD COLUMN `frameHeight` INTEGER NOT NULL DEFAULT 0,
ADD COLUMN `frameWidth` INTEGER NOT NULL DEFAULT 0;

View File

@ -6,7 +6,7 @@
// 3. Generate Prisma Client and type-safe models based on schema // 3. Generate Prisma Client and type-safe models based on schema
// npx prisma generate // npx prisma generate
// 4. Create a new migration // 4. Create a new migration
// npx prisma migrate dev --name init // npx prisma migrate dev --name [migration-name]
// 5. Apply the migration // 5. Apply the migration
// npx prisma migrate deploy // npx prisma migrate deploy
@ -20,18 +20,17 @@ datasource db {
} }
model Sprite { model Sprite {
id String @id @default(uuid()) id String @id @default(uuid())
name String name String
origin_x Decimal @default(0) origin_x Decimal @default(0)
origin_y Decimal @default(0) origin_y Decimal @default(0)
type String frameSpeed Int @default(0)
frameSpeed Int @default(0) frameWidth Int @default(0)
isAnimated Boolean @default(false) frameHeight Int @default(0)
isLooping Boolean @default(false) isAnimated Boolean @default(false)
isPlayableCharacter Boolean @default(false) isLooping Boolean @default(false)
isEnemy Boolean @default(false) createdAt DateTime @default(now())
createdAt DateTime @default(now()) updatedAt DateTime @updatedAt
updatedAt DateTime @updatedAt
} }
model Tile { model Tile {
@ -43,14 +42,18 @@ model Tile {
} }
model Object { model Object {
id String @id @default(uuid()) id String @id @default(uuid())
name String name String
tags Json? tags Json?
origin_x Decimal @default(0) origin_x Decimal @default(0)
origin_y Decimal @default(0) origin_y Decimal @default(0)
createdAt DateTime @default(now()) isAnimated Boolean @default(false)
updatedAt DateTime @updatedAt frameSpeed Int @default(0)
ZoneObject ZoneObject[] frameWidth Int @default(0)
frameHeight Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
ZoneObject ZoneObject[]
} }
model Item { model Item {

View File

@ -12,25 +12,23 @@ class SpriteRepository {
return prisma.sprite.findMany(); return prisma.sprite.findMany();
} }
async create(name: string, origin_x: number, origin_y: number, type: string): Promise<Sprite> { async create(name: string, origin_x: number, origin_y: number): Promise<Sprite> {
return prisma.sprite.create({ return prisma.sprite.create({
data: { data: {
name, name,
origin_x, origin_x,
origin_y, origin_y
type
}, },
}); });
} }
async update(id: string, name: string, origin_x: number, origin_y: number, type: string): Promise<Sprite> { async update(id: string, name: string, origin_x: number, origin_y: number): Promise<Sprite> {
return prisma.sprite.update({ return prisma.sprite.update({
where: { id }, where: { id },
data: { data: {
name, name,
origin_x, origin_x,
origin_y, origin_y
type
}, },
}); });
} }