/*
  Warnings:

  - The required column `referralCode` was added to the `Customer` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.

*/
-- AlterTable
ALTER TABLE `Customer` ADD COLUMN `referralCode` VARCHAR(191) NOT NULL,
    ADD COLUMN `referredById` INTEGER NULL;

-- CreateTable
CREATE TABLE `LoyaltyPoint` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `customerId` INTEGER NOT NULL,
    `points` INTEGER NOT NULL DEFAULT 0,
    `reason` VARCHAR(191) NULL,
    `type` VARCHAR(191) NOT NULL,
    `transactionRef` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

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

-- AddForeignKey
ALTER TABLE `Customer` ADD CONSTRAINT `Customer_referredById_fkey` FOREIGN KEY (`referredById`) REFERENCES `Customer`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `LoyaltyPoint` ADD CONSTRAINT `LoyaltyPoint_customerId_fkey` FOREIGN KEY (`customerId`) REFERENCES `Customer`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
