CREATE TABLE `an_TrainingLanguage` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `system` enum('n','y') NOT NULL DEFAULT 'n',
  `sorter` int(11) NOT NULL DEFAULT 0,
  `added` datetime NOT NULL,
  `changed` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `an_TrainingLanguage` (`id`, `title`, `system`, `sorter`, `added`, `changed`) VALUES
(NULL, 'English', 'y', 0, NOW(), NOW());

ALTER TABLE `an_Test` ADD `languageId` int(11) unsigned NOT NULL AFTER `image`;
UPDATE `an_Test` SET `languageId` = 1;
ALTER TABLE `an_Test` ADD KEY `languageId` (`languageId`);
ALTER TABLE `an_Test` ADD CONSTRAINT `an_Test_ibfk_2` FOREIGN KEY (`languageId`) REFERENCES `an_TrainingLanguage` (`id`);

ALTER TABLE `an_User`
  ADD `languageId` int(11) unsigned NOT NULL AFTER `address`,
  ADD `languageTitle` varchar(255) DEFAULT NULL AFTER `languageId`;
UPDATE `an_User` SET `languageId` = 1, `languageTitle` = 'English';
ALTER TABLE `an_User` ADD KEY `languageId` (`languageId`);
