diff --git a/bitshift/database/migration.py b/bitshift/database/migration.py index 9a74a18..7a4ba62 100644 --- a/bitshift/database/migration.py +++ b/bitshift/database/migration.py @@ -3,7 +3,7 @@ Contains information about database schema versions, and SQL queries to update between them. """ -VERSION = 8 +VERSION = 9 MIGRATIONS = [ # 1 -> 2 @@ -100,6 +100,21 @@ MIGRATIONS = [ [ """ALTER TABLE `origins` DROP COLUMN `origin_image`""" + ], + # 8 -> 9 + [ + """DELIMITER // + CREATE PROCEDURE `empty_database` + BEGIN + DELETE FROM `codelets`; + DELETE FROM `code`; + DELETE FROM `cache`; + ALTER TABLE `codelets` AUTO_INCREMENT = 1; + ALTER TABLE `authors` AUTO_INCREMENT = 1; + ALTER TABLE `symbols` AUTO_INCREMENT = 1; + ALTER TABLE `symbol_locations` AUTO_INCREMENT = 1; + END + DELIMITER ;""" ] ] diff --git a/bitshift/database/schema.sql b/bitshift/database/schema.sql index 913a365..65266b8 100644 --- a/bitshift/database/schema.sql +++ b/bitshift/database/schema.sql @@ -1,4 +1,4 @@ --- Schema version 8 +-- Schema version 9 CREATE DATABASE `bitshift` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; USE `bitshift`; @@ -6,7 +6,7 @@ USE `bitshift`; CREATE TABLE `version` ( `version` INT UNSIGNED NOT NULL ) ENGINE=InnoDB; -INSERT INTO `version` VALUES (8); +INSERT INTO `version` VALUES (9); CREATE TABLE `origins` ( `origin_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -107,6 +107,19 @@ CREATE TABLE `cache_data` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB; +DELIMITER // +CREATE PROCEDURE `empty_database` + BEGIN + DELETE FROM `codelets`; + DELETE FROM `code`; + DELETE FROM `cache`; + ALTER TABLE `codelets` AUTO_INCREMENT = 1; + ALTER TABLE `authors` AUTO_INCREMENT = 1; + ALTER TABLE `symbols` AUTO_INCREMENT = 1; + ALTER TABLE `symbol_locations` AUTO_INCREMENT = 1; + END +DELIMITER ; + CREATE EVENT `flush_cache` ON SCHEDULE EVERY 1 HOUR DO