-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DB schema migration infrastructure and script
- Loading branch information
Showing
8 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/*!40101 SET NAMES utf8 */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40101 SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET SQL_NOTES=0 */; | ||
|
||
|
||
DROP PROCEDURE IF EXISTS `upgrade_schema`; | ||
|
||
DELIMITER $$ | ||
|
||
CREATE PROCEDURE `upgrade_schema`() | ||
ret: | ||
BEGIN | ||
SET autocommit = 0; | ||
|
||
-- Create settings table for users who don't have it. | ||
CREATE TABLE IF NOT EXISTS `settings` ( | ||
`key` varchar(50) NOT NULL, | ||
`value` varchar(50) NOT NULL, | ||
PRIMARY KEY (`key`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | ||
|
||
-- Set default DB version number in case the user didn't have the table. | ||
INSERT IGNORE INTO `settings` (`key`, `value`) | ||
VALUES ('version', '0'); | ||
|
||
-- Get current DB version. | ||
SELECT @version := `value` FROM `settings` WHERE `key` = 'version'; | ||
|
||
-- Upgrade paths for each version: | ||
|
||
IF @version = '0' THEN | ||
ALTER TABLE `submitted_work` | ||
ADD INDEX `dashboard_status_index2` (`time`, `worker_id`); | ||
|
||
COMMIT; | ||
SET @version = '1'; | ||
END IF; | ||
|
||
-- Store updated version. | ||
UPDATE `settings` SET `value` = @version WHERE `key` = 'version'; | ||
COMMIT; | ||
|
||
-- Message for the console. | ||
SELECT 'Database upgraded successfully.'; | ||
END | ||
|
||
$$ | ||
|
||
DELIMITER ; | ||
|
||
CALL `upgrade_schema`(); | ||
DROP PROCEDURE `upgrade_schema`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters