From 821a6ae4f1a30c2b8b4575c408145f8b34877206 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 30 Apr 2014 14:44:31 -0400 Subject: [PATCH] DB -> v3 for symbol->code assoc vs. ->codelet (fixes #13) --- bitshift/database/migration.py | 13 +++++++++++-- bitshift/database/schema.sql | 10 +++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/bitshift/database/migration.py b/bitshift/database/migration.py index 2ea9666..caf3020 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 = 2 +VERSION = 3 MIGRATIONS = [ # 1 -> 2 @@ -17,12 +17,21 @@ MIGRATIONS = [ """ALTER TABLE `codelets` MODIFY COLUMN `codelet_code_id` BIGINT NOT NULL, ADD KEY (`codelet_lang`), - ADD FOREIGN KEY (`codelet_code_id`) + ADD CONSTRAINT `codelets_ibfk_1` FOREIGN KEY (`codelet_code_id`) REFERENCES `code` (`code_id`) ON DELETE RESTRICT ON UPDATE CASCADE""", """ALTER TABLE `symbols` ADD COLUMN `symbol_end_row` INT UNSIGNED NOT NULL, ADD COLUMN `symbol_end_col` INT UNSIGNED NOT NULL""" + ], + # 2 -> 3 + [ + """ALTER TABLE `symbols` + DROP FOREIGN KEY `symbols_ibfk_1`, + CHANGE COLUMN `symbol_codelet` `symbol_code` BIGINT NOT NULL, + ADD CONSTRAINT `symbols_ibfk_1` FOREIGN KEY (`symbol_code`) + REFERENCES `code` (`code_id`) + ON DELETE CASCADE ON UPDATE CASCADE""" ] ] diff --git a/bitshift/database/schema.sql b/bitshift/database/schema.sql index 56a2d85..99b9e42 100644 --- a/bitshift/database/schema.sql +++ b/bitshift/database/schema.sql @@ -1,4 +1,4 @@ --- Schema version 2 +-- Schema version 3 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 (2); +INSERT INTO `version` VALUES (3); CREATE TABLE `origins` ( `origin_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -62,7 +62,7 @@ CREATE TABLE `authors` ( CREATE TABLE `symbols` ( `symbol_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `symbol_codelet` BIGINT UNSIGNED NOT NULL, + `symbol_code` BIGINT NOT NULL, `symbol_type` TINYINT UNSIGNED NOT NULL, `symbol_name` VARCHAR(512) NOT NULL, `symbol_row` INT UNSIGNED NOT NULL, @@ -71,8 +71,8 @@ CREATE TABLE `symbols` ( `symbol_end_col` INT UNSIGNED NOT NULL, PRIMARY KEY (`symbol_id`), KEY (`symbol_type`, `symbol_name`(32)), - FOREIGN KEY (`symbol_codelet`) - REFERENCES `codelets` (`codelet_id`) + FOREIGN KEY (`symbol_code`) + REFERENCES `code` (`code_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB;