Skip to content

Commit

Permalink
revert: #4817
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Nov 20, 2024
1 parent a33633f commit 3d3f53a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 93 deletions.
51 changes: 3 additions & 48 deletions api/users/migrations/0039_alter_ffadminuser_first_name.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# Generated by Django 4.2.16 on 2024-11-04 17:09
from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.models import F
from django.db.models.functions import Left


def populate_new_first_name_field(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
FFAdminUser = apps.get_model("users", "FFAdminUser")

FFAdminUser.objects.update(first_name_v2=F("first_name"))


def populate_old_first_name_field(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
FFAdminUser = apps.get_model("users", "FFAdminUser")

FFAdminUser.objects.update(first_name=Left("first_name_v2", 30))


class Migration(migrations.Migration):
Expand All @@ -25,38 +9,9 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AddField(
migrations.AlterField(
model_name="ffadminuser",
name="first_name_v2",
field=models.CharField(max_length=150, default=""),
name="first_name",
field=models.CharField(max_length=150, verbose_name="first name"),
),
migrations.RunPython(populate_new_first_name_field, reverse_code=populate_old_first_name_field),
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.RenameField(
model_name="ffadminuser",
old_name="first_name",
new_name="_first_name_old",
),
migrations.RenameField(
model_name="ffadminuser",
old_name="first_name_v2",
new_name="first_name",
),
migrations.AlterField(
model_name="ffadminuser",
name="_first_name_old",
field=models.CharField(
db_column="first_name", max_length=30, verbose_name="first name"
),
),
migrations.AlterField(
model_name="ffadminuser",
name="first_name",
field=models.CharField(
db_column="first_name_v2", max_length=150, verbose_name="first name"
),
),
]
)
]
42 changes: 0 additions & 42 deletions api/users/migrations/0040_alter_ffadminuser_first_name_fix.py

This file was deleted.

4 changes: 1 addition & 3 deletions api/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ class FFAdminUser(LifecycleModel, AbstractUser):
email = models.EmailField(unique=True, null=False)
objects = UserManager()
username = models.CharField(unique=True, max_length=150, null=True, blank=True)
first_name = models.CharField(
"first name", max_length=150, db_column="first_name_v2"
)
first_name = models.CharField("first name", max_length=150)
last_name = models.CharField("last name", max_length=150)
google_user_id = models.CharField(max_length=50, null=True, blank=True)
github_user_id = models.CharField(max_length=50, null=True, blank=True)
Expand Down

0 comments on commit 3d3f53a

Please sign in to comment.