KVM test: kvm_config: add helper to raise exception informing line number
[autotest-zwu.git] / frontend / migrations / 059_drone_sets_permissions.py
bloba5d2cccdcdfde949d75fa937ee6ba6a5a960329c
1 import common
2 from autotest_lib.database import db_utils
4 UP_SQL = """
5 SET @group_id = (SELECT id FROM auth_group WHERE name = 'Basic Admin');
7 INSERT IGNORE INTO auth_group_permissions (group_id, permission_id)
8 SELECT @group_id, id FROM auth_permission WHERE codename IN (
9 'add_droneset', 'change_droneset', 'delete_droneset', 'add_drone',
10 'change_drone', 'delete_drone');
11 """
13 DOWN_SQL = """
14 DELETE auth_group_permissions.* FROM
15 auth_group INNER JOIN auth_group_permissions ON (
16 auth_group.id = auth_group_permissions.group_id)
17 INNER JOIN auth_permission ON (
18 auth_group_permissions.permission_id = auth_permission.id)
19 WHERE auth_group.name = 'Basic Admin' AND codename IN (
20 'add_droneset', 'change_droneset', 'delete_droneset', 'add_drone',
21 'change_drone', 'delete_drone');
22 """
25 def migrate_up(manager):
26 """
27 If the auth tables don't exist, we shouldn't try to set the permissions.
29 The auth tables will exist if this is an existing Autotest installation. If
30 they don't, then this is a fresh installation, and the user will run
31 `manage.py syncdb` later, which will add the proper permissions.
32 """
33 if db_utils.auth_tables_exist(manager):
34 manager.execute_script(UP_SQL)
37 def migrate_down(manager):
38 if db_utils.auth_tables_exist(manager):
39 manager.execute_script(DOWN_SQL)