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