Skip to content

Instantly share code, notes, and snippets.

@trang
Created October 15, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trang/66835392f279653b1aa0c4647938bfdb to your computer and use it in GitHub Desktop.
Save trang/66835392f279653b1aa0c4647938bfdb to your computer and use it in GitHub Desktop.
Restore sentences modifications
DROP TABLE IF EXISTS `sentences_to_fix`;
CREATE TABLE `sentences_to_fix` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lang` varchar(4) DEFAULT NULL,
`text` varbinary(1500) NOT NULL,
`username` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
`hash` BINARY(16) NOT NULL,
`user_id` int(11) DEFAULT NULL,
`backup_user_id` int(11) DEFAULT NULL,
`backup_lang` varchar(4) DEFAULT NULL,
`backup_text` varbinary(1500) NOT NULL,
PRIMARY KEY (`id`),
KEY `lang` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOAD DATA INFILE '/tmp/restored_modified_sentences_2017-10-14.csv' INTO TABLE sentences_to_fix;
UPDATE sentences_to_fix s JOIN users u ON s.username = u.username SET s.user_id = u.id;
UPDATE sentences_to_fix s1 JOIN sentences s2 ON s1.id = s2.id SET s1.backup_user_id = s2.user_id, s1.backup_lang = s2.lang, s1.backup_text = s2.text;
UPDATE sentences s1 JOIN sentences_to_fix s2 ON s1.id = s2.id SET s1.user_id = s2.user_id, s1.lang = s2.lang, s1.text = s2.text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment