-
-
Notifications
You must be signed in to change notification settings - Fork 290
Migrate User fields to MemberProfile (PR 1: Schema & Sync) #2686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| from apps.common.models import BATCH_SIZE | ||
| from apps.github.models.repository_contributor import RepositoryContributor | ||
| from apps.github.models.user import User | ||
| from apps.owasp.models.member_profile import MemberProfile | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -46,14 +47,35 @@ def handle(self, *args, **options): | |
| .annotate(total_contributions=Sum("contributions_count")) | ||
| } | ||
| users = [] | ||
| profiles = [] | ||
| for idx, user in enumerate(active_users[offset:]): | ||
| prefix = f"{idx + offset + 1} of {active_users_count - offset}" | ||
| print(f"{prefix:<10} {user.title}") | ||
|
|
||
| user.contributions_count = user_contributions.get(user.id, 0) | ||
| users.append(user) | ||
|
|
||
| profile, created = MemberProfile.objects.get_or_create(github_user_id=user.id) | ||
| if created: | ||
| profile.github_user = user | ||
| profile.contributions_count = user.contributions_count | ||
| profile.is_owasp_staff = user.is_owasp_staff | ||
| profile.has_public_member_page = user.has_public_member_page | ||
|
||
| profiles.append(profile) | ||
|
|
||
| if not len(users) % BATCH_SIZE: | ||
| User.bulk_save(users, fields=("contributions_count",)) | ||
| MemberProfile.bulk_save( | ||
| profiles, | ||
| fields=( | ||
| "contributions_count", | ||
| "is_owasp_staff", | ||
| "has_public_member_page", | ||
| ), | ||
| ) | ||
|
|
||
| User.bulk_save(users, fields=("contributions_count",)) | ||
| MemberProfile.bulk_save( | ||
| profiles, | ||
| fields=("contributions_count", "is_owasp_staff", "has_public_member_page"), | ||
| ) | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Generated by Django 5.2.7 on 2025-11-18 17:59 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('owasp', '0065_memberprofile_linkedin_page_id'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='memberprofile', | ||
| name='contributions_count', | ||
| field=models.PositiveIntegerField(default=0, verbose_name='Contributions count'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='memberprofile', | ||
| name='has_public_member_page', | ||
| field=models.BooleanField(default=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='memberprofile', | ||
| name='is_owasp_staff', | ||
| field=models.BooleanField(default=False, help_text='Indicates if the user is OWASP Foundation staff.', verbose_name='Is OWASP Staff'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Generated by Django 5.2.7 on 2025-11-18 18:04 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
| def copy_user_data_to_member_profile(apps, schema_editor): | ||
| User = apps.get_model('github', 'User') | ||
| MemberProfile = apps.get_model('owasp', 'MemberProfile') | ||
| for user in User.objects.all(): | ||
| profile, _ = MemberProfile.objects.get_or_create(github_user=user) | ||
| profile.has_public_member_page = user.has_public_member_page | ||
| profile.is_owasp_staff = user.is_owasp_staff | ||
| profile.contributions_count = user.contributions_count | ||
| profile.save() | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('owasp', '0066_memberprofile_contributions_count_and_more'), | ||
| ('github', '0039_remove_commit_commit_repo_created_idx'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(copy_user_data_to_member_profile, migrations.RunPython.noop), | ||
| ] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command was originally made for updating the
GitHub.Usercontributions count. So, I suggest to move this command toOwaspapp and only update the contributions count ofMemberProfile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you asked, I created a new member profile update in the owasp folder only updating contributions_count,
so far a few changes are still pending. I’ll have this PR ready for review soon. (I have exams going on, so my time is a bit limited, but I’ll do my best to finish this in the next 24 hour)