/*
  Warnings:

  - You are about to drop the column `email` on the `Customer` table. All the data in the column will be lost.
  - You are about to drop the column `firstName` on the `Customer` table. All the data in the column will be lost.
  - You are about to drop the column `lastName` on the `Customer` table. All the data in the column will be lost.
  - You are about to drop the column `password` on the `Customer` table. All the data in the column will be lost.
  - You are about to drop the column `phoneNumber` on the `Customer` table. All the data in the column will be lost.
  - The `address` column on the `Customer` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the column `openinTime` on the `Merchant` table. All the data in the column will be lost.
  - You are about to drop the column `updateAt` on the `Merchant` table. All the data in the column will be lost.
  - The `operatingDays` column on the `Merchant` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - The `approvalStatus` column on the `Merchant` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the column `driversLiscence` on the `Rider` table. All the data in the column will be lost.
  - The `vehicleType` column on the `Rider` table would be dropped and recreated. This will lead to data loss if there is data in the column.
  - You are about to drop the column `userIds` on the `SuperAdmin` table. All the data in the column will be lost.
  - You are about to drop the `ItemGroups` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `Orders` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `Products` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `productItemGroups` table. If the table is not empty, all the data it contains will be lost.
  - A unique constraint covering the columns `[userId]` on the table `SuperAdmin` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[phoneNumber]` on the table `User` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `orderId` to the `Item` table without a default value. This is not possible if the table is not empty.
  - Added the required column `isOpen` to the `Merchant` table without a default value. This is not possible if the table is not empty.
  - Added the required column `openingTime` to the `Merchant` table without a default value. This is not possible if the table is not empty.
  - Added the required column `rating` to the `Merchant` table without a default value. This is not possible if the table is not empty.
  - Added the required column `updatedAt` to the `Merchant` table without a default value. This is not possible if the table is not empty.
  - Added the required column `visibility` to the `Merchant` table without a default value. This is not possible if the table is not empty.
  - Added the required column `brand` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `clearance` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `color` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `driversLicence` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `motorType` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `officialReceipt` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `plateNumber` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `professionalDriverLicense` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `registeredOwner` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `supportingDocument` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `vaccinationCard` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `vehicleData` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `vehicleYearModel` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `year` to the `Rider` table without a default value. This is not possible if the table is not empty.
  - Added the required column `userId` to the `SuperAdmin` table without a default value. This is not possible if the table is not empty.
  - Added the required column `birthDate` to the `User` table without a default value. This is not possible if the table is not empty.
  - Added the required column `email` to the `User` table without a default value. This is not possible if the table is not empty.
  - Added the required column `sex` to the `User` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "Vehicle" AS ENUM ('CAR', 'BIKE', 'TRUCK', 'VAN', 'BUS', 'TRICYCLE', 'KEKE', 'OTHER');

-- CreateEnum
CREATE TYPE "MerchantDay" AS ENUM ('SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY');

-- CreateEnum
CREATE TYPE "ApprovalStatus" AS ENUM ('PENDING', 'APPROVED', 'REJECTED');

-- DropForeignKey
ALTER TABLE "Category" DROP CONSTRAINT "Category_productId_fkey";

-- DropForeignKey
ALTER TABLE "ItemGroups" DROP CONSTRAINT "ItemGroups_productItemId_fkey";

-- DropForeignKey
ALTER TABLE "Orders" DROP CONSTRAINT "Orders_customerId_fkey";

-- DropForeignKey
ALTER TABLE "Orders" DROP CONSTRAINT "Orders_itemId_fkey";

-- DropForeignKey
ALTER TABLE "Orders" DROP CONSTRAINT "Orders_riderId_fkey";

-- DropForeignKey
ALTER TABLE "Products" DROP CONSTRAINT "Products_itemId_fkey";

-- DropForeignKey
ALTER TABLE "Products" DROP CONSTRAINT "Products_merchantId_fkey";

-- DropForeignKey
ALTER TABLE "Products" DROP CONSTRAINT "Products_productItemId_fkey";

-- DropForeignKey
ALTER TABLE "SuperAdmin" DROP CONSTRAINT "SuperAdmin_userIds_fkey";

-- DropIndex
DROP INDEX "Customer_phoneNumber_key";

-- DropIndex
DROP INDEX "SuperAdmin_userIds_key";

-- AlterTable
ALTER TABLE "Customer" DROP COLUMN "email",
DROP COLUMN "firstName",
DROP COLUMN "lastName",
DROP COLUMN "password",
DROP COLUMN "phoneNumber",
DROP COLUMN "address",
ADD COLUMN     "address" TEXT[];

-- AlterTable
ALTER TABLE "Item" ADD COLUMN     "orderId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "Merchant" DROP COLUMN "openinTime",
DROP COLUMN "updateAt",
ADD COLUMN     "isOpen" BOOLEAN NOT NULL,
ADD COLUMN     "openingTime" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "rating" INTEGER NOT NULL,
ADD COLUMN     "updatedAt" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "visibility" BOOLEAN NOT NULL,
DROP COLUMN "operatingDays",
ADD COLUMN     "operatingDays" "MerchantDay"[],
DROP COLUMN "approvalStatus",
ADD COLUMN     "approvalStatus" "ApprovalStatus" NOT NULL DEFAULT 'PENDING';

-- AlterTable
ALTER TABLE "Rider" DROP COLUMN "driversLiscence",
ADD COLUMN     "brand" TEXT NOT NULL,
ADD COLUMN     "clearance" TEXT NOT NULL,
ADD COLUMN     "color" TEXT NOT NULL,
ADD COLUMN     "driversLicence" TEXT NOT NULL,
ADD COLUMN     "motorType" TEXT NOT NULL,
ADD COLUMN     "officialReceipt" TEXT NOT NULL,
ADD COLUMN     "plateNumber" TEXT NOT NULL,
ADD COLUMN     "professionalDriverLicense" TEXT NOT NULL,
ADD COLUMN     "registeredOwner" TEXT NOT NULL,
ADD COLUMN     "supportingDocument" TEXT NOT NULL,
ADD COLUMN     "vaccinationCard" TEXT NOT NULL,
ADD COLUMN     "vehicleData" TEXT NOT NULL,
ADD COLUMN     "vehicleYearModel" TEXT NOT NULL,
ADD COLUMN     "year" TIMESTAMP(3) NOT NULL,
DROP COLUMN "vehicleType",
ADD COLUMN     "vehicleType" "Vehicle" NOT NULL DEFAULT 'BIKE';

-- AlterTable
ALTER TABLE "SuperAdmin" DROP COLUMN "userIds",
ADD COLUMN     "userId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "User" ADD COLUMN     "birthDate" TIMESTAMP(3) NOT NULL,
ADD COLUMN     "email" TEXT NOT NULL,
ADD COLUMN     "sex" TEXT NOT NULL;

-- DropTable
DROP TABLE "ItemGroups";

-- DropTable
DROP TABLE "Orders";

-- DropTable
DROP TABLE "Products";

-- DropTable
DROP TABLE "productItemGroups";

-- DropEnum
DROP TYPE "MerchantApprovalStatus";

-- DropEnum
DROP TYPE "MerchantDays";

-- DropEnum
DROP TYPE "Vehicles";

-- CreateTable
CREATE TABLE "Order" (
    "id" SERIAL NOT NULL,
    "status" "OrderStatus" NOT NULL DEFAULT 'Preparing',
    "totalPrice" DOUBLE PRECISION NOT NULL,
    "totalQuantity" INTEGER NOT NULL,
    "riderId" INTEGER NOT NULL,
    "customerId" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Order_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Product" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "price" INTEGER NOT NULL,
    "isAvailable" BOOLEAN NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "merchantId" INTEGER NOT NULL,
    "visibility" BOOLEAN NOT NULL,
    "variantId" INTEGER NOT NULL,

    CONSTRAINT "Product_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Variant" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "additionalPrice" INTEGER NOT NULL,
    "isAvailable" BOOLEAN NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "productId" INTEGER NOT NULL,

    CONSTRAINT "Variant_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Review" (
    "id" SERIAL NOT NULL,
    "comment" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "merchantId" INTEGER NOT NULL,
    "customerId" INTEGER NOT NULL,

    CONSTRAINT "Review_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Order_riderId_key" ON "Order"("riderId");

-- CreateIndex
CREATE UNIQUE INDEX "Order_customerId_key" ON "Order"("customerId");

-- CreateIndex
CREATE UNIQUE INDEX "SuperAdmin_userId_key" ON "SuperAdmin"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "User_phoneNumber_key" ON "User"("phoneNumber");

-- AddForeignKey
ALTER TABLE "SuperAdmin" ADD CONSTRAINT "SuperAdmin_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Order" ADD CONSTRAINT "Order_riderId_fkey" FOREIGN KEY ("riderId") REFERENCES "Rider"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Order" ADD CONSTRAINT "Order_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_orderId_fkey" FOREIGN KEY ("orderId") REFERENCES "Order"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Product" ADD CONSTRAINT "Product_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Variant" ADD CONSTRAINT "Variant_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Category" ADD CONSTRAINT "Category_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Review" ADD CONSTRAINT "Review_merchantId_fkey" FOREIGN KEY ("merchantId") REFERENCES "Merchant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Review" ADD CONSTRAINT "Review_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
