1import common 2from autotest_lib.database import db_utils 3 4UP_SQL = """ 5SET @group_id = (SELECT id FROM auth_group WHERE name = 'Basic Admin'); 6 7INSERT IGNORE INTO auth_group_permissions (group_id, permission_id) 8SELECT @group_id, id FROM auth_permission WHERE codename IN ( 9 'add_hostattribute', 'change_hostattribute', 'delete_hostattribute'); 10""" 11 12DOWN_SQL = """ 13DELETE auth_group_permissions.* FROM 14auth_group INNER JOIN auth_group_permissions ON ( 15 auth_group.id = auth_group_permissions.group_id) 16INNER JOIN auth_permission ON ( 17 auth_group_permissions.permission_id = auth_permission.id) 18WHERE auth_group.name = 'Basic Admin' AND codename IN ( 19 'add_hostattribute', 'change_hostattribute', 'delete_hostattribute'); 20""" 21 22 23def migrate_up(manager): 24 if db_utils.auth_tables_exist(manager): 25 manager.execute_script(UP_SQL) 26 27 28def migrate_down(manager): 29 if db_utils.auth_tables_exist(manager): 30 manager.execute_script(DOWN_SQL) 31