diff --git a/README.md b/README.md index f7e97af5..943963b9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docker-compose.yml b/docker-compose.yml index 760258de..380df336 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.7' services: postgres: image: postgis/postgis:13-3.2-alpine diff --git a/profiles/migrations/0058_alter_profile_first_name_alter_profile_last_name.py b/profiles/migrations/0058_alter_profile_first_name_alter_profile_last_name.py new file mode 100644 index 00000000..fe061154 --- /dev/null +++ b/profiles/migrations/0058_alter_profile_first_name_alter_profile_last_name.py @@ -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) + ) + + +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 + ), + ), + ] diff --git a/profiles/models.py b/profiles/models.py index 86f77350..5a451497 100644 --- a/profiles/models.py +++ b/profiles/models.py @@ -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, diff --git a/profiles/tests/test_models.py b/profiles/tests/test_models.py index 274e3c2f..5560047a 100644 --- a/profiles/tests/test_models.py +++ b/profiles/tests/test_models.py @@ -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(