forked from ebhomengo/niki
1
0
Fork 0
niki/repository/mysql/migration/1705992494_create_kind_boxe...

36 lines
2.4 KiB
SQL

-- +migrate Up
CREATE TABLE `kind_boxes` (
`id` INT PRIMARY KEY AUTO_INCREMENT,
`kind_box_req_id` INT NOT NULL,
`benefactor_id` INT NOT NULL,
`type` ENUM('on-table','cylindrical','stand-up') NOT NULL,
`amount` INT UNSIGNED,
`serial_number` VARCHAR(191) UNIQUE,
`status` ENUM('delivered','ready-to-return','assigned-receiver-agent','returned','enumerated') NOT NULL,
`deliver_refer_time_id` INT NOT NULL,
`deliver_refer_date` DATETIME NOT NULL,
`deliver_address_id` INT NOT NULL,
`sender_agent_id` INT NOT NULL,
`delivered_at` DATETIME NOT NULL,
`return_refer_time_id` INT,
`return_refer_date` DATETIME,
`return_address_id` INT,
`receiver_agent_id` INT,
`returned_at` DATETIME,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` TIMESTAMP NULL,
FOREIGN KEY (`kind_box_req_id`) REFERENCES `kind_box_reqs` (`id`),
FOREIGN KEY (`benefactor_id`) REFERENCES `benefactors` (`id`),
FOREIGN KEY (`deliver_refer_time_id`) REFERENCES `refer_times` (`id`),
FOREIGN KEY (`deliver_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`sender_agent_id`) REFERENCES `admins` (`id`),
FOREIGN KEY (`return_refer_time_id`) REFERENCES `refer_times` (`id`),
FOREIGN KEY (`return_address_id`) REFERENCES `addresses` (`id`),
FOREIGN KEY (`receiver_agent_id`) REFERENCES `admins` (`id`),
INDEX `index_serial_number` (`serial_number`)
);
-- +migrate Down
DROP TABLE `kind_boxes`;