# ---------------------------------------------------------------------- #
# Script generated with: DeZign for Databases V7.3.1                     #
# Target DBMS:           MySQL 5                                         #
# Project file:          DISCO Shop Cms.dez                              #
# Project name:          Datenkraft DISCO 4.0 (CMS)                      #
# Author:                                                                #
# Script type:           Database creation script                        #
# Created on:            2015-05-07 13:47                                #
# ---------------------------------------------------------------------- #


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

# ---------------------------------------------------------------------- #
# Add table "Language"                                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `Language` (
    `Language_Code` VARCHAR(3) NOT NULL,
    `Language_Name` VARCHAR(255) NOT NULL,
    `Language_Charset` VARCHAR(32) NOT NULL DEFAULT 'UTF-8',
    `Language_Backend_Show` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Language_Frontend_Show` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Language_Backend_Image` VARCHAR(255),
    `Language_LC` VARCHAR(40),
    `Language_Order` INTEGER,
    CONSTRAINT `PK_Language` PRIMARY KEY (`Language_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Language_1` ON `Language` (`Language_Order`);

# ---------------------------------------------------------------------- #
# Add table "AuthorizationSubType"                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `AuthorizationSubType` (
    `AuthorizationSubType_Code` VARCHAR(32) NOT NULL,
    `AuthorizationSubType_Name` VARCHAR(255),
    CONSTRAINT `PK_AuthorizationSubType` PRIMARY KEY (`AuthorizationSubType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "Authorization"                                              #
# ---------------------------------------------------------------------- #

CREATE TABLE `Authorization` (
    `Authorization_Code` VARCHAR(32) NOT NULL,
    `Authorization_Type` ENUM('backoffice','frontend') NOT NULL DEFAULT 'backoffice',
    `AuthorizationSubType_Code` VARCHAR(32),
    `Authorization_Name` VARCHAR(255),
    CONSTRAINT `PK_Authorization` PRIMARY KEY (`Authorization_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `Authorization_AuthorizationSubType_Code` ON `Authorization` (`AuthorizationSubType_Code`);

# ---------------------------------------------------------------------- #
# Add table "Menu"                                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `Menu` (
    `Menu_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `Authorization_Code` VARCHAR(32) NOT NULL,
    `Menu_Code` VARCHAR(40),
    `Menu_Controller` VARCHAR(255) NOT NULL,
    `Menu_ID_Root` INTEGER(10) UNSIGNED NOT NULL,
    `Menu_Left` INTEGER(10) UNSIGNED NOT NULL,
    `Menu_Right` INTEGER(10) UNSIGNED NOT NULL,
    `Menu_Order` INTEGER(10) UNSIGNED NOT NULL,
    `Menu_Level` INTEGER(10) UNSIGNED NOT NULL,
    `Menu_Action` VARCHAR(250) NOT NULL,
    `Menu_Title` VARCHAR(255),
    `Menu_TitleCallback` VARCHAR(255),
    `Menu_Info` TEXT,
    `Menu_Icon` VARCHAR(255),
    `Menu_Show` ENUM('true','false') NOT NULL DEFAULT 'true',
    CONSTRAINT `PK_Menu` PRIMARY KEY (`Menu_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `Menu_Authorization_Code` ON `Menu` (`Authorization_Code`);

CREATE INDEX `Menu_ID_2` ON `Menu` (`Menu_Action`);

CREATE INDEX `IDX_Menu_3` ON `Menu` (`Menu_Controller`);

CREATE INDEX `IDX_Menu_4` ON `Menu` (`Menu_Left`);

CREATE INDEX `IDX_Menu_5` ON `Menu` (`Menu_Right`);

CREATE INDEX `IDX_Menu_6` ON `Menu` (`Menu_Order`);

CREATE INDEX `IDX_Menu_7` ON `Menu` (`Menu_Level`);

CREATE INDEX `IDX_Menu_8` ON `Menu` (`Menu_ID_Root`,`Menu_Left`,`Menu_Right`,`Menu_Level`);

CREATE UNIQUE INDEX `IDX_Menu_Code` ON `Menu` (`Menu_ID_Root`,`Menu_Code`);

# ---------------------------------------------------------------------- #
# Add table "MenuParameter"                                              #
# ---------------------------------------------------------------------- #

CREATE TABLE `MenuParameter` (
    `Menu_ID` INTEGER(10) UNSIGNED NOT NULL,
    `MenuParameter_Key` VARCHAR(255) NOT NULL,
    `MenuParameter_Value` VARCHAR(255),
    CONSTRAINT `PK_MenuParameter` PRIMARY KEY (`Menu_ID`, `MenuParameter_Key`)
)
ENGINE=InnoDB;

CREATE INDEX `ActionParameter_Menu_ID` ON `MenuParameter` (`Menu_ID`);

# ---------------------------------------------------------------------- #
# Add table "LTMTranslation"                                             #
# ---------------------------------------------------------------------- #

CREATE TABLE `LTMTranslation` (
    `Translation_Code` VARCHAR(255) NOT NULL,
    `Translation_Description` TEXT,
    `Translation_Internal` ENUM('true','false') DEFAULT 'false',
    CONSTRAINT `PK_LTMTranslation` PRIMARY KEY (`Translation_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "LTMTranslation_Language"                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `LTMTranslation_Language` (
    `Translation_Code` VARCHAR(255) NOT NULL,
    `Language_Code` VARCHAR(3) NOT NULL,
    `Translation_Text` TEXT,
    `Translation_UserEdit` ENUM('true','false') DEFAULT 'false',
    CONSTRAINT `PK_LTMTranslation_Language` PRIMARY KEY (`Translation_Code`, `Language_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_LTMTranslation_Language_1` ON `LTMTranslation_Language` (`Translation_Code`);

CREATE INDEX `IDX_LTMTranslation_Language_2` ON `LTMTranslation_Language` (`Language_Code`);

# ---------------------------------------------------------------------- #
# Add table "PersonGroupType"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `PersonGroupType` (
    `PersonGroupType_Code` VARCHAR(40) NOT NULL,
    `PersonGroupType_Name` VARCHAR(255),
    CONSTRAINT `PK_PersonGroupType` PRIMARY KEY (`PersonGroupType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "ArticleEntry"                                               #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntry` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `ArticleEntry_Date` DATE NOT NULL DEFAULT '0000-00-00 00:00:00',
    `ArticleEntry_Expire` DATE NOT NULL DEFAULT '0000-00-00 00:00:00',
    `ArticleEntry_Time` TIME,
    `ArticleEntry_Value` FLOAT,
    `ArticleEntry_Rating` INTEGER,
    `ArticleEntry_Rating_Count` INTEGER,
    `ArticleEntry_Template` VARCHAR(255),
    `__ArticleEntry_Title` VARCHAR(255) NOT NULL,
    `__ArticleEntry_Head` TEXT,
    `__ArticleEntry_Text` LONGTEXT,
    `__ArticleEntry_Appendix` VARCHAR(255),
    `__ArticleEntry_TextCode` VARCHAR(255),
    `__ArticleEntry_Show` ENUM('true','false') DEFAULT 'true',
    `__ArticleEntry_HTML` ENUM('true','false') DEFAULT 'false',
    `__ArticleEntry_Menu` VARCHAR(255),
    `__ArticleEntry_SiteTitle` VARCHAR(255),
    `__ArticleEntry_SiteDescription` VARCHAR(255),
    `__ArticleEntry_Keyword` VARCHAR(255),
    `__ArticleEntry_Additional` TEXT,
    `__ArticleEntry_ShowFrom` DATETIME,
    `__ArticleEntry_ShowTo` DATETIME,
    CONSTRAINT `PK_ArticleEntry` PRIMARY KEY (`ArticleEntry_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntry_1` ON `ArticleEntry` (`ArticleEntry_Date`);

CREATE INDEX `IDX_ArticleEntry_2` ON `ArticleEntry` (`ArticleEntry_Rating_Count`);

# ---------------------------------------------------------------------- #
# Add table "CMSArticleCategory"                                         #
# ---------------------------------------------------------------------- #

CREATE TABLE `CMSArticleCategory` (
    `CMSArticleCategory_Code` VARCHAR(32) NOT NULL,
    `CMSArticleCategory_Name` VARCHAR(255) NOT NULL,
    `CMSArticleCategory_CtrlAction` VARCHAR(40),
    CONSTRAINT `PK_CMSArticleCategory` PRIMARY KEY (`CMSArticleCategory_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "PictureFile_Type"                                           #
# ---------------------------------------------------------------------- #

CREATE TABLE `PictureFile_Type` (
    `PictureFileType_Code` VARCHAR(40) NOT NULL,
    `PictureFileType_Name` VARCHAR(255) NOT NULL,
    `PictureFileType_Height` INTEGER,
    `PictureFileType_Width` INTEGER,
    CONSTRAINT `PK_PictureFile_Type` PRIMARY KEY (`PictureFileType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "DocumentCategory"                                           #
# ---------------------------------------------------------------------- #

CREATE TABLE `DocumentCategory` (
    `DocumentCategory_Code` VARCHAR(40) NOT NULL,
    `DocumentCategory_FileExtensions` VARCHAR(255),
    `__DocumentCategory_Title` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_DocumentCategory` PRIMARY KEY (`DocumentCategory_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "PictureCategory"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `PictureCategory` (
    `PictureCategory_Code` VARCHAR(40) NOT NULL,
    `__PictureCategory_Title` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_PictureCategory` PRIMARY KEY (`PictureCategory_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "Currency"                                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `Currency` (
    `Currency_Code` VARCHAR(16) NOT NULL,
    `Currency_Shortcut` VARCHAR(16) NOT NULL,
    `Currency_Name` VARCHAR(255) NOT NULL,
    `Currency_ExchangeRate` DOUBLE NOT NULL DEFAULT 1.0,
    CONSTRAINT `PK_Currency` PRIMARY KEY (`Currency_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "VersionType"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `VersionType` (
    `VersionType_Code` VARCHAR(40) NOT NULL,
    `VersionType_Controller` VARCHAR(255),
    `VersionType_Name` VARCHAR(255) NOT NULL,
    `VersionType_DisplayField` VARCHAR(255),
    CONSTRAINT `PK_VersionType` PRIMARY KEY (`VersionType_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_VersionType_1` ON `VersionType` (`VersionType_Controller`);

# ---------------------------------------------------------------------- #
# Add table "VersionState"                                               #
# ---------------------------------------------------------------------- #

CREATE TABLE `VersionState` (
    `VersionState_Code` VARCHAR(40) NOT NULL,
    `VersionState_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_VersionState` PRIMARY KEY (`VersionState_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "CMSMapping"                                                 #
# ---------------------------------------------------------------------- #

CREATE TABLE `CMSMapping` (
    `CMSMapping_Code` VARCHAR(255) NOT NULL,
    `CMSMapping_Target` VARCHAR(255) NOT NULL,
    `CMSMapping_Internal` ENUM('true','false') DEFAULT 'true',
    CONSTRAINT `PK_CMSMapping` PRIMARY KEY (`CMSMapping_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "NewsletterGroup"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterGroup` (
    `NewsletterGroup_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterGroup_Order` INTEGER NOT NULL,
    `NewsletterGroup_Show` ENUM('true','false') NOT NULL DEFAULT 'false',
    `NewsletterGroup_Name` VARCHAR(255) NOT NULL,
    `__NewsletterGroup_Title` VARCHAR(255),
    `__NewsletterGroup_Description` TEXT,
    CONSTRAINT `PK_NewsletterGroup` PRIMARY KEY (`NewsletterGroup_ID`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "NewsletterState"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterState` (
    `NewsletterState_Code` VARCHAR(40) NOT NULL,
    `NewsletterState_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_NewsletterState` PRIMARY KEY (`NewsletterState_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "NewsletterType"                                             #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterType` (
    `NewsletterType_Code` VARCHAR(40) NOT NULL,
    `NewsletterGroup_ID` INTEGER,
    `NewsletterType_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_NewsletterType` PRIMARY KEY (`NewsletterType_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_NewsletterType_1` ON `NewsletterType` (`NewsletterGroup_ID`);

# ---------------------------------------------------------------------- #
# Add table "NewsletterInstance"                                         #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterInstance` (
    `NewsletterInstance_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterInstance_Info` TEXT,
    CONSTRAINT `PK_NewsletterInstance` PRIMARY KEY (`NewsletterInstance_ID`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "NewsletterRecipientImport"                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterRecipientImport` (
    `NewsletterRecipientImport_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterRecipientImport_Name` VARCHAR(255),
    CONSTRAINT `PK_NewsletterRecipientImport` PRIMARY KEY (`NewsletterRecipientImport_ID`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "ContactType"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `ContactType` (
    `ContactType_Code` VARCHAR(40) NOT NULL,
    `ContactType_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_ContactType` PRIMARY KEY (`ContactType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "LinkCategory"                                               #
# ---------------------------------------------------------------------- #

CREATE TABLE `LinkCategory` (
    `LinkCategory_Code` VARCHAR(40) NOT NULL,
    `__LinkCategory_Title` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_LinkCategory` PRIMARY KEY (`LinkCategory_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "FieldDefinitionType"                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldDefinitionType` (
    `FieldDefinitionType_Code` VARCHAR(40) NOT NULL,
    `FieldDefinitionType_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_FieldDefinitionType` PRIMARY KEY (`FieldDefinitionType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "FieldDefinitionDatatype"                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldDefinitionDatatype` (
    `FieldDefinitionDatatype_Code` VARCHAR(40) NOT NULL,
    `FieldDefinitionDatatype_Name` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_FieldDefinitionDatatype` PRIMARY KEY (`FieldDefinitionDatatype_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "MapLocationCategory"                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `MapLocationCategory` (
    `MapLocationCategory_Code` VARCHAR(40) NOT NULL,
    `__MapLocationCategory_Title` VARCHAR(255) NOT NULL,
    CONSTRAINT `PK_MapLocationCategory` PRIMARY KEY (`MapLocationCategory_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "QueueState"                                                 #
# ---------------------------------------------------------------------- #

CREATE TABLE `QueueState` (
    `QueueState_Code` VARCHAR(40) NOT NULL,
    `QueueState_Name` VARCHAR(255),
    CONSTRAINT `PK_QueueState` PRIMARY KEY (`QueueState_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "QueueType"                                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `QueueType` (
    `QueueType_Code` VARCHAR(40) NOT NULL,
    `QueueType_Title` VARCHAR(255),
    CONSTRAINT `PK_QueueType` PRIMARY KEY (`QueueType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "NewsletterFilter"                                           #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterFilter` (
    `NewsletterFilter_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterFilter_Order` INTEGER,
    `NewsletterFilter_Name` VARCHAR(255),
    `NewsletterFilter_Active` ENUM('true','false') DEFAULT 'false',
    `NewsletterFilter_SQL` TEXT,
    CONSTRAINT `PK_NewsletterFilter` PRIMARY KEY (`NewsletterFilter_ID`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "Rating"                                                     #
# ---------------------------------------------------------------------- #

CREATE TABLE `Rating` (
    `Rating_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `ArticleEntry_ID` INTEGER(10) UNSIGNED,
    `Rating_Value` INTEGER,
    `Rating_Title` VARCHAR(255),
    `Rating_Text` TEXT,
    `Rating_IP` VARCHAR(40),
    `Rating_UserAgent` VARCHAR(255),
    CONSTRAINT `PK_Rating` PRIMARY KEY (`Rating_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Rating_1` ON `Rating` (`ArticleEntry_ID`);

# ---------------------------------------------------------------------- #
# Add table "ArticleEntryDateTimeType"                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntryDateTimeType` (
    `ArticleEntryDateTimeType_Code` VARCHAR(40) NOT NULL,
    `ArticleEntryDateTimeType_Name` VARCHAR(255),
    CONSTRAINT `PK_ArticleEntryDateTimeType` PRIMARY KEY (`ArticleEntryDateTimeType_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "CountryZone"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `CountryZone` (
    `CountryZone_Code` VARCHAR(64) NOT NULL,
    `CountryZone_Name` VARCHAR(255),
    CONSTRAINT `PK_CountryZone` PRIMARY KEY (`CountryZone_Code`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "Sms"                                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `Sms` (
    `Sms_ID` INTEGER(11) NOT NULL AUTO_INCREMENT,
    `Sms_MessageID` VARCHAR(255) NOT NULL,
    `Sms_Servicename` VARCHAR(255) NOT NULL,
    `Sms_Recipient` VARCHAR(255),
    `Sms_SentText` VARCHAR(255),
    `Sms_EventName` VARCHAR(40),
    `Sms_SendDateTime` DATETIME,
    `Sms_SentDateTime` DATETIME,
    `Sms_SentStatus` VARCHAR(40),
    `Sms_ErrorCount` INTEGER(3) UNSIGNED DEFAULT 0,
    `Sms_ResponseText` VARCHAR(255),
    `Sms_Responder` VARCHAR(255),
    `Sms_ResponseDateTime` DATETIME,
    `Sms_ResponseValidUntil` DATETIME,
    CONSTRAINT `PK_Sms` PRIMARY KEY (`Sms_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Sms_1` ON `Sms` (`Sms_MessageID`,`Sms_Servicename`);

# ---------------------------------------------------------------------- #
# Add table "PersonGroup"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `PersonGroup` (
    `PersonGroup_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `PersonGroupType_Code` VARCHAR(40),
    `PersonGroup_Name` VARCHAR(255),
    `PersonGroup_Table` VARCHAR(255),
    `PersonGroup_Shortcut` VARCHAR(12),
    CONSTRAINT `PK_PersonGroup` PRIMARY KEY (`PersonGroup_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_PersonGroup_1` ON `PersonGroup` (`PersonGroupType_Code`);

# ---------------------------------------------------------------------- #
# Add table "Person"                                                     #
# ---------------------------------------------------------------------- #

CREATE TABLE `Person` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `PersonGroup_ID` INTEGER(10) UNSIGNED ZEROFILL,
    `Person_Code` VARCHAR(32) NOT NULL,
    `Person_Sex` ENUM('male','female','unknown') NOT NULL DEFAULT 'unknown',
    `Person_Title` VARCHAR(100),
    `Person_Lastname` VARCHAR(255),
    `Person_Firstname` VARCHAR(255),
    `Person_Email` VARCHAR(255),
    CONSTRAINT `PK_Person` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

CREATE UNIQUE INDEX `IDX_Person_Code` ON `Person` (`Person_Code`);

CREATE INDEX `IDX_Person_2` ON `Person` (`PersonGroup_ID`);

CREATE INDEX `IDX_Person_3` ON `Person` (`Person_Lastname`);

# ---------------------------------------------------------------------- #
# Add table "Country"                                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `Country` (
    `Country_Code` CHAR(2) NOT NULL,
    `Currency_Code` VARCHAR(16),
    `Language_Code_Default` VARCHAR(3) NOT NULL,
    `Country_Code_Alpha_3` CHAR(3) NOT NULL,
    `Country_Code_Numeric` INTEGER,
    `Country_Code_TLD` VARCHAR(10) NOT NULL,
    `Country_Code_IOC` VARCHAR(10) NOT NULL,
    `Country_EUMember` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Country_Show` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Country_Name` VARCHAR(255),
    CONSTRAINT `PK_Country` PRIMARY KEY (`Country_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `Country_Language_Code_Default` ON `Country` (`Language_Code_Default`);

CREATE INDEX `IDX_Country_2` ON `Country` (`Currency_Code`);

# ---------------------------------------------------------------------- #
# Add table "Worker"                                                     #
# ---------------------------------------------------------------------- #

CREATE TABLE `Worker` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Language_Code` VARCHAR(3),
    `Worker_Username` VARCHAR(64) NOT NULL,
    `Worker_Password` VARCHAR(32) NOT NULL,
    `Worker_Active` ENUM('true','false') NOT NULL DEFAULT 'false',
    CONSTRAINT `PK_Worker` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Worker_Username` ON `Worker` (`Worker_Username`);

CREATE UNIQUE INDEX `IDX_Worker_Username_Unique` ON `Worker` (`Worker_Username`);

CREATE INDEX `IDX_Worker_3` ON `Worker` (`Language_Code`);

# ---------------------------------------------------------------------- #
# Add table "Person_Authorization"                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `Person_Authorization` (
    `Authorization_Code` VARCHAR(32) NOT NULL,
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Person_Authorization_Access` ENUM('true','false') NOT NULL DEFAULT 'false',
    CONSTRAINT `PK_Person_Authorization` PRIMARY KEY (`Authorization_Code`, `Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Person_Authorization_1` ON `Person_Authorization` (`Authorization_Code`);

CREATE INDEX `IDX_Person_Authorization_2` ON `Person_Authorization` (`Person_ID`);

# ---------------------------------------------------------------------- #
# Add table "PersonGroup_Authorization"                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `PersonGroup_Authorization` (
    `Authorization_Code` VARCHAR(32) NOT NULL,
    `PersonGroup_ID` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_PersonGroup_Authorization` PRIMARY KEY (`Authorization_Code`, `PersonGroup_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `PersonGroup_Authorization_PersonGroup_ID` ON `PersonGroup_Authorization` (`PersonGroup_ID`);

CREATE INDEX `IDX_PersonGroup_Authorization_2` ON `PersonGroup_Authorization` (`Authorization_Code`);

# ---------------------------------------------------------------------- #
# Add table "Link"                                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `Link` (
    `Link_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `LinkCategory_Code` VARCHAR(40),
    `Link_Url` VARCHAR(255) NOT NULL,
    `__Link_Title` VARCHAR(255) NOT NULL,
    `__Link_Description` TEXT,
    `__Link_Show` ENUM('true','false') DEFAULT 'true',
    `Link_Target` ENUM('_blank','_self','_parent') NOT NULL,
    CONSTRAINT `PK_Link` PRIMARY KEY (`Link_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Link_1` ON `Link` (`LinkCategory_Code`);

# ---------------------------------------------------------------------- #
# Add table "Picture"                                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `Picture` (
    `Picture_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `PictureCategory_Code` VARCHAR(40),
    `Picture_Symbolic` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Picture_XRated` ENUM('true','false') NOT NULL DEFAULT 'false',
    `__Picture_Title` VARCHAR(255) NOT NULL,
    `__Picture_Description` TEXT,
    `__Picture_Show` ENUM('true','false') DEFAULT 'true',
    `__Picture_Link` VARCHAR(255),
    `__Picture_Copyright` VARCHAR(255),
    CONSTRAINT `PK_Picture` PRIMARY KEY (`Picture_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Picture_1` ON `Picture` (`PictureCategory_Code`);

# ---------------------------------------------------------------------- #
# Add table "PictureFile"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `PictureFile` (
    `PictureFile_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `Picture_ID` INTEGER(10) UNSIGNED NOT NULL,
    `PictureFileType_Code` VARCHAR(40) NOT NULL,
    `PictureFile_Width` INTEGER UNSIGNED NOT NULL,
    `PictureFile_Height` INTEGER UNSIGNED NOT NULL,
    `PictureFile_Filename` VARCHAR(255) NOT NULL,
    `PictureFile_CroppedX1` INTEGER UNSIGNED,
    `PictureFile_CroppedY1` INTEGER UNSIGNED,
    `PictureFile_CroppedX2` INTEGER UNSIGNED,
    `PictureFile_CroppedY2` INTEGER UNSIGNED,
    CONSTRAINT `PK_PictureFile` PRIMARY KEY (`PictureFile_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_PictureFile_1` ON `PictureFile` (`Picture_ID`);

CREATE INDEX `IDX_PictureFile_2` ON `PictureFile` (`PictureFileType_Code`);

# ---------------------------------------------------------------------- #
# Add table "Version"                                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `Version` (
    `Version_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `VersionType_Code` VARCHAR(40) NOT NULL,
    `Language_Code` VARCHAR(3),
    `VersionState_Code` VARCHAR(40) NOT NULL,
    `Person_ID` INTEGER(10) UNSIGNED,
    `Version_Datetime` DATETIME,
    `Version_ParentID` VARCHAR(255),
    `Version_ViewID` VARCHAR(255),
    `Version_TableName` VARCHAR(255),
    `Version_Data` TEXT,
    `Version_View` VARCHAR(255),
    `Version_View_Detail` VARCHAR(255),
    `Version_View_Preview` VARCHAR(255),
    CONSTRAINT `PK_Version` PRIMARY KEY (`Version_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Version_1` ON `Version` (`VersionType_Code`);

CREATE INDEX `IDX_Version_2` ON `Version` (`Language_Code`);

CREATE INDEX `IDX_Version_3` ON `Version` (`VersionState_Code`);

CREATE INDEX `IDX_Version_4` ON `Version` (`Person_ID`);

# ---------------------------------------------------------------------- #
# Add table "Contact"                                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `Contact` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ContactType_Code` VARCHAR(40) NOT NULL,
    `Contact_Subject` VARCHAR(255),
    `Contact_Datetime` DATETIME,
    `Contact_Formdata` TEXT,
    `Contact_Email` LONGTEXT,
    CONSTRAINT `PK_Contact` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Contact_1` ON `Contact` (`ContactType_Code`);

# ---------------------------------------------------------------------- #
# Add table "Language_Person"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `Language_Person` (
    `Language_Code` VARCHAR(3) NOT NULL,
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_Language_Person` PRIMARY KEY (`Language_Code`, `Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Language_Person_1` ON `Language_Person` (`Language_Code`);

CREATE INDEX `IDX_Language_Person_2` ON `Language_Person` (`Person_ID`);

# ---------------------------------------------------------------------- #
# Add table "NewsletterRecipient"                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterRecipient` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Language_Code` VARCHAR(3) NOT NULL,
    `NewsletterRecipientImport_ID` INTEGER,
    `NewsletterRecipient_Active` ENUM('true','false') NOT NULL DEFAULT 'false',
    `NewsletterRecipient_Info` VARCHAR(255),
    `NewsletterRecipient_PrivateSalutation` ENUM('true','false') DEFAULT 'false',
    `NewsletterRecipient_ImportConflict` INTEGER,
    CONSTRAINT `PK_NewsletterRecipient` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_NewsletterRecipient_1` ON `NewsletterRecipient` (`Language_Code`);

CREATE INDEX `IDX_NewsletterRecipient_2` ON `NewsletterRecipient` (`NewsletterRecipientImport_ID`);

# ---------------------------------------------------------------------- #
# Add table "Newsletter"                                                 #
# ---------------------------------------------------------------------- #

CREATE TABLE `Newsletter` (
    `Newsletter_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterState_Code` VARCHAR(40) NOT NULL,
    `NewsletterType_Code` VARCHAR(40) NOT NULL,
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Newsletter_TXTTemplate` VARCHAR(255),
    `Newsletter_HTMLTemplate` VARCHAR(255),
    CONSTRAINT `PK_Newsletter` PRIMARY KEY (`Newsletter_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Newsletter_1` ON `Newsletter` (`NewsletterState_Code`);

CREATE INDEX `IDX_Newsletter_2` ON `Newsletter` (`ArticleEntry_ID`);

CREATE INDEX `IDX_Newsletter_3` ON `Newsletter` (`NewsletterType_Code`);

# ---------------------------------------------------------------------- #
# Add table "NewsletterGroup_NewsletterRecipient"                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterGroup_NewsletterRecipient` (
    `NewsletterGroup_ID` INTEGER NOT NULL,
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_NewsletterGroup_NewsletterRecipient` PRIMARY KEY (`NewsletterGroup_ID`, `Person_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_NewsletterGroup_NewsletterRecipient_1` ON `NewsletterGroup_NewsletterRecipient` (`NewsletterGroup_ID`);

CREATE INDEX `IDX_NewsletterGroup_NewsletterRecipient_2` ON `NewsletterGroup_NewsletterRecipient` (`Person_ID`);

# ---------------------------------------------------------------------- #
# Add table "NewsletterQueue"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterQueue` (
    `NewsletterQueue_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Newsletter_ID` INTEGER NOT NULL,
    `NewsletterInstance_ID` INTEGER,
    `Language_Code` VARCHAR(3) NOT NULL,
    `NewsletterQueue_Send` ENUM('true','false') NOT NULL DEFAULT 'false',
    `NewsletterQueue_Tries` INTEGER NOT NULL DEFAULT 0,
    `NewsletterQueue_Hit` DATETIME,
    `NewsletterQueue_BounceBack` ENUM('true','false') NOT NULL DEFAULT 'false',
    CONSTRAINT `PK_NewsletterQueue` PRIMARY KEY (`NewsletterQueue_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_NewsletterQueue_1` ON `NewsletterQueue` (`Person_ID`);

CREATE INDEX `IDX_NewsletterQueue_2` ON `NewsletterQueue` (`Newsletter_ID`);

CREATE INDEX `IDX_NewsletterQueue_3` ON `NewsletterQueue` (`Language_Code`);

CREATE INDEX `IDX_NewsletterQueue_4` ON `NewsletterQueue` (`NewsletterInstance_ID`);

CREATE UNIQUE INDEX `IDX_NewsletterQueue_5` ON `NewsletterQueue` (`NewsletterInstance_ID`,`Newsletter_ID`,`Person_ID`);

# ---------------------------------------------------------------------- #
# Add table "Newsletter_ArticleEntry"                                    #
# ---------------------------------------------------------------------- #

CREATE TABLE `Newsletter_ArticleEntry` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Newsletter_ID` INTEGER NOT NULL,
    CONSTRAINT `PK_Newsletter_ArticleEntry` PRIMARY KEY (`ArticleEntry_ID`, `Newsletter_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Newsletter_ArticleEntry_1` ON `Newsletter_ArticleEntry` (`ArticleEntry_ID`);

CREATE INDEX `IDX_Newsletter_ArticleEntry_2` ON `Newsletter_ArticleEntry` (`Newsletter_ID`);

# ---------------------------------------------------------------------- #
# Add table "Customer"                                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `Customer` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Language_Code` VARCHAR(3),
    `Country_Code` CHAR(2),
    `Customer_Username` VARCHAR(255),
    `Customer_Password` VARCHAR(64),
    `Customer_Active` ENUM('true','false') DEFAULT 'false',
    `Customer_Number` VARCHAR(64),
    `Customer_Company` VARCHAR(255),
    `Customer_IsCompany` ENUM('true','false') DEFAULT 'false',
    `Customer_Street` VARCHAR(255),
    `Customer_ZIPCode` VARCHAR(10),
    `Customer_City` VARCHAR(255),
    `Customer_Phone` VARCHAR(255),
    `Customer_Fax` VARCHAR(255),
    `Customer_UID` VARCHAR(255),
    `Customer_Birthday` DATE,
    `Customer_AccountNumber` VARCHAR(255),
    `Customer_AccountName` VARCHAR(255),
    `Customer_Info` TEXT,
    `Customer_Import` VARCHAR(255),
    CONSTRAINT `PK_Customer` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

CREATE UNIQUE INDEX `IDX_Customer_1` ON `Customer` (`Customer_Username`,`Customer_Password`);

CREATE UNIQUE INDEX `IDX_Customer_2` ON `Customer` (`Customer_Number`);

CREATE INDEX `IDX_Customer_3` ON `Customer` (`Country_Code`);

CREATE INDEX `IDX_Customer_4` ON `Customer` (`Language_Code`);

# ---------------------------------------------------------------------- #
# Add table "FieldDefinition"                                            #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldDefinition` (
    `FieldDefinition_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `FieldDefinitionDatatype_Code` VARCHAR(40) NOT NULL,
    `FieldDefinitionType_Code` VARCHAR(40) NOT NULL,
    `FieldDefinition_Code` VARCHAR(128),
    `FieldDefinition_Order` INTEGER NOT NULL,
    `FieldDefinition_Name` VARCHAR(255) NOT NULL,
    `__FieldDefinition_Title` VARCHAR(40),
    `FieldDefinition_ActiveFrontend` ENUM('true','false') DEFAULT 'true',
    `FieldDefinition_ActiveBackend` ENUM('true','false') DEFAULT 'true',
    `FieldDefinition_Default` VARCHAR(255),
    CONSTRAINT `PK_FieldDefinition` PRIMARY KEY (`FieldDefinition_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_FieldDefinition_1` ON `FieldDefinition` (`FieldDefinitionDatatype_Code`);

CREATE INDEX `IDX_FieldDefinition_2` ON `FieldDefinition` (`FieldDefinitionType_Code`);

CREATE UNIQUE INDEX `IDX_FieldDefinition_3` ON `FieldDefinition` (`FieldDefinition_Code`,`FieldDefinitionDatatype_Code`);

CREATE INDEX `IDX_FieldDefinition_4` ON `FieldDefinition` (`FieldDefinition_Order`);

CREATE INDEX `IDX_FieldDefinition_5` ON `FieldDefinition` (`FieldDefinitionType_Code`,`FieldDefinition_Order`);

# ---------------------------------------------------------------------- #
# Add table "FieldData"                                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldData` (
    `FieldData_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `FieldDefinition_ID` INTEGER NOT NULL,
    `ArticleEntry_ID` INTEGER(10) UNSIGNED,
    `__FieldData_MLString` VARCHAR(255),
    `__FieldData_MLText` TEXT,
    `FieldData_String` VARCHAR(255),
    `FieldData_Text` TEXT,
    `FieldData_Int` INTEGER,
    `FieldData_Float` FLOAT,
    `FieldData_Boolean` ENUM('true','false') DEFAULT 'true',
    `FieldData_Date` DATE,
    `FieldData_DateTime` DATETIME,
    CONSTRAINT `PK_FieldData` PRIMARY KEY (`FieldData_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_FieldData_1` ON `FieldData` (`FieldDefinition_ID`);

CREATE INDEX `IDX_FieldData_2` ON `FieldData` (`ArticleEntry_ID`);

# ---------------------------------------------------------------------- #
# Add table "NewsletterClickJournal"                                     #
# ---------------------------------------------------------------------- #

CREATE TABLE `NewsletterClickJournal` (
    `NewsletterClickJournal_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `NewsletterQueue_ID` INTEGER NOT NULL,
    `NewsletterClickJournal_Link` VARCHAR(255),
    CONSTRAINT `PK_NewsletterClickJournal` PRIMARY KEY (`NewsletterClickJournal_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_NewsletterClickJournal_1` ON `NewsletterClickJournal` (`NewsletterQueue_ID`);

# ---------------------------------------------------------------------- #
# Add table "MapLocation"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `MapLocation` (
    `MapLocation_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `MapLocationCategory_Code` VARCHAR(40),
    `MapLocation_Latitude` DOUBLE NOT NULL,
    `MapLocation_Longitude` DOUBLE NOT NULL,
    `MapLocation_RoutingDestination` ENUM('true','false') NOT NULL DEFAULT 'true',
    `__MapLocation_Title` VARCHAR(255),
    `__MapLocation_ToolTip` VARCHAR(255),
    `__MapLocation_Text` TEXT,
    `__MapLocation_Show` ENUM('true','false') NOT NULL DEFAULT 'true',
    `__MapLocation_Street` VARCHAR(255),
    `__MapLocation_ZIPCode` VARCHAR(255),
    `__MapLocation_City` VARCHAR(255),
    CONSTRAINT `PK_MapLocation` PRIMARY KEY (`MapLocation_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_MapLocation_1` ON `MapLocation` (`MapLocationCategory_Code`);

# ---------------------------------------------------------------------- #
# Add table "Queue"                                                      #
# ---------------------------------------------------------------------- #

CREATE TABLE `Queue` (
    `Queue_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `QueueType_Code` VARCHAR(40) NOT NULL,
    `QueueState_Code` VARCHAR(40),
    `Queue_Title` VARCHAR(255) NOT NULL,
    `Queue_Action` VARCHAR(255) NOT NULL,
    `Queue_Priority` TINYINT UNSIGNED NOT NULL DEFAULT 20,
    `Queue_Lock` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Queue_Active` ENUM('true','false') NOT NULL DEFAULT 'false',
    `Queue_Date` DATETIME,
    CONSTRAINT `PK_Queue` PRIMARY KEY (`Queue_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Queue_1` ON `Queue` (`QueueState_Code`);

CREATE INDEX `IDX_Queue_2` ON `Queue` (`QueueType_Code`);

CREATE UNIQUE INDEX `IDX_Queue_3` ON `Queue` (`Queue_Action`);

# ---------------------------------------------------------------------- #
# Add table "QueueData"                                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `QueueData` (
    `QueueData_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Queue_ID` INTEGER NOT NULL,
    `QueueData_Source` LONGTEXT,
    `QueueData_Target` LONGTEXT,
    `QueueData_Done` ENUM('true','false') DEFAULT 'false',
    CONSTRAINT `PK_QueueData` PRIMARY KEY (`QueueData_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_QueueData_1` ON `QueueData` (`Queue_ID`);

# ---------------------------------------------------------------------- #
# Add table "ArticleEntryDateTime"                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntryDateTime` (
    `ArticleEntryDateTime_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `ArticleEntry_ID` INTEGER(10) UNSIGNED,
    `ArticleEntryDateTimeType_Code` VARCHAR(40),
    `ArticleEntryDateTime_Main` ENUM('true','false') DEFAULT 'false',
    `ArticleEntryDateTime_Active` ENUM('true','false') DEFAULT 'false',
    `ArticleEntryDateTime_DateFrom` DATE,
    `ArticleEntryDateTime_DateTo` DATE,
    `ArticleEntryDateTime_TimeFrom` TIME,
    `ArticleEntryDateTime_TimeTo` TIME,
    CONSTRAINT `PK_ArticleEntryDateTime` PRIMARY KEY (`ArticleEntryDateTime_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntryDateTime_1` ON `ArticleEntryDateTime` (`ArticleEntry_ID`);

CREATE INDEX `IDX_ArticleEntryDateTime_2` ON `ArticleEntryDateTime` (`ArticleEntryDateTime_DateFrom`,`ArticleEntryDateTime_DateTo`);

CREATE INDEX `IDX_ArticleEntryDateTime_3` ON `ArticleEntryDateTime` (`ArticleEntryDateTime_DateFrom`,`ArticleEntry_ID`,`ArticleEntryDateTime_DateTo`);

CREATE INDEX `IDX_ArticleEntryDateTime_4` ON `ArticleEntryDateTime` (`ArticleEntryDateTimeType_Code`);

# ---------------------------------------------------------------------- #
# Add table "CountryZone_Country"                                        #
# ---------------------------------------------------------------------- #

CREATE TABLE `CountryZone_Country` (
    `CountryZone_Code` VARCHAR(64) NOT NULL,
    `Country_Code` CHAR(2) NOT NULL,
    CONSTRAINT `PK_CountryZone_Country` PRIMARY KEY (`CountryZone_Code`, `Country_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_CountryZone_Country_1` ON `CountryZone_Country` (`CountryZone_Code`);

CREATE INDEX `IDX_CountryZone_Country_2` ON `CountryZone_Country` (`Country_Code`);

# ---------------------------------------------------------------------- #
# Add table "Clipboard"                                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `Clipboard` (
    `Person_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Clipboard_Data` TEXT NOT NULL,
    CONSTRAINT `PK_Clipboard` PRIMARY KEY (`Person_ID`)
)
ENGINE=InnoDB;

# ---------------------------------------------------------------------- #
# Add table "ArticleEntry_Link"                                          #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntry_Link` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Link_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ArticleEntry_Link_Order` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_ArticleEntry_Link` PRIMARY KEY (`ArticleEntry_ID`, `Link_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntry_Link_1` ON `ArticleEntry_Link` (`ArticleEntry_ID`);

CREATE INDEX `IDX_ArticleEntry_Link_2` ON `ArticleEntry_Link` (`Link_ID`);

CREATE INDEX `IDX_ArticleEntry_Link_3` ON `ArticleEntry_Link` (`ArticleEntry_Link_Order`);

CREATE INDEX `IDX_ArticleEntry_Link_4` ON `ArticleEntry_Link` (`ArticleEntry_ID`,`ArticleEntry_Link_Order`);

# ---------------------------------------------------------------------- #
# Add table "ArticleEntry_Picture"                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntry_Picture` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Picture_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ArticleEntry_Picture_Order` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_ArticleEntry_Picture` PRIMARY KEY (`ArticleEntry_ID`, `Picture_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntry_Picture_1` ON `ArticleEntry_Picture` (`ArticleEntry_ID`);

CREATE INDEX `IDX_ArticleEntry_Picture_2` ON `ArticleEntry_Picture` (`Picture_ID`);

CREATE INDEX `IDX_ArticleEntry_Picture_3` ON `ArticleEntry_Picture` (`ArticleEntry_Picture_Order`);

CREATE INDEX `IDX_ArticleEntry_Picture_4` ON `ArticleEntry_Picture` (`ArticleEntry_ID`,`ArticleEntry_Picture_Order`);

# ---------------------------------------------------------------------- #
# Add table "Document"                                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `Document` (
    `Document_ID` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `DocumentCategory_Code` VARCHAR(40),
    `Picture_ID` INTEGER(10) UNSIGNED,
    `Document_Name` VARCHAR(255) NOT NULL,
    `__Document_Title` VARCHAR(255) NOT NULL,
    `__Document_Description` TEXT,
    `__Document_Show` ENUM('true','false') DEFAULT 'true',
    `Document_Size` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_Document` PRIMARY KEY (`Document_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_Document_1` ON `Document` (`DocumentCategory_Code`);

CREATE INDEX `IDX_Document_2` ON `Document` (`Picture_ID`);

# ---------------------------------------------------------------------- #
# Add table "ArticleEntry_MapLocation"                                   #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntry_MapLocation` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `MapLocation_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ArticleEntry_MapLocation_Order` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_ArticleEntry_MapLocation` PRIMARY KEY (`ArticleEntry_ID`, `MapLocation_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntry_MapLocation_1` ON `ArticleEntry_MapLocation` (`ArticleEntry_ID`);

CREATE INDEX `IDX_ArticleEntry_MapLocation_2` ON `ArticleEntry_MapLocation` (`MapLocation_ID`);

CREATE INDEX `IDX_ArticleEntry_MapLocation_3` ON `ArticleEntry_MapLocation` (`ArticleEntry_MapLocation_Order`);

CREATE INDEX `IDX_ArticleEntry_MapLocation_4` ON `ArticleEntry_MapLocation` (`ArticleEntry_ID`,`ArticleEntry_MapLocation_Order`);

# ---------------------------------------------------------------------- #
# Add table "ArticleEntry_Document"                                      #
# ---------------------------------------------------------------------- #

CREATE TABLE `ArticleEntry_Document` (
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `Document_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ArticleEntry_Document_Order` INTEGER(10) UNSIGNED NOT NULL,
    CONSTRAINT `PK_ArticleEntry_Document` PRIMARY KEY (`ArticleEntry_ID`, `Document_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_ArticleEntry_Document_1` ON `ArticleEntry_Document` (`ArticleEntry_ID`);

CREATE INDEX `IDX_ArticleEntry_Document_2` ON `ArticleEntry_Document` (`Document_ID`);

CREATE INDEX `IDX_ArticleEntry_Document_3` ON `ArticleEntry_Document` (`ArticleEntry_Document_Order`);

CREATE INDEX `IDX_ArticleEntry_Document_4` ON `ArticleEntry_Document` (`ArticleEntry_ID`,`ArticleEntry_Document_Order`);

# ---------------------------------------------------------------------- #
# Add table "CMSArticle"                                                 #
# ---------------------------------------------------------------------- #

CREATE TABLE `CMSArticle` (
    `CMSArticle_ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    `CMSArticleCategory_Code` VARCHAR(32) NOT NULL,
    `ArticleEntry_ID` INTEGER(10) UNSIGNED NOT NULL,
    `ArticleEntry_ID_Parent` INTEGER(10) UNSIGNED,
    `Language_Code` VARCHAR(3),
    `CMSArticle_ID_Copy` INTEGER UNSIGNED,
    `Person_ID` INTEGER(10) UNSIGNED,
    `CMSArticle_Code` VARCHAR(64),
    `CMSArticle_Order` INTEGER,
    `CMSArticle_Linked` ENUM('true','false') DEFAULT 'false',
    CONSTRAINT `PK_CMSArticle` PRIMARY KEY (`CMSArticle_ID`),
    CONSTRAINT `TUC_CMSArticle_1` UNIQUE (`CMSArticle_Code`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_CMSArticle_1` ON `CMSArticle` (`ArticleEntry_ID`);

CREATE INDEX `IDX_CMSArticle_2` ON `CMSArticle` (`CMSArticleCategory_Code`);

CREATE INDEX `IDX_CMSArticle_3` ON `CMSArticle` (`Language_Code`);

CREATE INDEX `IDX_CMSArticle_4` ON `CMSArticle` (`Person_ID`);

CREATE INDEX `IDX_CMSArticle_5` ON `CMSArticle` (`CMSArticle_Code`);

CREATE INDEX `IDX_CMSArticle_6` ON `CMSArticle` (`ArticleEntry_ID_Parent`);

CREATE INDEX `IDX_CMSArticle_7` ON `CMSArticle` (`CMSArticle_ID_Copy`);

CREATE INDEX `IDX_CMSArticle_8` ON `CMSArticle` (`CMSArticle_Order`);

CREATE INDEX `IDX_CMSArticle_9` ON `CMSArticle` (`CMSArticleCategory_Code`,`CMSArticle_Order`);

# ---------------------------------------------------------------------- #
# Add table "FieldSelect"                                                #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldSelect` (
    `FieldSelect_ID` INTEGER NOT NULL AUTO_INCREMENT,
    `FieldDefinition_ID` INTEGER,
    `FieldSelect_Order` INTEGER NOT NULL,
    `FieldSelect_Code` VARCHAR(255),
    `FieldSelect_Name` VARCHAR(255) NOT NULL,
    `FieldSelect_ID_Parent` INTEGER,
    `__FieldSelect_Title` VARCHAR(255),
    CONSTRAINT `PK_FieldSelect` PRIMARY KEY (`FieldSelect_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_FieldSelect_1` ON `FieldSelect` (`FieldDefinition_ID`);

CREATE UNIQUE INDEX `IDX_FieldSelect_2` ON `FieldSelect` (`FieldSelect_Code`);

CREATE INDEX `IDX_FieldSelect_3` ON `FieldSelect` (`FieldSelect_Order`);

CREATE INDEX `IDX_FieldSelect_4` ON `FieldSelect` (`FieldDefinition_ID`,`FieldSelect_Order`,`FieldSelect_ID_Parent`);

CREATE INDEX `IDX_FieldSelect_5` ON `FieldSelect` (`FieldSelect_ID_Parent`);

# ---------------------------------------------------------------------- #
# Add table "FieldData_FieldSelect"                                      #
# ---------------------------------------------------------------------- #

CREATE TABLE `FieldData_FieldSelect` (
    `FieldData_ID` INTEGER NOT NULL,
    `FieldSelect_ID` INTEGER NOT NULL,
    CONSTRAINT `PK_FieldData_FieldSelect` PRIMARY KEY (`FieldData_ID`, `FieldSelect_ID`)
)
ENGINE=InnoDB;

CREATE INDEX `IDX_FieldData_FieldSelect_1` ON `FieldData_FieldSelect` (`FieldData_ID`);

CREATE INDEX `IDX_FieldData_FieldSelect_2` ON `FieldData_FieldSelect` (`FieldSelect_ID`);

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

ALTER TABLE `PersonGroup` ADD CONSTRAINT `PersonGroupType_PersonGroup` 
    FOREIGN KEY (`PersonGroupType_Code`) REFERENCES `PersonGroupType` (`PersonGroupType_Code`);

ALTER TABLE `Person` ADD CONSTRAINT `PersonGroup_Person` 
    FOREIGN KEY (`PersonGroup_ID`) REFERENCES `PersonGroup` (`PersonGroup_ID`);

ALTER TABLE `Country` ADD CONSTRAINT `Language_Country` 
    FOREIGN KEY (`Language_Code_Default`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `Country` ADD CONSTRAINT `Currency_Country` 
    FOREIGN KEY (`Currency_Code`) REFERENCES `Currency` (`Currency_Code`);

ALTER TABLE `Authorization` ADD CONSTRAINT `AuthorizationSubType_Authorization` 
    FOREIGN KEY (`AuthorizationSubType_Code`) REFERENCES `AuthorizationSubType` (`AuthorizationSubType_Code`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `Worker` ADD CONSTRAINT `Person_Worker` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `Worker` ADD CONSTRAINT `Language_Worker` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `Person_Authorization` ADD CONSTRAINT `Authorization_Person_Authorization` 
    FOREIGN KEY (`Authorization_Code`) REFERENCES `Authorization` (`Authorization_Code`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `Person_Authorization` ADD CONSTRAINT `Person_Person_Authorization` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `PersonGroup_Authorization` ADD CONSTRAINT `PersonGroup_PersonGroup_Authorization` 
    FOREIGN KEY (`PersonGroup_ID`) REFERENCES `PersonGroup` (`PersonGroup_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `PersonGroup_Authorization` ADD CONSTRAINT `Authorization_PersonGroup_Authorization` 
    FOREIGN KEY (`Authorization_Code`) REFERENCES `Authorization` (`Authorization_Code`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `Menu` ADD CONSTRAINT `Authorization_Menu` 
    FOREIGN KEY (`Authorization_Code`) REFERENCES `Authorization` (`Authorization_Code`);

ALTER TABLE `MenuParameter` ADD CONSTRAINT `Menu_MenuParameter` 
    FOREIGN KEY (`Menu_ID`) REFERENCES `Menu` (`Menu_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `LTMTranslation_Language` ADD CONSTRAINT `LTMTranslation_LTMTranslation_Language` 
    FOREIGN KEY (`Translation_Code`) REFERENCES `LTMTranslation` (`Translation_Code`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `LTMTranslation_Language` ADD CONSTRAINT `Language_LTMTranslation_Language` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `ArticleEntry_Document` ADD CONSTRAINT `Document_ArticleEntry_Document` 
    FOREIGN KEY (`Document_ID`) REFERENCES `Document` (`Document_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_Document` ADD CONSTRAINT `ArticleEntry_ArticleEntry_Document` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_Link` ADD CONSTRAINT `ArticleEntry_ArticleEntry_Link` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_Link` ADD CONSTRAINT `Link_ArticleEntry_Link` 
    FOREIGN KEY (`Link_ID`) REFERENCES `Link` (`Link_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_Picture` ADD CONSTRAINT `ArticleEntry_ArticleEntry_Picture` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_Picture` ADD CONSTRAINT `Picture_ArticleEntry_Picture` 
    FOREIGN KEY (`Picture_ID`) REFERENCES `Picture` (`Picture_ID`) ON DELETE CASCADE;

ALTER TABLE `CMSArticle` ADD CONSTRAINT `ArticleEntry_CMSArticle_Parent` 
    FOREIGN KEY (`ArticleEntry_ID_Parent`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `CMSArticle` ADD CONSTRAINT `Language_CMSArticle` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `CMSArticle` ADD CONSTRAINT `CMSArticleCategory_CMSArticle` 
    FOREIGN KEY (`CMSArticleCategory_Code`) REFERENCES `CMSArticleCategory` (`CMSArticleCategory_Code`) ON DELETE CASCADE;

ALTER TABLE `CMSArticle` ADD CONSTRAINT `Person_CMSArticle` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`);

ALTER TABLE `CMSArticle` ADD CONSTRAINT `ArticleEntry_CMSArticle` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `CMSArticle` ADD CONSTRAINT `CMSArticle_CMSArticle` 
    FOREIGN KEY (`CMSArticle_ID_Copy`) REFERENCES `CMSArticle` (`CMSArticle_ID`) ON DELETE SET NULL;

ALTER TABLE `Document` ADD CONSTRAINT `DocumentCategory_Document` 
    FOREIGN KEY (`DocumentCategory_Code`) REFERENCES `DocumentCategory` (`DocumentCategory_Code`);

ALTER TABLE `Document` ADD CONSTRAINT `Picture_Document` 
    FOREIGN KEY (`Picture_ID`) REFERENCES `Picture` (`Picture_ID`) ON DELETE SET NULL;

ALTER TABLE `Link` ADD CONSTRAINT `LinkCategory_Link` 
    FOREIGN KEY (`LinkCategory_Code`) REFERENCES `LinkCategory` (`LinkCategory_Code`);

ALTER TABLE `Picture` ADD CONSTRAINT `PictureCategory_Picture` 
    FOREIGN KEY (`PictureCategory_Code`) REFERENCES `PictureCategory` (`PictureCategory_Code`);

ALTER TABLE `PictureFile` ADD CONSTRAINT `PictureFile_Type_PictureFile` 
    FOREIGN KEY (`PictureFileType_Code`) REFERENCES `PictureFile_Type` (`PictureFileType_Code`) ON DELETE CASCADE;

ALTER TABLE `PictureFile` ADD CONSTRAINT `Picture_PictureFile` 
    FOREIGN KEY (`Picture_ID`) REFERENCES `Picture` (`Picture_ID`) ON DELETE CASCADE;

ALTER TABLE `Version` ADD CONSTRAINT `VersionType_Version` 
    FOREIGN KEY (`VersionType_Code`) REFERENCES `VersionType` (`VersionType_Code`);

ALTER TABLE `Version` ADD CONSTRAINT `Language_Version` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `Version` ADD CONSTRAINT `VersionState_Version` 
    FOREIGN KEY (`VersionState_Code`) REFERENCES `VersionState` (`VersionState_Code`);

ALTER TABLE `Version` ADD CONSTRAINT `Person_Version` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`);

ALTER TABLE `Contact` ADD CONSTRAINT `Person_Contact` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`) ON DELETE CASCADE;

ALTER TABLE `Contact` ADD CONSTRAINT `ContactType_Contact` 
    FOREIGN KEY (`ContactType_Code`) REFERENCES `ContactType` (`ContactType_Code`);

ALTER TABLE `Language_Person` ADD CONSTRAINT `Language_Language_Person` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`) ON DELETE CASCADE;

ALTER TABLE `Language_Person` ADD CONSTRAINT `Person_Language_Person` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterRecipient` ADD CONSTRAINT `Person_NewsletterRecipient` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`);

ALTER TABLE `NewsletterRecipient` ADD CONSTRAINT `Language_NewsletterRecipient` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`) ON DELETE CASCADE;

ALTER TABLE `NewsletterRecipient` ADD CONSTRAINT `NewsletterRecipientImport_NewsletterRecipient` 
    FOREIGN KEY (`NewsletterRecipientImport_ID`) REFERENCES `NewsletterRecipientImport` (`NewsletterRecipientImport_ID`);

ALTER TABLE `Newsletter` ADD CONSTRAINT `NewsletterState_Newsletter` 
    FOREIGN KEY (`NewsletterState_Code`) REFERENCES `NewsletterState` (`NewsletterState_Code`);

ALTER TABLE `Newsletter` ADD CONSTRAINT `ArticleEntry_Newsletter` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE RESTRICT;

ALTER TABLE `Newsletter` ADD CONSTRAINT `NewsletterType_Newsletter` 
    FOREIGN KEY (`NewsletterType_Code`) REFERENCES `NewsletterType` (`NewsletterType_Code`);

ALTER TABLE `NewsletterGroup_NewsletterRecipient` ADD CONSTRAINT `NewsletterGroup_NewsletterGroup_NewsletterRecipient` 
    FOREIGN KEY (`NewsletterGroup_ID`) REFERENCES `NewsletterGroup` (`NewsletterGroup_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterGroup_NewsletterRecipient` ADD CONSTRAINT `NewsletterRecipient_NewsletterGroup_NewsletterRecipient` 
    FOREIGN KEY (`Person_ID`) REFERENCES `NewsletterRecipient` (`Person_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterQueue` ADD CONSTRAINT `NewsletterRecipient_NewsletterQueue` 
    FOREIGN KEY (`Person_ID`) REFERENCES `NewsletterRecipient` (`Person_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterQueue` ADD CONSTRAINT `Newsletter_NewsletterQueue` 
    FOREIGN KEY (`Newsletter_ID`) REFERENCES `Newsletter` (`Newsletter_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterQueue` ADD CONSTRAINT `Language_NewsletterQueue` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `NewsletterQueue` ADD CONSTRAINT `NewsletterInstance_NewsletterQueue` 
    FOREIGN KEY (`NewsletterInstance_ID`) REFERENCES `NewsletterInstance` (`NewsletterInstance_ID`) ON DELETE CASCADE;

ALTER TABLE `Newsletter_ArticleEntry` ADD CONSTRAINT `ArticleEntry_Newsletter_ArticleEntry` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `Newsletter_ArticleEntry` ADD CONSTRAINT `Newsletter_Newsletter_ArticleEntry` 
    FOREIGN KEY (`Newsletter_ID`) REFERENCES `Newsletter` (`Newsletter_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterType` ADD CONSTRAINT `NewsletterGroup_NewsletterType` 
    FOREIGN KEY (`NewsletterGroup_ID`) REFERENCES `NewsletterGroup` (`NewsletterGroup_ID`);

ALTER TABLE `Customer` ADD CONSTRAINT `Person_Customer` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Person` (`Person_ID`) ON DELETE CASCADE;

ALTER TABLE `Customer` ADD CONSTRAINT `Country_Customer` 
    FOREIGN KEY (`Country_Code`) REFERENCES `Country` (`Country_Code`);

ALTER TABLE `Customer` ADD CONSTRAINT `Language_Customer` 
    FOREIGN KEY (`Language_Code`) REFERENCES `Language` (`Language_Code`);

ALTER TABLE `FieldDefinition` ADD CONSTRAINT `FieldDefinitionDatatype_FieldDefinition` 
    FOREIGN KEY (`FieldDefinitionDatatype_Code`) REFERENCES `FieldDefinitionDatatype` (`FieldDefinitionDatatype_Code`);

ALTER TABLE `FieldDefinition` ADD CONSTRAINT `FieldDefinitionType_FieldDefinition` 
    FOREIGN KEY (`FieldDefinitionType_Code`) REFERENCES `FieldDefinitionType` (`FieldDefinitionType_Code`) ON DELETE CASCADE;

ALTER TABLE `FieldData` ADD CONSTRAINT `FieldDefinition_FieldData` 
    FOREIGN KEY (`FieldDefinition_ID`) REFERENCES `FieldDefinition` (`FieldDefinition_ID`) ON DELETE CASCADE;

ALTER TABLE `FieldData` ADD CONSTRAINT `ArticleEntry_FieldData` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `FieldSelect` ADD CONSTRAINT `FieldDefinition_FieldSelect` 
    FOREIGN KEY (`FieldDefinition_ID`) REFERENCES `FieldDefinition` (`FieldDefinition_ID`);

ALTER TABLE `FieldSelect` ADD CONSTRAINT `FieldSelect_FieldSelect` 
    FOREIGN KEY (`FieldSelect_ID_Parent`) REFERENCES `FieldSelect` (`FieldSelect_ID`) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE `FieldData_FieldSelect` ADD CONSTRAINT `FieldData_FieldData_FieldSelect` 
    FOREIGN KEY (`FieldData_ID`) REFERENCES `FieldData` (`FieldData_ID`) ON DELETE CASCADE;

ALTER TABLE `FieldData_FieldSelect` ADD CONSTRAINT `FieldSelect_FieldData_FieldSelect` 
    FOREIGN KEY (`FieldSelect_ID`) REFERENCES `FieldSelect` (`FieldSelect_ID`) ON DELETE CASCADE;

ALTER TABLE `NewsletterClickJournal` ADD CONSTRAINT `NewsletterQueue_NewsletterClickJournal` 
    FOREIGN KEY (`NewsletterQueue_ID`) REFERENCES `NewsletterQueue` (`NewsletterQueue_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_MapLocation` ADD CONSTRAINT `ArticleEntry_ArticleEntry_MapLocation` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntry_MapLocation` ADD CONSTRAINT `MapLocation_ArticleEntry_MapLocation` 
    FOREIGN KEY (`MapLocation_ID`) REFERENCES `MapLocation` (`MapLocation_ID`) ON DELETE CASCADE;

ALTER TABLE `MapLocation` ADD CONSTRAINT `MapLocationCategory_MapLocation` 
    FOREIGN KEY (`MapLocationCategory_Code`) REFERENCES `MapLocationCategory` (`MapLocationCategory_Code`);

ALTER TABLE `Queue` ADD CONSTRAINT `QueueState_Queue` 
    FOREIGN KEY (`QueueState_Code`) REFERENCES `QueueState` (`QueueState_Code`);

ALTER TABLE `Queue` ADD CONSTRAINT `QueueType_Queue` 
    FOREIGN KEY (`QueueType_Code`) REFERENCES `QueueType` (`QueueType_Code`);

ALTER TABLE `QueueData` ADD CONSTRAINT `Queue_QueueData` 
    FOREIGN KEY (`Queue_ID`) REFERENCES `Queue` (`Queue_ID`) ON DELETE CASCADE;

ALTER TABLE `Rating` ADD CONSTRAINT `ArticleEntry_Rating` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntryDateTime` ADD CONSTRAINT `ArticleEntry_ArticleEntryDateTime` 
    FOREIGN KEY (`ArticleEntry_ID`) REFERENCES `ArticleEntry` (`ArticleEntry_ID`) ON DELETE CASCADE;

ALTER TABLE `ArticleEntryDateTime` ADD CONSTRAINT `ArticleEntryDateTimeType_ArticleEntryDateTime` 
    FOREIGN KEY (`ArticleEntryDateTimeType_Code`) REFERENCES `ArticleEntryDateTimeType` (`ArticleEntryDateTimeType_Code`);

ALTER TABLE `CountryZone_Country` ADD CONSTRAINT `CountryZone_CountryZone_Country` 
    FOREIGN KEY (`CountryZone_Code`) REFERENCES `CountryZone` (`CountryZone_Code`) ON DELETE CASCADE;

ALTER TABLE `CountryZone_Country` ADD CONSTRAINT `Country_CountryZone_Country` 
    FOREIGN KEY (`Country_Code`) REFERENCES `Country` (`Country_Code`) ON DELETE CASCADE;

ALTER TABLE `Clipboard` ADD CONSTRAINT `Worker_Clipboard` 
    FOREIGN KEY (`Person_ID`) REFERENCES `Worker` (`Person_ID`);
