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

fix: add migration file to generate stale flags tag for all existing projects #3755

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.2.25 on 2024-04-11 10:24
from django.apps.registry import Apps
from django.conf import settings
from django.db import migrations
from django.db.backends.base.schema import BaseDatabaseSchemaEditor


def create_tag(apps: Apps, schema_editor: BaseDatabaseSchemaEditor) -> None:
if not settings.WORKFLOWS_LOGIC_INSTALLED:
return

from workflows_logic.stale_flags.constants import (
STALE_FLAGS_TAG_LABEL,
STALE_FLAGS_TAG_COLOR,
STALE_FLAGS_TAG_TYPE,
)

project_model = apps.get_model("projects", "Project")
tag_model = apps.get_model("tags", "Tag")

to_create = []
for project in project_model.objects.exclude(tags__label=STALE_FLAGS_TAG_LABEL):
to_create.append(
tag_model(
project=project,
label=STALE_FLAGS_TAG_LABEL,
is_system_tag=True,
color=STALE_FLAGS_TAG_COLOR,
type=STALE_FLAGS_TAG_TYPE
)
)

tag_model.objects.bulk_create(to_create)


class Migration(migrations.Migration):

dependencies = [
('tags', '0005_add_tag_fields_for_stale_flags_logic'),
]

operations = [
migrations.RunPython(create_tag, reverse_code=migrations.RunPython.noop)
]