CREATE TABLE `cash_session_operations` (
    `id` VARCHAR(191) NOT NULL,
    `shop_id` VARCHAR(191) NOT NULL,
    `cash_session_id` VARCHAR(191) NOT NULL,
    `created_by_id` VARCHAR(191) NULL,
    `type` ENUM('OPENING', 'OPENING_EDIT', 'MANUAL_IN', 'MANUAL_OUT', 'CLOSING', 'REOPEN') NOT NULL,
    `source` VARCHAR(191) NULL,
    `note` TEXT NULL,
    `amount_delta` INT NULL,
    `counts_toward_expected_cash` BOOLEAN NOT NULL DEFAULT false,
    `resulting_expected_cash` INT NULL,
    `metadata` JSON NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    PRIMARY KEY (`id`),
    INDEX `cash_session_operations_shop_id_cash_session_id_created_at_idx`(`shop_id`, `cash_session_id`, `created_at`),
    INDEX `cash_session_operations_cash_session_id_created_at_idx`(`cash_session_id`, `created_at`),
    INDEX `cash_session_operations_created_by_id_idx`(`created_by_id`),
    CONSTRAINT `cash_session_operations_shop_id_fkey`
        FOREIGN KEY (`shop_id`) REFERENCES `shops`(`id`)
        ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT `cash_session_operations_cash_session_id_fkey`
        FOREIGN KEY (`cash_session_id`) REFERENCES `cash_sessions`(`id`)
        ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT `cash_session_operations_created_by_id_fkey`
        FOREIGN KEY (`created_by_id`) REFERENCES `shop_users`(`id`)
        ON DELETE SET NULL ON UPDATE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

