Skip to content

Instantly share code, notes, and snippets.

@albankora
Created June 25, 2018 04:17
Show Gist options
  • Save albankora/59ceee8ee47197a313fa629fb3ef3438 to your computer and use it in GitHub Desktop.
Save albankora/59ceee8ee47197a313fa629fb3ef3438 to your computer and use it in GitHub Desktop.
CREATE TABLE user (
user_id INT(7),
user_prefix VARCHAR(16),
name VARCHAR (255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(user_id, user_prefix)
);
DELIMITER $$
CREATE PROCEDURE prepare_data()
BEGIN
DECLARE i INT DEFAULT 100;
WHILE i < 10000000 DO
INSERT INTO user (user_id, user_prefix, name) VALUES (i, i, 'test nad all test because of text');
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL prepare_data();
//UP
ALTER TABLE user DROP PRIMARY KEY, ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);
//DOWN
ALTER TABLE user DROP PRIMARY KEY, DROP COLUMN `id`, ADD PRIMARY KEY (user_id, user_prefix);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment