CREATE TABLE `calendar` (
  `Calendar_No` int(11) NOT NULL AUTO_INCREMENT,
  `ClassName` varchar(50) DEFAULT NULL,
  `Name` varchar(50) NOT NULL,
  `AllowedEventTypes` text NOT NULL,
  `Views` text NOT NULL,
  `DefaultView` varchar(20) NOT NULL DEFAULT 'month',
  `Public` tinyint(4) NOT NULL DEFAULT 1,
  `EventType_Filter` text DEFAULT NULL,
  `ResourceColumns` text DEFAULT NULL,
  `ResourceSortColumns` text DEFAULT NULL,
  `OwnedBy_User_Id` int(11) DEFAULT NULL,
  `ResourceCategory` enum('Who','Where') NOT NULL DEFAULT 'Who',
  `Default_Filter` varchar(200) DEFAULT '',
  `Active` tinyint(4) NOT NULL DEFAULT 1,
  `CreateDate` datetime DEFAULT NULL,
  `CreatedBy` varchar(20) DEFAULT NULL,
  `ModifiedDate` datetime DEFAULT NULL,
  `ModifiedBy` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`Calendar_No`),
  UNIQUE KEY `ClassName` (`ClassName`),
  KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `event` (
  `Event_No` int(11) NOT NULL AUTO_INCREMENT,
  `EventTypeDef_No` int(11) NOT NULL,
  `Status` enum('Available','Free','Busy','Out','Canceled') NOT NULL DEFAULT 'Available',
  `Name` varchar(200) NOT NULL DEFAULT '',
  `Color` varchar(7) NOT NULL,
  `OwnedBy_Calendar_No` int(11) NOT NULL,
  `Private` tinyint(4) DEFAULT 0,
  `Tentative` tinyint(4) NOT NULL DEFAULT 0,
  `OnCalendar` tinyint(4) NOT NULL DEFAULT 0,
  `IsFavorite` tinyint(4) NOT NULL DEFAULT 0,
  `Description` text DEFAULT NULL,
  `Active` tinyint(4) NOT NULL DEFAULT 1,
  `CreateDate` datetime DEFAULT NULL,
  `CreatedBy` varchar(20) DEFAULT NULL,
  `ModifiedDate` datetime DEFAULT NULL,
  `ModifiedBy` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`Event_No`),
  KEY `EventTypeDef_No` (`EventTypeDef_No`),
  KEY `Status` (`Status`),
  KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `event_sched` (
  `EventSched_No` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique No',
  `Event_No` int(11) NOT NULL,
  `RecurrenceRule` text DEFAULT NULL,
  `DurationInMin` int(11) NOT NULL,
  `StartDateTime` datetime DEFAULT NULL,
  `UntilDate` date DEFAULT NULL,
  `Active` tinyint(4) NOT NULL DEFAULT 1,
  `CreateDate` datetime DEFAULT NULL,
  `CreatedBy` varchar(20) DEFAULT NULL,
  `ModifiedDate` datetime DEFAULT NULL,
  `ModifiedBy` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`EventSched_No`),
  KEY `Event_No` (`Event_No`),
  KEY `StartDateTime` (`StartDateTime`),
  KEY `UntilDate` (`UntilDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `event_subtype` (
  `EventSubType_No` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique No',
  `Event_No` int(11) NOT NULL,
  `EventTypeDef_No` int(11) NOT NULL,
  `Active` tinyint(4) NOT NULL DEFAULT 1,
  `CreateDate` datetime DEFAULT NULL,
  `CreatedBy` varchar(20) DEFAULT NULL,
  `ModifiedDate` datetime DEFAULT NULL,
  `ModifiedBy` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`EventSubType_No`),
  KEY `Event_No` (`Event_No`),
  KEY `EventTypeDef_No` (`EventTypeDef_No`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `eventtype_def` (
  `EventTypeDef_No` int(11) NOT NULL AUTO_INCREMENT,
  `ClassName` varchar(50) DEFAULT NULL,
  `Name` varchar(50) NOT NULL COMMENT 'Name',
  `Status` enum('Available','Free','Busy','Out'),
  `Parent_EventTypeDef_No` int(11) NOT NULL,
  `PublicColor` varchar(7) NOT NULL,
  `PrivateColor` varchar(7) NOT NULL,
  `Public` tinyint(4) NOT NULL DEFAULT 0,
  `WhoSource` varchar(50) DEFAULT NULL,
  `AllowOtherWho` tinyint(4) NOT NULL DEFAULT 0,
  `WhereSource` varchar(50) DEFAULT NULL,
  `AllowOtherWhere` tinyint(4) NOT NULL DEFAULT 0,
  `CanChangeAfterSaved` tinyint(4) DEFAULT 1,
  `OwnerLabel` varchar(50) DEFAULT NULL,
  `WhoOwnerSource` varchar(50) DEFAULT NULL,
  `AllowOtherWhoOwner` tinyint(4) DEFAULT 0,
  `Active` tinyint(4) NOT NULL DEFAULT 1,
  `CreateDate` datetime DEFAULT NULL,
  `CreatedBy` varchar(20) DEFAULT NULL,
  `ModifiedDate` datetime DEFAULT NULL,
  `ModifiedBy` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`EventTypeDef_No`),
  UNIQUE KEY `ClassName` (`ClassName`),
  KEY `Name` (`Name`),
  KEY `Status` (`Status`),
  KEY `Parent_EventTypeDef_No` (`Parent_EventTypeDef_No`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
