-
Notifications
You must be signed in to change notification settings - Fork 557
✨(backend) add a is_first_connection flag to the User model #1938
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/backend/core/migrations/0030_user_is_first_connection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Generated by Django 5.2.11 on 2026-03-04 14:49 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def set_is_first_connection_false(apps, schema_editor): | ||
| """Update all existing user.is_first_connection to False.""" | ||
| user = apps.get_model("core", "User") | ||
|
|
||
| user.objects.update(is_first_connection=False) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("core", "0029_userreconciliationcsvimport_userreconciliation"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="user", | ||
| name="is_first_connection", | ||
| field=models.BooleanField( | ||
| default=True, | ||
| help_text="Whether the user has completed the first connection process.", | ||
| verbose_name="first connection status", | ||
| ), | ||
| ), | ||
| migrations.RunPython( | ||
| set_is_first_connection_false, | ||
| reverse_code=migrations.RunPython.noop, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/backend/core/tests/migrations/test_migrations_0018_update_blank_title.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import pytest | ||
|
|
||
| from core import models | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| def test_update_blank_title_migration(migrator): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/backend/core/tests/migrations/test_migrations_0030_user_is_first_connection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Module testing migration 0030 about adding is_first_connection to user model.""" | ||
|
|
||
| from django.contrib.auth.hashers import make_password | ||
|
|
||
| import factory | ||
| import pytest | ||
|
|
||
| from core import models | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| def test_set_is_first_connection_false(migrator): | ||
| """ | ||
| Test that once the migration adding is_first_connection column to user model is applied | ||
| all existing user have the False value. | ||
| """ | ||
| old_state = migrator.apply_initial_migration( | ||
| ("core", "0029_userreconciliationcsvimport_userreconciliation") | ||
| ) | ||
| OldUser = old_state.apps.get_model("core", "User") | ||
|
|
||
| old_user1 = OldUser.objects.create( | ||
| email="email1@example.com", sub="user1", password=make_password("password") | ||
| ) | ||
| old_user2 = OldUser.objects.create( | ||
| email="email2@example.com", sub="user2", password=make_password("password") | ||
| ) | ||
|
|
||
| assert hasattr(old_user1, "is_first_connection") is False | ||
| assert hasattr(old_user2, "is_first_connection") is False | ||
|
|
||
| # # Apply the migration | ||
| new_state = migrator.apply_tested_migration( | ||
| ("core", "0030_user_is_first_connection") | ||
| ) | ||
|
|
||
| NewUser = new_state.apps.get_model("core", "User") | ||
|
|
||
| updated_user1 = NewUser.objects.get(id=old_user1.id) | ||
|
|
||
| assert updated_user1.is_first_connection is False | ||
|
|
||
| updated_user2 = NewUser.objects.get(id=old_user2.id) | ||
|
|
||
| assert updated_user2.is_first_connection is False | ||
|
|
||
| # create a new user after migration | ||
|
|
||
| new_user1 = NewUser.objects.create( | ||
| email="email3example.com", sub="user3", password=make_password("password") | ||
| ) | ||
| assert new_user1.is_first_connection is True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.