/*
  Warnings:

  - The values [INCOMING,PREPARING,READY,DELIVERY,COMPLETED] on the enum `OrderStatus` will be removed. If these variants are still used in the database, this will fail.
  - You are about to drop the column `isFirstLogin` on the `Customer` table. All the data in the column will be lost.
  - You are about to drop the column `orderId` on the `Item` table. All the data in the column will be lost.
  - You are about to drop the column `productId` on the `Item` table. All the data in the column will be lost.
  - You are about to drop the column `isFirstLogin` on the `Merchant` table. All the data in the column will be lost.
  - You are about to alter the column `rating` on the `Merchant` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Integer`.
  - You are about to drop the column `orderImageUrl` on the `Order` table. All the data in the column will be lost.
  - You are about to drop the column `imgUrl` on the `Product` table. All the data in the column will be lost.
  - You are about to drop the column `variantId` on the `Product` table. All the data in the column will be lost.
  - You are about to drop the column `brand` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `clearanceUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `coins` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `color` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `driversLicenceUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `isRegisteredOwner` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `motorType` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `officialReceiptUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `plateNumber` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `supportingDocumentUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `vaccinationCardUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `vehicleYearModelUrl` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `year` on the `Rider` table. All the data in the column will be lost.
  - You are about to drop the column `adminType` on the `User` table. All the data in the column will be lost.
  - You are about to drop the column `birthDate` on the `User` table. All the data in the column will be lost.
  - You are about to drop the column `imgProfileUrl` on the `User` table. All the data in the column will be lost.
  - You are about to drop the column `sex` on the `User` table. All the data in the column will be lost.
  - You are about to drop the column `userType` on the `User` table. All the data in the column will be lost.
  - Added the required column `cartId` to the `Item` table without a default value. This is not possible if the table is not empty.
  - Added the required column `variantId` to the `Item` 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.
  - Changed the type of `approvalStatus` on the `Rider` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
  - Made the column `name` on table `User` required. This step will fail if there are existing NULL values in that column.

*/
-- AlterEnum
BEGIN;
CREATE TYPE "OrderStatus_new" AS ENUM ('Preparing', 'Ready', 'Incoming', 'Delivered', 'Completed');
ALTER TABLE "Order" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "Order" ALTER COLUMN "status" TYPE "OrderStatus_new" USING ("status"::text::"OrderStatus_new");
ALTER TYPE "OrderStatus" RENAME TO "OrderStatus_old";
ALTER TYPE "OrderStatus_new" RENAME TO "OrderStatus";
DROP TYPE "OrderStatus_old";
ALTER TABLE "Order" ALTER COLUMN "status" SET DEFAULT 'Preparing';
COMMIT;

-- DropForeignKey
ALTER TABLE "Item" DROP CONSTRAINT "Item_orderId_fkey";

-- DropForeignKey
ALTER TABLE "Item" DROP CONSTRAINT "Item_productId_fkey";

-- DropIndex
DROP INDEX "Order_merchantId_key";

-- DropIndex
DROP INDEX "User_email_key";

-- DropIndex
DROP INDEX "User_phoneNumber_key";

-- AlterTable
ALTER TABLE "Customer" DROP COLUMN "isFirstLogin";

-- AlterTable
ALTER TABLE "Item" DROP COLUMN "orderId",
DROP COLUMN "productId",
ADD COLUMN     "cartId" INTEGER NOT NULL,
ADD COLUMN     "variantId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "Merchant" DROP COLUMN "isFirstLogin",
ALTER COLUMN "rating" SET DATA TYPE INTEGER;

-- AlterTable
ALTER TABLE "Order" DROP COLUMN "orderImageUrl",
ALTER COLUMN "status" SET DEFAULT 'Preparing';

-- AlterTable
ALTER TABLE "Product" DROP COLUMN "imgUrl",
DROP COLUMN "variantId";

-- AlterTable
ALTER TABLE "Rider" DROP COLUMN "brand",
DROP COLUMN "clearanceUrl",
DROP COLUMN "coins",
DROP COLUMN "color",
DROP COLUMN "driversLicenceUrl",
DROP COLUMN "isRegisteredOwner",
DROP COLUMN "motorType",
DROP COLUMN "officialReceiptUrl",
DROP COLUMN "plateNumber",
DROP COLUMN "supportingDocumentUrl",
DROP COLUMN "vaccinationCardUrl",
DROP COLUMN "vehicleYearModelUrl",
DROP COLUMN "year",
ADD COLUMN     "driversLicence" TEXT NOT NULL,
ADD COLUMN     "vehicleType" "Vehicle" NOT NULL DEFAULT 'BIKE',
DROP COLUMN "approvalStatus",
ADD COLUMN     "approvalStatus" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "User" DROP COLUMN "adminType",
DROP COLUMN "birthDate",
DROP COLUMN "imgProfileUrl",
DROP COLUMN "sex",
DROP COLUMN "userType",
ADD COLUMN     "role" TEXT NOT NULL DEFAULT 'USER',
ALTER COLUMN "name" SET NOT NULL;

-- DropEnum
DROP TYPE "MotorType";

-- DropEnum
DROP TYPE "RiderStatus";

-- DropEnum
DROP TYPE "UserType";

-- CreateTable
CREATE TABLE "SuperAdmin" (
    "id" SERIAL NOT NULL,
    "adminType" "AdminType" NOT NULL DEFAULT 'CSR',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "Cart" (
    "id" SERIAL NOT NULL,
    "customerId" INTEGER NOT NULL,
    "merchantId" INTEGER NOT NULL,
    "visibility" BOOLEAN NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "_addOnItems" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "_productAddOns" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL
);

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

-- CreateIndex
CREATE UNIQUE INDEX "_addOnItems_AB_unique" ON "_addOnItems"("A", "B");

-- CreateIndex
CREATE INDEX "_addOnItems_B_index" ON "_addOnItems"("B");

-- CreateIndex
CREATE UNIQUE INDEX "_productAddOns_AB_unique" ON "_productAddOns"("A", "B");

-- CreateIndex
CREATE INDEX "_productAddOns_B_index" ON "_productAddOns"("B");

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

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

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

-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_variantId_fkey" FOREIGN KEY ("variantId") REFERENCES "Variant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Item" ADD CONSTRAINT "Item_cartId_fkey" FOREIGN KEY ("cartId") REFERENCES "Cart"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_addOnItems" ADD CONSTRAINT "_addOnItems_A_fkey" FOREIGN KEY ("A") REFERENCES "Item"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_addOnItems" ADD CONSTRAINT "_addOnItems_B_fkey" FOREIGN KEY ("B") REFERENCES "Variant"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_productAddOns" ADD CONSTRAINT "_productAddOns_A_fkey" FOREIGN KEY ("A") REFERENCES "Product"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_productAddOns" ADD CONSTRAINT "_productAddOns_B_fkey" FOREIGN KEY ("B") REFERENCES "Product"("id") ON DELETE CASCADE ON UPDATE CASCADE;
