Skip to content

Instantly share code, notes, and snippets.

@ddurst
Last active August 29, 2015 14:16
Show Gist options
  • Save ddurst/0899de46f7bc07e6c713 to your computer and use it in GitHub Desktop.
Save ddurst/0899de46f7bc07e6c713 to your computer and use it in GitHub Desktop.
mkt-2015-03-10 SQL tweaks
-- BEFORE PUSH
-- step 1
-- -- on stage
DROP INDEX `fxa_uid` ON `users`; -- on stage, it's called `fxa_uid` because of how we reverted the initial migration
-- -- on prod
DROP INDEX `username` ON `users`;
-- step 2
ALTER TABLE `users` CHANGE `username` `username` varchar(255) NULL DEFAULT NULL
-- step 3
ALTER TABLE `users` ADD COLUMN `fxa_uid` varchar(255) NULL DEFAULT NULL;
-- step 4
UPDATE users SET fxa_uid=username WHERE LENGTH(username) = 32;
-- step 5
CREATE UNIQUE INDEX `fxa_uid` ON users(fxa_uid);
-- step 6
UPDATE users SET last_login=last_login_attempt WHERE last_login = '1970-01-01 00:00:00' AND last_login_attempt IS NOT NULL
-- AFTER PUSH
-- step 0 (only on prod)
UPDATE users SET fxa_uid=username WHERE LENGTH(username) = 32 and fxa_uid IS NULL; -- to get any records added during the transition
-- step 1
ALTER TABLE `users` DROP COLUMN username, DROP COLUMN last_login_attempt, DROP COLUMN last_login_attempt_ip, DROP COLUMN failed_login_attempts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment