-- DownloadManager - Script d'installation
-- PuzzleApp / Webemyos / Jérôme Oliva

CREATE TABLE IF NOT EXISTS `DmDocument` (
    `Id` int(11) NOT NULL AUTO_INCREMENT,
    `CategoryId` int(11) NULL,
    `Name` VARCHAR(200) NOT NULL,
    `Code` VARCHAR(200) NOT NULL,
    `Description` TEXT NULL,
    `FileType` VARCHAR(50) NULL,
    `FileSize` VARCHAR(50) NULL,
    `Status` INT NOT NULL DEFAULT 1,
    `DateCreated` DATE NOT NULL,
    PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET `utf8`;

CREATE TABLE IF NOT EXISTS `DmCategory` (
    `Id` int(11) NOT NULL AUTO_INCREMENT,
    `Name` VARCHAR(200) NOT NULL,
    `Code` VARCHAR(200) NOT NULL,
    `Description` TEXT NULL,
    PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET `utf8`;

CREATE TABLE IF NOT EXISTS `DmDownload` (
    `Id` int(11) NOT NULL AUTO_INCREMENT,
    `DocumentId` int(11) NOT NULL,
    `Email` VARCHAR(255) NOT NULL,
    `DateDownload` DATETIME NOT NULL,
    `IpAddress` VARCHAR(50) NULL,
    PRIMARY KEY (`Id`),
    CONSTRAINT `DmDocument_DmDownload` FOREIGN KEY (`DocumentId`) REFERENCES `DmDocument`(`Id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET `utf8`;
