showard | 250d84d | 2010-01-12 21:59:48 +0000 | [diff] [blame] | 1 | import common |
| 2 | from autotest_lib.database import db_utils, migrate |
| 3 | |
| 4 | TKO_MIGRATION_NAME = '031_rename_tko_tables' |
| 5 | migrations_module = __import__('autotest_lib.tko.migrations', globals(), |
| 6 | locals(), [TKO_MIGRATION_NAME]) |
| 7 | tko_migration = getattr(migrations_module, TKO_MIGRATION_NAME) |
| 8 | |
| 9 | TABLE_NAMES = tko_migration.RENAMES_UP.values() |
| 10 | |
| 11 | |
| 12 | def migrate_up(manager): |
| 13 | tko_manager = migrate.get_migration_manager(db_name='TKO', debug=False, |
| 14 | force=False) |
showard | 82e1b48 | 2010-01-15 00:21:58 +0000 | [diff] [blame] | 15 | 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') |
showard | 250d84d | 2010-01-12 21:59:48 +0000 | [diff] [blame] | 18 | |
showard | 12454c6 | 2010-01-15 19:15:14 +0000 | [diff] [blame] | 19 | if manager.simulate: |
| 20 | tko_manager.initialize_and_fill_test_db() |
| 21 | |
showard | 250d84d | 2010-01-12 21:59:48 +0000 | [diff] [blame] | 22 | 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 | |
| 37 | def migrate_down(manager): |
| 38 | raise Exception('Migration 46 is not reversible!') |