
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

-- ---------------------------------------------------------------------
-- order_delivery_schedule
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `order_delivery_schedule`;

CREATE TABLE `order_delivery_schedule`
(
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `order_id` INTEGER,
    `delivery_address_id` INTEGER,
    `delivery_place_id` INTEGER,
    `schedule_id` INTEGER NOT NULL,
    `due_delivery_time_start` DATETIME NOT NULL,
    `due_delivery_time_end` DATETIME NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fi_order_delivery_schedule_order_id` (`order_id`),
    INDEX `fi_order_delivery_address_id` (`delivery_address_id`),
    INDEX `fi_order_delivery_place_id` (`delivery_place_id`),
    INDEX `fi_order_delivery_schedule_id` (`schedule_id`),
    CONSTRAINT `fk_order_delivery_schedule_order_id`
        FOREIGN KEY (`order_id`)
        REFERENCES `order` (`id`),
    CONSTRAINT `fk_order_delivery_address_id`
        FOREIGN KEY (`delivery_address_id`)
        REFERENCES `order_address` (`id`),
    CONSTRAINT `fk_order_delivery_place_id`
        FOREIGN KEY (`delivery_place_id`)
        REFERENCES `pdr_places` (`id`),
    CONSTRAINT `fk_order_delivery_schedule_id`
        FOREIGN KEY (`schedule_id`)
        REFERENCES `lps_area_schedule` (`id`)
) ENGINE=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
