Skip to content
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

HP-2344 | Shorten profile name fields to 150 characters #488

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ This repository contains `requirements*.in` and corresponding `requirements*.txt
This project uses
[`black`](https://github.com/ambv/black),
[`flake8`](https://gitlab.com/pycqa/flake8) and
[`isort`](https://github.com/timothycrosley/isort)
[`isort`](https://github.com/pycqa/isort)
for code formatting and quality checking. Project follows the basic
black config, without any modifications.

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
postgres:
image: postgis/postgis:13-3.2-alpine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.9 on 2024-04-17 10:00

from django.db import migrations
from django.db.models.functions import Substr

import utils.fields


def truncate_name_fields(apps, schema_editor):
Profile = apps.get_model("profiles", "Profile")
Profile.objects.update(
first_name=Substr("first_name", 1, 150), last_name=Substr("last_name", 1, 150)
)
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.



class Migration(migrations.Migration):

dependencies = [
("profiles", "0057_remove_profile_id_default_value__noop"),
]

operations = [
migrations.RunPython(truncate_name_fields, migrations.RunPython.noop),
migrations.AlterField(
model_name="profile",
name="first_name",
field=utils.fields.NullToEmptyCharField(
blank=True, db_index=True, max_length=150
),
),
migrations.AlterField(
model_name="profile",
name="last_name",
field=utils.fields.NullToEmptyCharField(
blank=True, db_index=True, max_length=150
),
),
]
4 changes: 2 additions & 2 deletions profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

class Profile(UUIDModel, SerializableMixin):
user = models.OneToOneField(User, on_delete=models.PROTECT, null=True, blank=True)
first_name = NullToEmptyCharField(max_length=255, blank=True, db_index=True)
last_name = NullToEmptyCharField(max_length=255, blank=True, db_index=True)
first_name = NullToEmptyCharField(max_length=150, blank=True, db_index=True)
last_name = NullToEmptyCharField(max_length=150, blank=True, db_index=True)
nickname = NullToEmptyCharField(max_length=32, blank=True, db_index=True)
language = models.CharField(
max_length=2,
Expand Down
2 changes: 1 addition & 1 deletion profiles/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def execute_string_field_max_length_validation_test(
class TestProfileValidation(ValidationTestBase):
@pytest.mark.parametrize(
"field_name,max_length",
[("first_name", 255), ("last_name", 255), ("nickname", 32)],
[("first_name", 150), ("last_name", 150), ("nickname", 32)],
)
def test_string_field_max_length(self, field_name, max_length, profile):
self.execute_string_field_max_length_validation_test(
Expand Down