-
Notifications
You must be signed in to change notification settings - Fork 3.6k
chore: intake migration #5950
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
chore: intake migration #5950
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Generated by Django 4.2.15 on 2024-11-05 07:02 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("db", "0083_device_workspace_timezone_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveConstraint( | ||
| model_name="label", | ||
| name="label_unique_name_project_when_deleted_at_null", | ||
| ), | ||
| migrations.AlterUniqueTogether( | ||
| name="label", | ||
| unique_together=set(), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="deployboard", | ||
| name="is_disabled", | ||
| field=models.BooleanField(default=False), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="inboxissue", | ||
| name="extra", | ||
| field=models.JSONField(default=dict), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="inboxissue", | ||
| name="source_email", | ||
| field=models.TextField(blank=True, null=True), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="user", | ||
| name="bot_type", | ||
| field=models.CharField( | ||
| blank=True, max_length=30, null=True, verbose_name="Bot Type" | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="deployboard", | ||
| name="entity_name", | ||
| field=models.CharField(blank=True, max_length=30, null=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="inboxissue", | ||
| name="source", | ||
| field=models.CharField( | ||
| blank=True, default="IN_APP", max_length=255, null=True | ||
| ), | ||
| ), | ||
|
Comment on lines
+48
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add choices for source field. The Consider adding choices like: SOURCE_CHOICES = [
("IN_APP", "In App"),
("EMAIL", "Email"),
# add other sources
] |
||
| migrations.AddConstraint( | ||
| model_name="label", | ||
| constraint=models.UniqueConstraint( | ||
| condition=models.Q( | ||
| ("deleted_at__isnull", True), ("project__isnull", True) | ||
| ), | ||
| fields=("name",), | ||
| name="unique_name_when_project_null_and_not_deleted", | ||
| ), | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name="label", | ||
| constraint=models.UniqueConstraint( | ||
| condition=models.Q( | ||
| ("deleted_at__isnull", True), ("project__isnull", False) | ||
| ), | ||
| fields=("project", "name"), | ||
| name="unique_project_name_when_not_deleted", | ||
| ), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,14 @@ class DeployBoard(WorkspaceBaseModel): | |
| ("cycle", "Task"), | ||
| ("page", "Page"), | ||
| ("view", "View"), | ||
| ("intake", "Intake"), | ||
| ) | ||
|
|
||
| entity_identifier = models.UUIDField(null=True) | ||
| entity_name = models.CharField( | ||
| max_length=30, | ||
| choices=TYPE_CHOICES, | ||
| null=True, | ||
| blank=True, | ||
|
Comment on lines
+29
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Restore type safety for entity_name field The removal of
Consider one of these solutions: entity_name = models.CharField(
max_length=30,
- null=True,
- blank=True,
+ choices=TYPE_CHOICES,
+ null=True, # if null values are really needed
+ blank=True, # if blank values are really needed
)Or if flexible values are required, add a validator: +from django.core.validators import RegexValidator
+
entity_name = models.CharField(
max_length=30,
null=True,
blank=True,
+ validators=[RegexValidator(
+ regex='^(project|issue|module|cycle|page|view|intake)$',
+ message='entity_name must match one of the defined types',
+ )]
)
|
||
| ) | ||
| anchor = models.CharField( | ||
| max_length=255, default=get_anchor, unique=True, db_index=True | ||
|
|
@@ -41,6 +43,7 @@ class DeployBoard(WorkspaceBaseModel): | |
| is_votes_enabled = models.BooleanField(default=False) | ||
| view_props = models.JSONField(default=dict) | ||
| is_activity_enabled = models.BooleanField(default=True) | ||
| is_disabled = models.BooleanField(default=False) | ||
|
|
||
| def __str__(self): | ||
| """Return name of the deploy board""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,9 +57,16 @@ class InboxIssue(ProjectBaseModel): | |
| on_delete=models.SET_NULL, | ||
| null=True, | ||
| ) | ||
| source = models.TextField(blank=True, null=True) | ||
| source = models.CharField( | ||
| max_length=255, | ||
| default="IN_APP", | ||
| null=True, | ||
| blank=True, | ||
| ) | ||
| source_email = models.TextField(blank=True, null=True) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider JSONField default value implementation. While the new fields are well-structured, using a mutable default (dict) for JSONField can lead to unexpected behavior. Consider using a callable default instead. - extra = models.JSONField(default=dict)
+ extra = models.JSONField(default=dict)
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ if self.extra is None:
+ self.extra = {}Also, consider adding validation for the + def clean(self):
+ super().clean()
+ if self.source_email:
+ from django.core.validators import validate_email
+ validate_email(self.source_email)Also applies to: 69-69 |
||
| external_source = models.CharField(max_length=255, null=True, blank=True) | ||
| external_id = models.CharField(max_length=255, blank=True, null=True) | ||
| extra = models.JSONField(default=dict) | ||
|
|
||
| class Meta: | ||
| verbose_name = "InboxIssue" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mutable default in JSONField.
Using
default=dictfor JSONField is dangerous as it creates a mutable default that's shared between instances.Replace with: