From ab10f062f760df78f34af3b42ef19b975ab07cba Mon Sep 17 00:00:00 2001 From: Adarnof Date: Fri, 24 Mar 2017 10:03:56 -0400 Subject: [PATCH] Correct migration syntax. --- .../migrations/0015_user_profiles.py | 24 +++++++++---------- ...5.py => 0003_make_strings_more_stringy.py} | 0 ...5.py => 0004_make_strings_more_stringy.py} | 0 .../migrations/0003_default_groups.py | 12 +--------- .../migrations/0006_request_groups_perm.py | 18 -------------- ...5.py => 0002_make_strings_more_stringy.py} | 0 ...5.py => 0003_make_strings_more_stringy.py} | 0 ...5.py => 0002_make_strings_more_stringy.py} | 0 ...5.py => 0003_make_strings_more_stringy.py} | 0 ...5.py => 0003_make_strings_more_stringy.py} | 0 ...5.py => 0002_make_strings_more_stringy.py} | 0 11 files changed, 13 insertions(+), 41 deletions(-) rename corputils/migrations/{0003_auto_20170322_2335.py => 0003_make_strings_more_stringy.py} (100%) rename fleetactivitytracking/migrations/{0004_auto_20170322_2335.py => 0004_make_strings_more_stringy.py} (100%) rename hrapplications/migrations/{0002_auto_20170322_2335.py => 0002_make_strings_more_stringy.py} (100%) rename notifications/migrations/{0003_auto_20170322_2335.py => 0003_make_strings_more_stringy.py} (100%) rename optimer/migrations/{0002_auto_20170322_2335.py => 0002_make_strings_more_stringy.py} (100%) rename services/migrations/{0003_auto_20170322_2335.py => 0003_make_strings_more_stringy.py} (100%) rename srp/migrations/{0003_auto_20170322_2335.py => 0003_make_strings_more_stringy.py} (100%) rename timerboard/migrations/{0002_auto_20170322_2335.py => 0002_make_strings_more_stringy.py} (100%) diff --git a/authentication/migrations/0015_user_profiles.py b/authentication/migrations/0015_user_profiles.py index 9609c25b..ebf40a88 100644 --- a/authentication/migrations/0015_user_profiles.py +++ b/authentication/migrations/0015_user_profiles.py @@ -24,7 +24,7 @@ def create_member_state(apps, schema_editor): try: # move group permissions to state g = Group.objects.get(name=member_state_name) - s.permissions.add(g.permissions.all()) + [s.permissions.add(p.pk) for p in g.permissions.all()] g.delete() except Group.DoesNotExist: pass @@ -32,8 +32,8 @@ def create_member_state(apps, schema_editor): # auto-populate member IDs CORP_IDS = getattr(settings, 'CORP_IDS', []) ALLIANCE_IDS = getattr(settings, 'ALLIANCE_IDS', []) - s.member_corporations.add(EveCorporationInfo.objects.filter(corporation_id__in=CORP_IDS)) - s.member_alliances.add(EveAllianceInfo.objects.filter(alliance_id__in=ALLIANCE_IDS)) + [s.member_corporations.add(c.pk) for c in EveCorporationInfo.objects.filter(corporation_id__in=CORP_IDS)] + [s.member_alliances.add(a.pk) for a in EveAllianceInfo.objects.filter(alliance_id__in=ALLIANCE_IDS)] def create_member_group(apps, schema_editor): @@ -45,11 +45,11 @@ def create_member_group(apps, schema_editor): try: # move permissions back state = State.objects.get(name=member_state_name) - g.permissions.add(state.permissions.all()) + [g.permissions.add(p.pk) for p in state.permissions.all()] # move users back for profile in state.userprofile_set.all().select_related('user'): - profile.user.groups.add(g) + profile.user.groups.add(g.pk) except State.DoesNotExist: pass @@ -65,7 +65,7 @@ def create_blue_state(apps, schema_editor): try: # move group permissions to state g = Group.objects.get(name=blue_state_name) - s.permissions.add(g.permissions.all()) + [s.permissions.add(p.pk) for p in g.permissions.all()] g.permissions.clear() except Group.DoesNotExist: pass @@ -73,8 +73,8 @@ def create_blue_state(apps, schema_editor): # auto-populate blue member IDs BLUE_CORP_IDS = getattr(settings, 'BLUE_CORP_IDS', []) BLUE_ALLIANCE_IDS = getattr(settings, 'BLUE_ALLIANCE_IDS', []) - s.member_corporations.add(EveCorporationInfo.objects.filter(corporation_id__in=BLUE_CORP_IDS)) - s.member_alliances.add(EveAllianceInfo.objects.filter(alliance_id__in=BLUE_ALLIANCE_IDS)) + [s.member_corporations.add(c.pk) for c in EveCorporationInfo.objects.filter(corporation_id__in=BLUE_CORP_IDS)] + [s.member_alliances.add(a.pk) for a in EveAllianceInfo.objects.filter(alliance_id__in=BLUE_ALLIANCE_IDS)] def create_blue_group(apps, schema_editor): @@ -86,11 +86,11 @@ def create_blue_group(apps, schema_editor): try: # move permissions back state = State.objects.get(name=blue_state_name) - g.permissions.add(state.permissions.all()) + [g.permissions.add(p.pk) for p in state.permissions.all()] # move users back for profile in state.userprofile_set.all().select_related('user'): - profile.user.groups.add(g) + profile.user.groups.add(g.pk) except State.DoesNotExist: pass @@ -131,9 +131,9 @@ def create_profiles(apps, schema_editor): # carry states and mains forward profile = UserProfile.objects.get_or_create(user=auth.user.pk) state = State.objects.get(name=auth.state if auth.state else 'Guest') - profile.state = state + profile.state = state.pk char = EveCharacter.objects.get(character_id=auth.main_char_id) - profile.main_character = char + profile.main_character = char.pk profile.save() diff --git a/corputils/migrations/0003_auto_20170322_2335.py b/corputils/migrations/0003_make_strings_more_stringy.py similarity index 100% rename from corputils/migrations/0003_auto_20170322_2335.py rename to corputils/migrations/0003_make_strings_more_stringy.py diff --git a/fleetactivitytracking/migrations/0004_auto_20170322_2335.py b/fleetactivitytracking/migrations/0004_make_strings_more_stringy.py similarity index 100% rename from fleetactivitytracking/migrations/0004_auto_20170322_2335.py rename to fleetactivitytracking/migrations/0004_make_strings_more_stringy.py diff --git a/groupmanagement/migrations/0003_default_groups.py b/groupmanagement/migrations/0003_default_groups.py index c2af1db1..260aada6 100644 --- a/groupmanagement/migrations/0003_default_groups.py +++ b/groupmanagement/migrations/0003_default_groups.py @@ -5,20 +5,10 @@ from __future__ import unicode_literals from django.db import migrations from django.conf import settings -def create_groups(apps, schema_editor): - Group = apps.get_model('auth', 'Group') - Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP) - Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP) - -def reverse(apps, schema_editor): - pass - class Migration(migrations.Migration): dependencies = [ ('groupmanagement', '0002_auto_20160906_2354'), ] - operations = [ - migrations.RunPython(create_groups, reverse) - ] + operations = [] diff --git a/groupmanagement/migrations/0006_request_groups_perm.py b/groupmanagement/migrations/0006_request_groups_perm.py index d869496e..6124982a 100644 --- a/groupmanagement/migrations/0006_request_groups_perm.py +++ b/groupmanagement/migrations/0006_request_groups_perm.py @@ -12,23 +12,6 @@ import logging logger = logging.getLogger(__name__) -def add_default_member_permission(apps, schema_editor): - for app_config in apps.get_app_configs(): - app_config.models_module = True - create_permissions(app_config, apps=apps, verbosity=0) - app_config.models_module = None - - Group = apps.get_model("auth", "Group") - Permission = apps.get_model("auth", "Permission") - - try: - perm = Permission.objects.get(codename='request_groups', name='Can request non-public groups') - group = Group.objects.get(name=getattr(settings, str('DEFAULT_AUTH_GROUP'), 'Member')) - group.permissions.add(perm) - except ObjectDoesNotExist: - logger.warning('Failed to add default request_groups permission to Member group') - - class Migration(migrations.Migration): dependencies = [ @@ -40,5 +23,4 @@ class Migration(migrations.Migration): name='authgroup', options={'permissions': (('request_groups', 'Can request non-public groups'),)}, ), - migrations.RunPython(add_default_member_permission), ] diff --git a/hrapplications/migrations/0002_auto_20170322_2335.py b/hrapplications/migrations/0002_make_strings_more_stringy.py similarity index 100% rename from hrapplications/migrations/0002_auto_20170322_2335.py rename to hrapplications/migrations/0002_make_strings_more_stringy.py diff --git a/notifications/migrations/0003_auto_20170322_2335.py b/notifications/migrations/0003_make_strings_more_stringy.py similarity index 100% rename from notifications/migrations/0003_auto_20170322_2335.py rename to notifications/migrations/0003_make_strings_more_stringy.py diff --git a/optimer/migrations/0002_auto_20170322_2335.py b/optimer/migrations/0002_make_strings_more_stringy.py similarity index 100% rename from optimer/migrations/0002_auto_20170322_2335.py rename to optimer/migrations/0002_make_strings_more_stringy.py diff --git a/services/migrations/0003_auto_20170322_2335.py b/services/migrations/0003_make_strings_more_stringy.py similarity index 100% rename from services/migrations/0003_auto_20170322_2335.py rename to services/migrations/0003_make_strings_more_stringy.py diff --git a/srp/migrations/0003_auto_20170322_2335.py b/srp/migrations/0003_make_strings_more_stringy.py similarity index 100% rename from srp/migrations/0003_auto_20170322_2335.py rename to srp/migrations/0003_make_strings_more_stringy.py diff --git a/timerboard/migrations/0002_auto_20170322_2335.py b/timerboard/migrations/0002_make_strings_more_stringy.py similarity index 100% rename from timerboard/migrations/0002_auto_20170322_2335.py rename to timerboard/migrations/0002_make_strings_more_stringy.py