
# 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;

-- ---------------------------------------------------------------------
-- pdr_places
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `pdr_places`;

CREATE TABLE `pdr_places`
(
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(50) NOT NULL,
    `active` TINYINT DEFAULT 1 NOT NULL,
    `price` FLOAT DEFAULT 0 NOT NULL,
    `minimum_amount` FLOAT DEFAULT 0 NOT NULL,
    `latitude` DOUBLE,
    `longitude` DOUBLE,
    `address1` VARCHAR(255) NOT NULL,
    `address2` VARCHAR(255),
    `address3` VARCHAR(255),
    `zipcode` VARCHAR(10) NOT NULL,
    `city` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB;

-- ---------------------------------------------------------------------
-- pdr_schedule
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `pdr_schedule`;

CREATE TABLE `pdr_schedule`
(
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `id_place` INTEGER NOT NULL,
    `day` INTEGER NOT NULL,
    `begin_time` TIME NOT NULL,
    `end_time` TIME NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `fi_places_schedule` (`id_place`),
    CONSTRAINT `fk_places_schedule`
        FOREIGN KEY (`id_place`)
        REFERENCES `pdr_places` (`id`)
        ON DELETE CASCADE
) ENGINE=InnoDB;

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