blob: a3eb8788bbf0e48a3b2adfb7f71be7dfcdcf1849 [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)
15 if (tko_manager.get_db_version() < 31):
16 raise Exception('You must update the TKO database to the latest '
17 'version before merging')
18
19 if not manager.force:
20 response = raw_input(
21 'This migration will merge the autotest_web and tko databases. '
22 'Following the migration, the tko database will be dropped. '
23 'Any user-added tables in tko will NOT be migrated. This '
24 'migration is NOT reversible. Are you sure you want to '
25 'continue? (yes/no) ')
26 if response != 'yes':
27 raise Exception('User has chosen to abort migration')
28
29 db_utils.move_tables(manager, tko_manager, TABLE_NAMES)
30 db_utils.drop_database(tko_manager)
31 manager.execute_script(tko_migration.RECREATE_VIEWS_UP)
32
33
34def migrate_down(manager):
35 raise Exception('Migration 46 is not reversible!')