CREATE TABLE IF NOT EXISTS `ClusterNode` (
  `Id` int(11) NOT NULL auto_increment,
  `NetworkAddress` VARCHAR(255) NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

INSERT INTO `ClusterNode` (`Id` ,`NetworkAddress`) VALUES ( NULL , 'localhost' );


ALTER TABLE `Realm` ADD `ClusterNode` INT NOT NULL ;
ALTER TABLE `Realm` ADD INDEX ( `ClusterNode` ) ;
UPDATE `Realm` SET `Node` = 1;
ALTER TABLE `Realm` ADD FOREIGN KEY ( `Node` ) REFERENCES `ClusterNode` (`Id`);


ALTER TABLE `Server` ADD `ClusterNode` INT NOT NULL ;
ALTER TABLE `Server` ADD INDEX ( `ClusterNode` ) ;
UPDATE `Server` SET `ClusterNode` = 1;
ALTER TABLE `Server` ADD FOREIGN KEY ( `ClusterNode` ) REFERENCES `ClusterNode` ( `Id` );


CREATE TABLE IF NOT EXISTS `CustomPatch` (
  `Id` int(11) NOT NULL auto_increment,
  `Type` int(11) NOT NULL,
  `User` int(11) NOT NULL,
  `TimeCreate` datetime NOT NULL,
  `Realm` int(11) NOT NULL,
  `Content` mediumtext NOT NULL,
  PRIMARY KEY  (`Id`),
  KEY `Realm` (`Realm`),
  KEY `User` (`User`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE `CustomPatch`
  ADD CONSTRAINT `CustomPatch_ibfk_2` FOREIGN KEY (`User`) REFERENCES `User` (`Id`),
  ADD CONSTRAINT `CustomPatch_ibfk_1` FOREIGN KEY (`Realm`) REFERENCES `Realm` (`Id`);  
