# ---------------------------------------------------------------------- #
# Script generated with: DeZign for Databases V7.3.4                     #
# Target DBMS:           MySQL 5                                         #
# Project file:          abliaDbComuni3.dez                              #
# Project name:          DB COMUNI - ABLIA                               #
# Author:                Andrea Colzi                                    #
# Script type:           Database creation script                        #
# Created on:            2015-11-27 13:05                                #
# ---------------------------------------------------------------------- #


# ---------------------------------------------------------------------- #
# Tables                                                                 #
# ---------------------------------------------------------------------- #

# ---------------------------------------------------------------------- #
# Add table "LOG_MAIL"                                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE IF NOT EXISTS `LOG_MAIL` (
    `id_logMail` INTEGER NOT NULL AUTO_INCREMENT,
    `id_users` INTEGER,
 `oggetto` VARCHAR(254),
       `tsInvio` DATETIME,
    `lmTo` VARCHAR(60),
    `lmCc` VARCHAR(60),
    `lmBcc` VARCHAR(60),
    `testoMessaggio` TEXT,
    `result` VARCHAR(1000),
  `lastUpdTmst` TIMESTAMP,
    `lastUpdId_user` INTEGER,
    CONSTRAINT `PK_LOG_MAIL` PRIMARY KEY (`id_logMail`)
);

# ---------------------------------------------------------------------- #
# Add table "LOG_MAIL_ATTACH"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE IF NOT EXISTS `LOG_MAIL_ATTACH` (
    `id_logMailAttach` INTEGER NOT NULL AUTO_INCREMENT,
    `nomeFile` VARCHAR(254),
    `id_logMail` INTEGER,
  `lastUpdTmst` TIMESTAMP,
    `lastUpdId_user` INTEGER,
    CONSTRAINT `PK_LOG_MAIL_ATTACH` PRIMARY KEY (`id_logMailAttach`),
	CONSTRAINT `LOG_MAIL_LOG_MAIL_ATTACH` 
    FOREIGN KEY (`id_logMail`) REFERENCES `LOG_MAIL` (`id_logMail`)
);

#ALTER TABLE `LOG_MAIL_ATTACH` ADD CONSTRAINT `LOG_MAIL_LOG_MAIL_ATTACH` 
#    FOREIGN KEY (`id_logMail`) REFERENCES `LOG_MAIL` (`id_logMail`);



# ---------------------------------------------------------------------- #
# Add table "LOG"                                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE IF NOT EXISTS `LOG` (
    `id_log` INTEGER NOT NULL AUTO_INCREMENT,
    `id_users` INTEGER,
    `id_blacklist` INTEGER,
    `dataLog` DATE,
    `descrizione` text,
    `ipAddress` CHAR(60),
    `flgMovimento` INTEGER,
  `lastUpdTmst` TIMESTAMP,
    `lastUpdId_user` INTEGER,
    CONSTRAINT `PK_LOG` PRIMARY KEY (`id_log`)
);

# ---------------------------------------------------------------------- #
# Foreign key constraints                                                #
# ---------------------------------------------------------------------- #

#ALTER TABLE `LOG` ADD CONSTRAINT `USERS_LOG` 
#    FOREIGN KEY (`id_users`) REFERENCES `USERS` (`id_users`);

#ALTER TABLE `LOG` ADD CONSTRAINT `BLACKLIST_LOG` 
#    FOREIGN KEY (`id_blacklist`) REFERENCES `BLACKLIST` (`id_blacklist`);

