Browse Source

Finish migration to v2.

tags/v1.0^2
Ben Kurtovic 10 years ago
parent
commit
0b655daaff
3 changed files with 19 additions and 7 deletions
  1. +2
    -0
      bitshift/database/__init__.py
  2. +15
    -6
      bitshift/database/migration.py
  3. +2
    -1
      bitshift/database/schema.sql

+ 2
- 0
bitshift/database/__init__.py View File

@@ -29,8 +29,10 @@ class Database(object):
def _migrate(self, cursor, current):
"""Migrate the database to the latest schema version."""
for version in xrange(current, VERSION):
print "Migrating to %d..." % version + 1
for query in MIGRATIONS[version - 1]:
cursor.execute(query)
cursor.execute("UPDATE version SET version = ?", (version + 1,))

def _check_version(self, migrate):
"""Check the database schema version and respond accordingly.


+ 15
- 6
bitshift/database/migration.py View File

@@ -8,12 +8,21 @@ VERSION = 2
MIGRATIONS = [
# 1 -> 2
[
# drop index on code_hash
"ALTER TABLE code DROP COLUMN code_hash",
# change code_id to BIGINT NOT NULL,
# add key on codelets to codelet_lang
# add symbol_end_row INT UNSIGNED NOT NULL
# add symbol_end_col INT UNSIGNED NOT NULL
"""ALTER TABLE `codelets`
DROP FOREIGN KEY `codelets_ibfk_1`""",
"""ALTER TABLE `code`
DROP KEY `code_hash`,
DROP COLUMN `code_hash`,
MODIFY COLUMN `code_id` BIGINT NOT NULL""",
"""ALTER TABLE `codelets`
MODIFY COLUMN `codelet_code_id` BIGINT NOT NULL,
ADD KEY (`codelet_lang`),
ADD 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
- 1
bitshift/database/schema.sql View File

@@ -6,6 +6,7 @@ USE `bitshift`;
CREATE TABLE `version` (
`version` INT UNSIGNED NOT NULL
) ENGINE=InnoDB;
INSERT INTO `version` VALUES (2);

CREATE TABLE `origins` (
`origin_id` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
@@ -26,7 +27,7 @@ CREATE TABLE `code` (
CREATE TABLE `codelets` (
`codelet_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`codelet_name` VARCHAR(300) NOT NULL,
`codelet_code_id` BIGINT UNSIGNED NOT NULL,
`codelet_code_id` BIGINT NOT NULL,
`codelet_lang` SMALLINT UNSIGNED DEFAULT NULL,
`codelet_origin` TINYINT UNSIGNED NOT NULL,
`codelet_url` VARCHAR(512) NOT NULL,


Loading…
Cancel
Save