Complete refractor - we do sexy code only

This commit is contained in:
2024-05-09 04:00:05 +02:00
parent ca88c085e6
commit 8356a83431
28 changed files with 449 additions and 492 deletions

View File

@ -1,42 +0,0 @@
-- CreateTable
CREATE TABLE `User` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`username` VARCHAR(191) NOT NULL,
`password` VARCHAR(191) NOT NULL,
`position_x` INTEGER NOT NULL,
`position_y` INTEGER NOT NULL,
`rotation` INTEGER NOT NULL,
`mapId` INTEGER NULL,
UNIQUE INDEX `User_username_key`(`username`),
UNIQUE INDEX `User_mapId_key`(`mapId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Map` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`tiles` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Chatlogs` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`userId` INTEGER NOT NULL,
`message` VARCHAR(191) NOT NULL,
`mapId` INTEGER NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `User` ADD CONSTRAINT `User_mapId_fkey` FOREIGN KEY (`mapId`) REFERENCES `Map`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Chatlogs` ADD CONSTRAINT `Chatlogs_mapId_fkey` FOREIGN KEY (`mapId`) REFERENCES `Map`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Chatlogs` ADD CONSTRAINT `Chatlogs_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -1,4 +0,0 @@
-- AlterTable
ALTER TABLE `User` MODIFY `position_x` INTEGER NULL,
MODIFY `position_y` INTEGER NULL,
MODIFY `rotation` INTEGER NULL;

View File

@ -1,12 +0,0 @@
/*
Warnings:
- You are about to alter the column `tiles` on the `Map` table. The data in that column could be lost. The data in that column will be cast from `VarChar(191)` to `Json`.
- Added the required column `height` to the `Map` table without a default value. This is not possible if the table is not empty.
- Added the required column `width` to the `Map` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `Map` ADD COLUMN `height` INTEGER NOT NULL,
ADD COLUMN `width` INTEGER NOT NULL,
MODIFY `tiles` JSON NOT NULL;

View File

@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE `User` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`email` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NULL,
UNIQUE INDEX `User_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -0,0 +1,59 @@
/*
Warnings:
- You are about to drop the column `email` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `name` on the `User` table. All the data in the column will be lost.
- A unique constraint covering the columns `[username]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[mapId]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `password` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `username` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX `User_email_key` ON `User`;
-- AlterTable
ALTER TABLE `User` DROP COLUMN `email`,
DROP COLUMN `name`,
ADD COLUMN `mapId` INTEGER NULL,
ADD COLUMN `password` VARCHAR(191) NOT NULL,
ADD COLUMN `position_x` INTEGER NULL,
ADD COLUMN `position_y` INTEGER NULL,
ADD COLUMN `rotation` INTEGER NULL,
ADD COLUMN `username` VARCHAR(191) NOT NULL;
-- CreateTable
CREATE TABLE `Map` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`width` INTEGER NOT NULL,
`height` INTEGER NOT NULL,
`tiles` JSON NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Chatlogs` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`userId` INTEGER NOT NULL,
`message` VARCHAR(191) NOT NULL,
`mapId` INTEGER NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `User_username_key` ON `User`(`username`);
-- CreateIndex
CREATE UNIQUE INDEX `User_mapId_key` ON `User`(`mapId`);
-- AddForeignKey
ALTER TABLE `User` ADD CONSTRAINT `User_mapId_fkey` FOREIGN KEY (`mapId`) REFERENCES `Map`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Chatlogs` ADD CONSTRAINT `Chatlogs_mapId_fkey` FOREIGN KEY (`mapId`) REFERENCES `Map`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Chatlogs` ADD CONSTRAINT `Chatlogs_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -1,8 +1,14 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
// CHEAT SHEET
// 1. Create a new Prisma project
// npx prisma init
// 2. Create a new database schema
// npx prisma db push
// 3. Generate Prisma Client
// npx prisma generate
// 4. Create a new migration
// npx prisma migrate dev --name init
// 5. Apply the migration
// npx prisma migrate deploy
generator client {
provider = "prisma-client-js"