Skip to content

Commit

Permalink
Safer migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Feb 9, 2024
1 parent 10edcd9 commit 5808181
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor

from projects.tags.models import TagType

PROTECTED_LABELS = {"protected", "donotdelete", "permanent"}
LABEL_REGEX = re.compile(r"[ _]")
Expand Down Expand Up @@ -36,6 +37,14 @@ def mark_existing_tags_as_permanent(
tag_class.objects.bulk_update(to_update, fields=["is_permanent"])


def populate_default_tag_type(
apps: Apps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
apps.get_model("tags", "tag").objects.filter(type__isnull=True).update(
type=TagType.NONE.value
)


class Migration(migrations.Migration):
dependencies = [
("tags", "0004_add_uuid_field"),
Expand All @@ -62,6 +71,19 @@ class Migration(migrations.Migration):
mark_existing_tags_as_permanent, reverse_code=migrations.RunPython.noop
),
migrations.AddField(
model_name="tag",
name="type",
field=models.CharField(
choices=[("NONE", "None"), ("STALE", "Stale")],
null=True,
help_text="Field used to provide a consistent identifier for the FE and API to use for business logic.",
max_length=100,
),
),
migrations.RunPython(
populate_default_tag_type, reverse_code=migrations.RunPython.noop
),
migrations.AlterField(
model_name="tag",
name="type",
field=models.CharField(
Expand Down

0 comments on commit 5808181

Please sign in to comment.