From 3d5b5312653f973e4fb3d86e692e61aae1512b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Dym=C3=A9r?= Date: Wed, 8 Nov 2023 19:28:42 +0100 Subject: [PATCH] Fix migrations --- ...r_unicore_id.py => 0007_member_melos_id.py} | 4 ++-- .../migrations/0008_auto_20191203_1447.py | 4 ++-- .../migrations/0009_auto_20191206_1435.py | 4 ++-- .../migrations/0013_auto_20201217_1503.py | 18 +++++++++--------- .../0015_rename_melos_id_member_unicore_id.py | 18 ++++++++++++++++++ 5 files changed, 33 insertions(+), 15 deletions(-) rename src/members/migrations/{0007_member_unicore_id.py => 0007_member_melos_id.py} (97%) create mode 100644 src/members/migrations/0015_rename_melos_id_member_unicore_id.py diff --git a/src/members/migrations/0007_member_unicore_id.py b/src/members/migrations/0007_member_melos_id.py similarity index 97% rename from src/members/migrations/0007_member_unicore_id.py rename to src/members/migrations/0007_member_melos_id.py index 0c667ced..0660d013 100644 --- a/src/members/migrations/0007_member_unicore_id.py +++ b/src/members/migrations/0007_member_melos_id.py @@ -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), @@ -47,4 +47,4 @@ class Migration(migrations.Migration): name='status', field=models.CharField(blank=True, null=True, default='', max_length=130), ), - ] + ] \ No newline at end of file diff --git a/src/members/migrations/0008_auto_20191203_1447.py b/src/members/migrations/0008_auto_20191203_1447.py index cf46376c..b51bcdc8 100644 --- a/src/members/migrations/0008_auto_20191203_1447.py +++ b/src/members/migrations/0008_auto_20191203_1447.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ('members', '0007_member_unicore_id'), + ('members', '0007_member_melos_id'), ] operations = [ @@ -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'), ), - ] + ] \ No newline at end of file diff --git a/src/members/migrations/0009_auto_20191206_1435.py b/src/members/migrations/0009_auto_20191206_1435.py index 23cb8b97..957083f7 100644 --- a/src/members/migrations/0009_auto_20191206_1435.py +++ b/src/members/migrations/0009_auto_20191206_1435.py @@ -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), ), - ] + ] \ No newline at end of file diff --git a/src/members/migrations/0013_auto_20201217_1503.py b/src/members/migrations/0013_auto_20201217_1503.py index 99e2a52d..c15a4758 100644 --- a/src/members/migrations/0013_auto_20201217_1503.py +++ b/src/members/migrations/0013_auto_20201217_1503.py @@ -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 @@ -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: @@ -56,4 +56,4 @@ class Migration(migrations.Migration): get_user_info, reverse_code=migrations.RunPython.noop ) - ] + ] \ No newline at end of file diff --git a/src/members/migrations/0015_rename_melos_id_member_unicore_id.py b/src/members/migrations/0015_rename_melos_id_member_unicore_id.py new file mode 100644 index 00000000..9f7c4a7a --- /dev/null +++ b/src/members/migrations/0015_rename_melos_id_member_unicore_id.py @@ -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', + ), + ]