'This migration has been customized to support upgrades from Cloudera
Enterprise 3.5, as well as Hue 1.2'

def forwards(self, orm):

    if ('userman_groupadministrator' in connection.introspection.table_names()):
        db.delete_table('userman_groupadministrator')
    if ('userman_grouprelations' in connection.introspection.table_names()):
        db.delete_table('userman_grouprelations')
    if ('userman_userprofile' in connection.introspection.table_names()):
        db.rename_table('userman_userprofile', 'useradmin_userprofile')
        db.delete_column('useradmin_userprofile', 'primary_group_id')
        db.create_index('useradmin_userprofile', ['user_id'])
        db.alter_column('useradmin_userprofile', 'creation_method', models.CharField(editable=True, null=False, max_length=64, default=UserProfile.CreationMethod.HUE))
        for up in UserProfile.objects.all():
            if (up.creation_method == '1'):
                up.creation_method = UserProfile.CreationMethod.EXTERNAL
            elif (up.creation_method == '0'):
                up.creation_method = UserProfile.CreationMethod.HUE
            up.save()
    else:
        db.create_table('useradmin_userprofile', (('home_directory', self.gf('django.db.models.fields.CharField')(max_length=1024, null=True)), ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], unique=True))))
        db.commit_transaction()
        db.start_transaction()
        db.send_create_signal('useradmin', ['UserProfile'])
    if ('userman_grouppermission' in connection.introspection.table_names()):
        db.rename_table('userman_grouppermission', 'useradmin_grouppermission')
        db.rename_column('useradmin_grouppermission', 'desktop_permission_id', 'hue_permission_id')
        db.create_index('useradmin_grouppermission', ['group_id'])
        db.create_index('useradmin_grouppermission', ['hue_permission_id'])
    else:
        db.create_table('useradmin_grouppermission', (('hue_permission', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['useradmin.HuePermission'])), ('group', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.Group'])), ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True))))
        db.commit_transaction()
        db.start_transaction()
        db.send_create_signal('useradmin', ['GroupPermission'])
    if ('userman_desktoppermission' in connection.introspection.table_names()):
        db.rename_table('userman_desktoppermission', 'useradmin_huepermission')
    else:
        db.create_table('useradmin_huepermission', (('action', self.gf('django.db.models.fields.CharField')(max_length=100)), ('app', self.gf('django.db.models.fields.CharField')(max_length=30)), ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('description', self.gf('django.db.models.fields.CharField')(max_length=255))))
        db.commit_transaction()
        db.start_transaction()
        db.send_create_signal('useradmin', ['HuePermission'])
