blob: f73dc74897f697bb3b6e76e60a812a4623ef5855 [file] [log] [blame]
showard250d84d2010-01-12 21:59:48 +00001import common
2from autotest_lib.database import db_utils, migrate
3
4TKO_MIGRATION_NAME = '031_rename_tko_tables'
5migrations_module = __import__('autotest_lib.tko.migrations', globals(),
6 locals(), [TKO_MIGRATION_NAME])
7tko_migration = getattr(migrations_module, TKO_MIGRATION_NAME)
8
9TABLE_NAMES = tko_migration.RENAMES_UP.values()
10
11
12def migrate_up(manager):
13 tko_manager = migrate.get_migration_manager(db_name='TKO', debug=False,
14 force=False)
showard82e1b482010-01-15 00:21:58 +000015 if tko_manager.get_db_version() < 31:
16 raise Exception('You must update the TKO database to at least version '
17 '31 before applying AUTOTEST_WEB migration 46')
showard250d84d2010-01-12 21:59:48 +000018
showard12454c62010-01-15 19:15:14 +000019 if manager.simulate:
20 tko_manager.initialize_and_fill_test_db()
21
showard250d84d2010-01-12 21:59:48 +000022 if not manager.force:
23 response = raw_input(
24 'This migration will merge the autotest_web and tko databases. '
25 'Following the migration, the tko database will be dropped. '
26 'Any user-added tables in tko will NOT be migrated. This '
27 'migration is NOT reversible. Are you sure you want to '
28 'continue? (yes/no) ')
29 if response != 'yes':
30 raise Exception('User has chosen to abort migration')
31
32 db_utils.move_tables(manager, tko_manager, TABLE_NAMES)
33 db_utils.drop_database(tko_manager)
34 manager.execute_script(tko_migration.RECREATE_VIEWS_UP)
35
36
37def migrate_down(manager):
38 raise Exception('Migration 46 is not reversible!')