ALTER TABLE `Task`  ENGINE = InnoDB;
ALTER TABLE `Backup`  ENGINE = InnoDB;
ALTER TABLE `Database`  ENGINE = InnoDB;
ALTER TABLE `Client`  ENGINE = InnoDB;
ALTER TABLE `Debug`  ENGINE = InnoDB;
ALTER TABLE `Emulator`  ENGINE = InnoDB;
ALTER TABLE `History`  ENGINE = InnoDB;
ALTER TABLE `Log`  ENGINE = InnoDB;
ALTER TABLE `User`  ENGINE = InnoDB;
ALTER TABLE `UserOnline`  ENGINE = InnoDB;
ALTER TABLE `News`  ENGINE = InnoDB;
ALTER TABLE `Server`  ENGINE = InnoDB;

ALTER TABLE `Emulator` ADD INDEX ( `Client` ) ;
ALTER TABLE `Emulator` ADD FOREIGN KEY ( `Client` ) REFERENCES `Client` (`Id`);

ALTER TABLE `Debug` ADD INDEX ( `Server` ) ;
ALTER TABLE `Debug` ADD FOREIGN KEY ( `Server` ) REFERENCES `Server` (`Id`);

ALTER TABLE `Backup` ADD INDEX ( `Server` ) ;
ALTER TABLE `Backup` ADD INDEX ( `Database` ) ;

ALTER TABLE `UserOnline` ADD FOREIGN KEY ( `User` ) REFERENCES `User` (`Id`);

ALTER TABLE `Task` CHANGE `User` `User` INT( 11 ) NULL ;
UPDATE `Task` SET `User` = NULL WHERE `User` = 0;
ALTER TABLE `Task` ADD INDEX ( `User` ) ;
ALTER TABLE `Task` ADD FOREIGN KEY ( `User` ) REFERENCES `User` (`Id`);

ALTER TABLE `Server` ADD INDEX ( `User` ) ;
ALTER TABLE `Server` ADD FOREIGN KEY ( `User` ) REFERENCES `User` (`Id`);
ALTER TABLE `Server` ADD INDEX ( `Database` ) ;
ALTER TABLE `Server` ADD FOREIGN KEY ( `Database` ) REFERENCES `Database` (`Id`);

ALTER TABLE `News` ADD INDEX ( `User` ) ;
ALTER TABLE `News` ADD FOREIGN KEY ( `User` ) REFERENCES `User` (`Id`);

ALTER TABLE `Log` ADD INDEX ( `User` ) ;
ALTER TABLE `Log` ADD FOREIGN KEY ( `User` ) REFERENCES `User` (`Id`);

ALTER TABLE `History` ADD FOREIGN KEY ( `Server` ) REFERENCES `Server` (`Id`);

ALTER TABLE `Database` ADD INDEX ( `Emulator` ) ;
ALTER TABLE `Database` CHANGE `Emulator` `Emulator` INT( 11 ) NULL ;
UPDATE `Database` SET `Emulator` = NULL WHERE `Emulator` = 0;
ALTER TABLE `Database` ADD FOREIGN KEY ( `Emulator` ) REFERENCES `Emulator` (`Id`);

