-- ------------------------------------------
-- Table structure for table `deposits`
-- ------------------------------------------

DROP TABLE IF EXISTS `deposits`;

CREATE TABLE `deposits` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,

    -- User
    `user_id` BIGINT UNSIGNED NOT NULL,

    -- Deposit
    `amount` DECIMAL(12,2) NOT NULL DEFAULT 0.00,
    `pay_type` VARCHAR(50) NOT NULL,

    -- Order
    `out_trade_no` VARCHAR(120) NOT NULL,
    `transaction_id` VARCHAR(150) DEFAULT NULL,

    -- Gateway
    `gateway_url` TEXT DEFAULT NULL,

    -- Status
    `status` ENUM('pending','success','failed') NOT NULL DEFAULT 'pending',

    -- Full Callback JSON
    `callback_data` LONGTEXT DEFAULT NULL,

    -- Time
    `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

    PRIMARY KEY (`id`),

    UNIQUE KEY `deposits_out_trade_no_unique` (`out_trade_no`),

    KEY `deposits_user_id_index` (`user_id`),

    CONSTRAINT `deposits_user_id_foreign`
    FOREIGN KEY (`user_id`)
    REFERENCES `users`(`id`)
    ON DELETE CASCADE

) ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci;