-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fields necessary for stale flags (#3263)
- Loading branch information
1 parent
932c62d
commit aa1d6bb
Showing
9 changed files
with
269 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
19 changes: 19 additions & 0 deletions
19
api/projects/migrations/0022_add_stale_flags_threshold_to_project.py
This file contains 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,19 @@ | ||
# Generated by Django 3.2.23 on 2023-12-06 14:35 | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("projects", "0021_add_identity_overrides_migration_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="project", | ||
name="stale_flags_limit_days", | ||
field=models.IntegerField( | ||
default=30, | ||
help_text="Number of days without modification in any environment before a flag is considered stale.", | ||
), | ||
), | ||
] |
This file contains 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
96 changes: 96 additions & 0 deletions
96
api/projects/tags/migrations/0005_add_tag_fields_for_stale_flags_logic.py
This file contains 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,96 @@ | ||
# Generated by Django 3.2.23 on 2023-12-06 15:11 | ||
import re | ||
|
||
from django.apps.registry import Apps | ||
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"[ _]") | ||
|
||
|
||
def get_sanitised_label(label: str) -> str: | ||
return LABEL_REGEX.sub("", label.lower()) | ||
|
||
|
||
def mark_existing_tags_as_permanent( | ||
apps: Apps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
""" | ||
Update all tags in the database which the FE treats as 'permanent' through regex matching | ||
to have the new is_permanent label. The FE will subsequently be updated to use the | ||
is_permanent attribute instead of regex matching. | ||
""" | ||
tag_class = apps.get_model("tags", "tag") | ||
|
||
to_update = [] | ||
|
||
for tag in filter( | ||
lambda t: get_sanitised_label(t.label) in PROTECTED_LABELS, | ||
tag_class.objects.all(), | ||
): | ||
tag.is_permanent = True | ||
to_update.append(tag) | ||
|
||
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"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="tag", | ||
name="is_permanent", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="When applied to a feature, it means this feature should be excluded from stale flags logic.", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="tag", | ||
name="is_system_tag", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="Indicates that a tag was created by the system, not the user.", | ||
), | ||
), | ||
migrations.RunPython( | ||
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( | ||
choices=[("NONE", "None"), ("STALE", "Stale")], | ||
default="NONE", | ||
help_text="Field used to provide a consistent identifier for the FE and API to use for business logic.", | ||
max_length=100, | ||
), | ||
), | ||
] |
This file contains 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 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 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 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