/*
  Warnings:

  - You are about to drop the column `constPerView` on the `Handle` table. All the data in the column will be lost.
  - You are about to drop the `contentDayView` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE `Content` DROP FOREIGN KEY `Content_handleId_fkey`;

-- DropForeignKey
ALTER TABLE `contentDayView` DROP FOREIGN KEY `contentDayView_contentId_fkey`;

-- DropIndex
DROP INDEX `Content_handleId_fkey` ON `Content`;

-- AlterTable
ALTER TABLE `Content` MODIFY `handleId` VARCHAR(191) NULL;

-- AlterTable
ALTER TABLE `Handle` DROP COLUMN `constPerView`,
    ADD COLUMN `costPerView` DOUBLE NOT NULL DEFAULT 1;

-- DropTable
DROP TABLE `contentDayView`;

-- CreateTable
CREATE TABLE `ContentDayView` (
    `id` VARCHAR(191) NOT NULL,
    `contentId` VARCHAR(191) NOT NULL,
    `date` DATETIME(3) NOT NULL,
    `views` INTEGER NOT NULL,
    `validViews` INTEGER NOT NULL,
    `premiumViews` INTEGER NOT NULL,
    `watchTime` INTEGER NOT NULL,

    UNIQUE INDEX `ContentDayView_contentId_date_key`(`contentId`, `date`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Content` ADD CONSTRAINT `Content_handleId_fkey` FOREIGN KEY (`handleId`) REFERENCES `Handle`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ContentDayView` ADD CONSTRAINT `ContentDayView_contentId_fkey` FOREIGN KEY (`contentId`) REFERENCES `Content`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
