Home | History | Annotate | Download | only in migrations
      1 from django.core import management
      2 import common
      3 from autotest_lib.frontend import settings
      4 from autotest_lib.database import db_utils
      5 
      6 AFE_MIGRATION_NAME = '059_drone_sets_permissions'
      7 migrations_module = __import__('autotest_lib.frontend.migrations', globals(),
      8                                locals(), [AFE_MIGRATION_NAME])
      9 migration_059 = getattr(migrations_module, AFE_MIGRATION_NAME)
     10 
     11 
     12 def migrate_up(manager):
     13     """
     14     If the auth tables don't exist, we shouldn't try to set the permissions.
     15 
     16     See migration 059
     17     """
     18     if db_utils.auth_tables_exist(manager):
     19         management.setup_environ(settings)
     20         # These have to be imported after the environment is set up
     21         from django.contrib.contenttypes import management as content_management
     22         from django.contrib.auth import management as auth_management
     23         from django.db import models as db_models
     24 
     25         content_management.update_all_contenttypes()
     26         for app in db_models.get_apps():
     27             auth_management.create_permissions(app, None, 2)
     28 
     29         manager.execute_script(migration_059.UP_SQL)
     30 
     31 
     32 def migrate_down(manager):
     33     if db_utils.auth_tables_exist(manager):
     34         manager.execute_script(migration_059.DOWN_SQL)
     35