/*
  Warnings:

  - You are about to drop the column `email` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `event_id` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `first_name` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `invoice` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `issue_date` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `last_name` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `ticketype_id` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to drop the column `title` on the `ticket_attendees` table. All the data in the column will be lost.
  - You are about to alter the column `code` on the `ticket_attendees` table. The data in that column could be lost. The data in that column will be cast from `VarChar(255)` to `VarChar(191)`.
  - Added the required column `order_id` to the `ticket_attendees` table without a default value. This is not possible if the table is not empty.
  - Added the required column `updatedAt` to the `ticket_attendees` table without a default value. This is not possible if the table is not empty.
  - Added the required column `updatedAt` to the `ticketypes` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE `ticket_attendees` DROP FOREIGN KEY `fk-ticket_attendees-event_id`;

-- DropForeignKey
ALTER TABLE `ticket_attendees` DROP FOREIGN KEY `fk-ticket_attendees-tycketype_id`;

-- DropIndex
DROP INDEX `idx-ticket_attendees-event_id-ticketype_id` ON `ticket_attendees`;

-- AlterTable
ALTER TABLE `ticket_attendees` DROP COLUMN `email`,
    DROP COLUMN `event_id`,
    DROP COLUMN `first_name`,
    DROP COLUMN `invoice`,
    DROP COLUMN `issue_date`,
    DROP COLUMN `last_name`,
    DROP COLUMN `ticketype_id`,
    DROP COLUMN `title`,
    ADD COLUMN `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    ADD COLUMN `details` LONGTEXT NULL,
    ADD COLUMN `event_details` LONGTEXT NULL,
    ADD COLUMN `order_id` INTEGER NOT NULL,
    ADD COLUMN `updatedAt` DATETIME(3) NOT NULL,
    MODIFY `price` DOUBLE NOT NULL DEFAULT 0,
    MODIFY `code` VARCHAR(191) NOT NULL;

-- AlterTable
ALTER TABLE `ticketypes` ADD COLUMN `collect_details` LONGTEXT NULL,
    ADD COLUMN `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    ADD COLUMN `updatedAt` DATETIME(3) NOT NULL;

-- CreateTable
CREATE TABLE `ticket_orders` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `email` VARCHAR(255) NOT NULL,
    `details` LONGTEXT NULL,
    `amount` DOUBLE NULL DEFAULT 0,
    `payment_id` VARCHAR(255) NULL,
    `variant_id` INTEGER NOT NULL,
    `et_id` INTEGER NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `idx-ticketorders-variant_id`(`variant_id`),
    INDEX `idx-ticketorders-et_id`(`et_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateIndex
CREATE INDEX `idx-ticket-order_id` ON `ticket_attendees`(`order_id`);

-- AddForeignKey
ALTER TABLE `ticket_orders` ADD CONSTRAINT `fk-ticketorders-variant_id` FOREIGN KEY (`variant_id`) REFERENCES `ticketypes`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `ticket_orders` ADD CONSTRAINT `fk-ticketorders-et_id` FOREIGN KEY (`et_id`) REFERENCES `event_times`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `ticket_attendees` ADD CONSTRAINT `fk-ticket-order_id` FOREIGN KEY (`order_id`) REFERENCES `ticket_orders`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
