Add downgrade support to migrate. This is really necessary for doing real migration development. Modified all existing migrations to support it.
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1336 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/migrations/001_initial_db.py b/tko/migrations/001_initial_db.py
index cf237d6..2c19abc 100755
--- a/tko/migrations/001_initial_db.py
+++ b/tko/migrations/001_initial_db.py
@@ -4,7 +4,6 @@
'iteration_result')
def migrate_up(manager):
- assert not manager.check_migrate_table_exists()
manager.execute("SHOW TABLES")
tables = [row[0] for row in manager.cursor.fetchall()]
db_initialized = True
@@ -25,7 +24,11 @@
manager.create_migrate_table()
-CREATE_DB_SQL = """\
+def migrate_down(manager):
+ manager.execute_script(DROP_DB_SQL)
+
+
+DROP_DB_SQL = """\
-- drop all views (since they depend on some or all of the following tables)
DROP VIEW IF EXISTS test_view;
DROP VIEW IF EXISTS perf_view;
@@ -39,7 +42,10 @@
DROP TABLE IF EXISTS machines;
DROP TABLE IF EXISTS kernels;
DROP TABLE IF EXISTS status;
+"""
+
+CREATE_DB_SQL = DROP_DB_SQL + """\
-- status key
CREATE TABLE status (
status_idx int(10) unsigned NOT NULL auto_increment PRIMARY KEY , -- numerical status