CREATE TABLE IF NOT EXISTS `#prefix#ModuleSettings` (
    `setting`              VARCHAR(64) NOT NULL UNIQUE,
    `value`            TEXT NOT NULL,
    PRIMARY KEY (`setting`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#Logger` (
    `id`            int(10) unsigned NOT NULL AUTO_INCREMENT,
    `id_ref`        int(10) NOT NULL,
    `id_type`       VARCHAR(255) NOT NULL,
    `type`          VARCHAR(255) NOT NULL,
    `level`         VARCHAR(255) NOT NULL,
    `date`          DATETIME DEFAULT null,
    `request`       TEXT NOT NULL,
    `response`      TEXT NOT NULL,
    `before_vars`   TEXT NOT NULL,
    `vars`          TEXT NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#Groups` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` VARCHAR(100) NOT NULL,
        `defaultEmailTemplate` VARCHAR(50),
        `type` ENUM('fixed', 'tiered'),
        `status` ENUM('on', 'off') DEFAULT 'off',
        `hours` int(11) DEFAULT 24,
         PRIMARY KEY (`id`),
         UNIQUE KEY `uniq` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#ProductGroup` (
    `id`  int(11) NOT NULL AUTO_INCREMENT,
    `gid` int(11),
    `pid` int(11),
     UNIQUE KEY `uniq` (`pid`),
     PRIMARY KEY (`id`),
     FOREIGN KEY (`gid`) REFERENCES `#prefix#Groups` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#GroupsConfiguration` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `groupid` int(11) NOT NULL ,
        `kind` VARCHAR(25) NOT NULL ,
        `configuration` text ,
         PRIMARY KEY (`id`),
         FOREIGN KEY (`groupid`) REFERENCES `#prefix#Groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#TicketTemplates` (
    `id`               int(11)      unsigned                NOT NULL AUTO_INCREMENT,
    `name`             VARCHAR(255) NOT NULL,
    `department_id`    int(11) unsigned NOT NULL,
    `admin_id`         int(11) unsigned NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#TicketTemplatesLangs` (
    `id`               int(11)      unsigned                NOT NULL AUTO_INCREMENT,
    `template_id`      int(11)      unsigned,
    `lang`             VARCHAR(60) NOT NULL,
    `subject`          VARCHAR(255) NOT NULL,
    `message`          TEXT,
    PRIMARY KEY (`id`),
    FOREIGN KEY (`template_id`) REFERENCES `#prefix#TicketTemplates` (`id`) ON DELETE CASCADE

) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#Usage` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `hid` int(11) NOT NULL,
    `bw` int(11),
    `disk` int(11),
    `date` DATE,
     UNIQUE KEY `uniq` (`hid`, `date`),
     PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#HostingDuedates` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `hid` int(11),
    `duedate` DATE,
     UNIQUE KEY `uniq` (`hid`),
     PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;

CREATE TABLE IF NOT EXISTS `#prefix#Notifications` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `groupid` int(11),
        `hostingid` int(11),
        `ticketid` int(11),
        `configurationid` int(11),
        `kind` VARCHAR(10) NOT NULL ,
        `type` VARCHAR(10) NOT NULL ,
        `over` int(11),
        `overUnit` VARCHAR (10),
        `date` DATETIME,
         PRIMARY KEY (`id`),
         FOREIGN KEY (`groupid`)   REFERENCES `#prefix#Groups` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=#charset# DEFAULT COLLATE #collation#;