From fe437aa331fc10b5c5f27b159cddf2c530ae661a Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sat, 20 Jul 2024 22:53:02 +0200 Subject: [PATCH] DB adjustments --- .../migration.sql | 20 +++++++++ prisma/schema.prisma | 45 ++++++++++--------- src/app/repositories/SpriteRepository.ts | 10 ++--- 3 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 prisma/migrations/20240720203031_new_sprite_table_fields/migration.sql diff --git a/prisma/migrations/20240720203031_new_sprite_table_fields/migration.sql b/prisma/migrations/20240720203031_new_sprite_table_fields/migration.sql new file mode 100644 index 0000000..e47dc32 --- /dev/null +++ b/prisma/migrations/20240720203031_new_sprite_table_fields/migration.sql @@ -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; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9aa1d97..7892cec 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -6,7 +6,7 @@ // 3. Generate Prisma Client and type-safe models based on schema // npx prisma generate // 4. Create a new migration -// npx prisma migrate dev --name init +// npx prisma migrate dev --name [migration-name] // 5. Apply the migration // npx prisma migrate deploy @@ -20,18 +20,17 @@ datasource db { } model Sprite { - id String @id @default(uuid()) - name String - origin_x Decimal @default(0) - origin_y Decimal @default(0) - type String - frameSpeed Int @default(0) - isAnimated Boolean @default(false) - isLooping Boolean @default(false) - isPlayableCharacter Boolean @default(false) - isEnemy Boolean @default(false) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + id String @id @default(uuid()) + name String + origin_x Decimal @default(0) + origin_y Decimal @default(0) + frameSpeed Int @default(0) + frameWidth Int @default(0) + frameHeight Int @default(0) + isAnimated Boolean @default(false) + isLooping Boolean @default(false) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt } model Tile { @@ -43,14 +42,18 @@ model Tile { } model Object { - id String @id @default(uuid()) - name String - tags Json? - origin_x Decimal @default(0) - origin_y Decimal @default(0) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - ZoneObject ZoneObject[] + id String @id @default(uuid()) + name String + tags Json? + origin_x Decimal @default(0) + origin_y Decimal @default(0) + isAnimated Boolean @default(false) + frameSpeed Int @default(0) + frameWidth Int @default(0) + frameHeight Int @default(0) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + ZoneObject ZoneObject[] } model Item { diff --git a/src/app/repositories/SpriteRepository.ts b/src/app/repositories/SpriteRepository.ts index a3e839a..6f89172 100644 --- a/src/app/repositories/SpriteRepository.ts +++ b/src/app/repositories/SpriteRepository.ts @@ -12,25 +12,23 @@ class SpriteRepository { return prisma.sprite.findMany(); } - async create(name: string, origin_x: number, origin_y: number, type: string): Promise { + async create(name: string, origin_x: number, origin_y: number): Promise { return prisma.sprite.create({ data: { name, origin_x, - origin_y, - type + origin_y }, }); } - async update(id: string, name: string, origin_x: number, origin_y: number, type: string): Promise { + async update(id: string, name: string, origin_x: number, origin_y: number): Promise { return prisma.sprite.update({ where: { id }, data: { name, origin_x, - origin_y, - type + origin_y }, }); }