Skip to content

Commit

Permalink
Fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
robindymer committed Nov 8, 2023
1 parent 0f2ce3a commit 3d5b531
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='member',
name='unicore_id',
name='melos_id',
field=models.IntegerField(blank=True, editable=False, null=True),
),
migrations.RunPython(nullify_columns),
Expand All @@ -47,4 +47,4 @@ class Migration(migrations.Migration):
name='status',
field=models.CharField(blank=True, null=True, default='', max_length=130),
),
]
]
4 changes: 2 additions & 2 deletions src/members/migrations/0008_auto_20191203_1447.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
('members', '0007_member_unicore_id'),
('members', '0007_member_melos_id'),
]

operations = [
Expand Down Expand Up @@ -48,4 +48,4 @@ class Migration(migrations.Migration):
name='status',
field=models.CharField(choices=[('unknown', 'Unknown'), ('nonmember', 'Nonmember'), ('member', 'Member'), ('alumnus', 'Alumnus')], default='unknown', max_length=20, verbose_name='Membership status'),
),
]
]
4 changes: 2 additions & 2 deletions src/members/migrations/0009_auto_20191206_1435.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='member',
name='unicore_id',
name='melos_id',
field=models.IntegerField(blank=True, editable=False, null=True, unique=True),
),
]
]
18 changes: 9 additions & 9 deletions src/members/migrations/0013_auto_20201217_1503.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
from django.db.models import Q
from utils.unicore_client import UnicoreClient

# This is a copy of the function used to get the unicore
# This is a copy of the function used to get the melos
# data for a member. The reason it is copied is that django migrations
# don't have access to model functions. The solution for this is to
# make a copy of the functions that populates the fields. This also
# makes sure that this migration file will work in the future, regardless
# of the changes to the Member model
def fetch_and_save_unicore_info(unicore_id):
unicore_data = UnicoreClient.get_user_data(unicore_id)
if unicore_data is not None:
def fetch_and_save_melos_info(melos_id):
melos_data = UnicoreClient.get_user_data(melos_id)
if melos_data is not None:
name = "{} {}".format(
unicore_data['first_name'].strip(),
unicore_data['last_name'].strip()
melos_data['first_name'].strip(),
melos_data['last_name'].strip()
)
person_nr = unicore_data['person_number']
person_nr = melos_data['person_number']
return name, person_nr

return None, None
Expand All @@ -27,7 +27,7 @@ def get_user_info(apps, schema_editor):
iterations = 1
members_to_update = Member.objects.filter(Q(name="") | Q(person_nr=""))
for member in members_to_update:
name, person_nr = fetch_and_save_unicore_info(member.unicore_id)
name, person_nr = fetch_and_save_melos_info(member.melos_id)
if name is None:
print("Could not fetch data for user {}".format(member.username))
else:
Expand Down Expand Up @@ -56,4 +56,4 @@ class Migration(migrations.Migration):
get_user_info,
reverse_code=migrations.RunPython.noop
)
]
]
18 changes: 18 additions & 0 deletions src/members/migrations/0015_rename_melos_id_member_unicore_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.17 on 2023-11-08 18:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('members', '0014_auto_20201217_1522'),
]

operations = [
migrations.RenameField(
model_name='member',
old_name='melos_id',
new_name='unicore_id',
),
]

0 comments on commit 3d5b531

Please sign in to comment.