/*
  Warnings:

  - The primary key for the `password_resets` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - You are about to alter the column `id` on the `password_resets` table. The data in that column could be lost. The data in that column will be cast from `UnsignedBigInt` to `VarChar(191)`.
  - You are about to drop the column `name` on the `users` table. All the data in the column will be lost.
  - You are about to drop the column `password` on the `users` table. All the data in the column will be lost.
  - You are about to drop the column `remember_token` on the `users` table. All the data in the column will be lost.
  - You are about to drop the `permission_role` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `permission_user` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `permissions` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `role_user` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `roles` table. If the table is not empty, all the data it contains will be lost.
  - A unique constraint covering the columns `[email]` on the table `password_resets` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[phoneNumber]` on the table `users` will be added. If there are existing duplicate values, this will fail.
  - Made the column `created_at` on table `password_resets` required. This step will fail if there are existing NULL values in that column.
  - Added the required column `firstName` to the `users` table without a default value. This is not possible if the table is not empty.
  - Added the required column `lastName` to the `users` table without a default value. This is not possible if the table is not empty.
  - Added the required column `passwordHash` to the `users` table without a default value. This is not possible if the table is not empty.
  - Added the required column `phoneNumber` to the `users` table without a default value. This is not possible if the table is not empty.
  - Added the required column `role` to the `users` table without a default value. This is not possible if the table is not empty.
  - Made the column `created_at` on table `users` required. This step will fail if there are existing NULL values in that column.
  - Made the column `updated_at` on table `users` required. This step will fail if there are existing NULL values in that column.

*/
-- DropForeignKey
ALTER TABLE `permission_role` DROP FOREIGN KEY `permission_role_permission_id_foreign`;

-- DropForeignKey
ALTER TABLE `permission_role` DROP FOREIGN KEY `permission_role_role_id_foreign`;

-- DropForeignKey
ALTER TABLE `permission_user` DROP FOREIGN KEY `permission_user_permission_id_foreign`;

-- DropForeignKey
ALTER TABLE `role_user` DROP FOREIGN KEY `role_user_role_id_foreign`;

-- AlterTable
ALTER TABLE `password_resets` DROP PRIMARY KEY,
    MODIFY `id` VARCHAR(191) NOT NULL,
    MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    ADD PRIMARY KEY (`id`);

