From fb341d5abdb09688c6308f2cc94abcfb5295d6c3 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 6 Jun 2014 12:58:55 -0400 Subject: [PATCH] empty_database procedure. --- bitshift/database/migration.py | 17 ++++++++++++++++- bitshift/database/schema.sql | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) 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