-- AlterTable
ALTER TABLE `users` DROP COLUMN `name`,
    DROP COLUMN `password`,
    DROP COLUMN `remember_token`,
    ADD COLUMN `avatar` VARCHAR(100) NULL,
    ADD COLUMN `biography` TEXT NULL,
    ADD COLUMN `firstName` VARCHAR(50) NOT NULL,
    ADD COLUMN `lastName` VARCHAR(50) NOT NULL,
    ADD COLUMN `passwordHash` VARCHAR(255) NOT NULL,
    ADD COLUMN `phoneNumber` VARCHAR(10) NOT NULL,
    ADD COLUMN `role` ENUM('User', 'Admin') NOT NULL,
    MODIFY `created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    MODIFY `updated_at` TIMESTAMP(0) NOT NULL;

-- DropTable
DROP TABLE `permission_role`;

-- DropTable
DROP TABLE `permission_user`;

-- DropTable
DROP TABLE `permissions`;

-- DropTable
DROP TABLE `role_user`;

-- DropTable
DROP TABLE `roles`;

-- CreateTable
CREATE TABLE `clubs` (
    `id` VARCHAR(255) NOT NULL,
    `phoneId` INTEGER NOT NULL,
    `clubName` VARCHAR(50) NOT NULL,
    `ownerId` BIGINT UNSIGNED NOT NULL,
    `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updatedAt` TIMESTAMP(0) NOT NULL,

    INDEX `clubs_ownerId_phoneId_idx`(`ownerId`, `phoneId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `groups` (
    `id` VARCHAR(255) NOT NULL,
    `phoneId` INTEGER NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `clubId` VARCHAR(255) NOT NULL,
    `createdAt` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `groups_name_clubId_phoneId_idx`(`name`, `clubId`, `phoneId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `players` (
    `id` VARCHAR(255) NOT NULL,
    `phoneId` INTEGER NOT NULL,
    `email` VARCHAR(255) NOT NULL,
    `ownerId` BIGINT UNSIGNED NOT NULL,
    `clubId` VARCHAR(255) NOT NULL,
    `rating` FLOAT NULL,
    `phoneNumber` VARCHAR(15) NULL,
    `firstName` VARCHAR(50) NULL,
    `lastName` VARCHAR(50) NULL,
    `dateOfBirth` DATE NULL,
    `avatarId` VARCHAR(255) NULL,
    `createdAt` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updatedAt` DATETIME(3) NOT NULL,
    `groupId` VARCHAR(255) NOT NULL,

    UNIQUE INDEX `players_email_key`(`email`),
    INDEX `players_clubId_phoneId_idx`(`clubId`, `phoneId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `games` (
    `id` VARCHAR(255) NOT NULL,
    `phoneId` INTEGER NOT NULL,
    `name` VARCHAR(50) NOT NULL,
    `notes` TEXT NOT NULL,
    `sequence` VARCHAR(255) NULL,
    `gameMode` VARCHAR(255) NULL,
    `gameType` VARCHAR(255) NULL,
    `gameTime` VARCHAR(255) NULL,
    `delayTime` VARCHAR(255) NULL,
    `numPads` TINYINT NULL,
    `gameDescription` TEXT NULL,
    `padLightUpTime` DOUBLE NULL,
    `scheduledDate` DATETIME(0) NULL,
    `clubId` VARCHAR(255) NOT NULL,
    `createdAt` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updatedAt` DATETIME(0) NOT NULL,

    INDEX `games_clubId_phoneId_idx`(`clubId`, `phoneId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `game_data` (
    `id` VARCHAR(255) NOT NULL,
    `gameId` VARCHAR(255) NOT NULL,
    `hits` INTEGER NOT NULL,
    `misses` INTEGER NOT NULL,
    `accuracy` FLOAT NOT NULL,
    `timeSequence` VARCHAR(255) NOT NULL,
    `padArrangement` VARCHAR(255) NULL,
    `createdAt` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `game_data_gameId_idx`(`gameId`),
    UNIQUE INDEX `game_data_gameId_key`(`gameId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `stations` (
    `id` VARCHAR(255) NOT NULL,
    `stationName` VARCHAR(255) NULL,
    `padArrangementName` VARCHAR(255) NULL,
    `padArrangementImage` VARCHAR(255) NULL,
    `numOfPads` TINYINT NULL,
    `pads` VARCHAR(255) NULL,
    `stationDescription` TEXT NULL,
    `rectangleAttributes` VARCHAR(255) NULL,
    `gameId` VARCHAR(255) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `_GameDataToPlayer` (
    `A` VARCHAR(255) NOT NULL,
    `B` VARCHAR(255) NOT NULL,

    UNIQUE INDEX `_GameDataToPlayer_AB_unique`(`A`, `B`),
    INDEX `_GameDataToPlayer_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE UNIQUE INDEX `password_resets_email_key` ON `password_resets`(`email`);

-- CreateIndex
CREATE UNIQUE INDEX `users_phoneNumber_key` ON `users`(`phoneNumber`);

-- CreateIndex
CREATE INDEX `users_email_idx` ON `users`(`email`);

-- AddForeignKey
ALTER TABLE `clubs` ADD CONSTRAINT `clubs_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `groups` ADD CONSTRAINT `groups_clubId_fkey` FOREIGN KEY (`clubId`) REFERENCES `clubs`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `players` ADD CONSTRAINT `players_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `players` ADD CONSTRAINT `players_clubId_fkey` FOREIGN KEY (`clubId`) REFERENCES `clubs`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `players` ADD CONSTRAINT `players_groupId_fkey` FOREIGN KEY (`groupId`) REFERENCES `groups`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `games` ADD CONSTRAINT `games_clubId_fkey` FOREIGN KEY (`clubId`) REFERENCES `clubs`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `game_data` ADD CONSTRAINT `game_data_gameId_fkey` FOREIGN KEY (`gameId`) REFERENCES `games`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `stations` ADD CONSTRAINT `stations_gameId_fkey` FOREIGN KEY (`gameId`) REFERENCES `games`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_GameDataToPlayer` ADD FOREIGN KEY (`A`) REFERENCES `game_data`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `_GameDataToPlayer` ADD FOREIGN KEY (`B`) REFERENCES `players`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- RenameIndex
ALTER TABLE `password_resets` RENAME INDEX `password_resets_email_index` TO `password_resets_email_idx`;

-- RenameIndex
ALTER TABLE `users` RENAME INDEX `users_email_unique` TO `users_email_key`;
