Skip to content

Commit

Permalink
Merge pull request #196 from rapidpro/update-deps
Browse files Browse the repository at this point in the history
Change unique_together to use constraints, replace use of index_together
  • Loading branch information
norkans7 authored Aug 22, 2024
2 parents 8f5bb86 + 8bb30aa commit 8913c67
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 10 deletions.
2 changes: 1 addition & 1 deletion code_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def status(line):
cmd("black dash test_runner")

status("Running ruff")
cmd("ruff dash")
cmd("ruff check dash")

status("Running isort")
cmd("isort dash")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.8 on 2024-08-21 16:03

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("categories", "0010_alter_category_created_by_alter_category_modified_by_and_more"),
("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterUniqueTogether(
name="category",
unique_together=set(),
),
migrations.AddConstraint(
model_name="category",
constraint=models.UniqueConstraint(fields=("name", "org"), name="categories_category_name_unique"),
),
]
2 changes: 1 addition & 1 deletion dash/categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self):

class Meta:
ordering = ["name"]
unique_together = ("name", "org")
constraints = [models.UniqueConstraint(fields=["name", "org"], name="categories_category_name_unique")]
verbose_name_plural = _("Categories")


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.8 on 2024-08-21 16:03

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
(
"dashblocks",
"0012_rename_dashblock_org_is_active_dashblock_type_priority_dashblocks__org_id_024805_idx_and_more",
),
]

operations = [
migrations.RenameIndex(
model_name="dashblock",
new_name="dashblock_org_typ_prio_idx",
old_name="dashblocks__org_id_024805_idx",
),
migrations.RenameIndex(
model_name="dashblocktype",
new_name="dashblocktype_slug_name_idx",
old_name="dashblocks__slug_c0c6c6_idx",
),
]
6 changes: 4 additions & 2 deletions dash/dashblocks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __str__(self):

class Meta:
ordering = ["name"]
indexes = [models.Index(fields=["slug", "name"])]
indexes = [models.Index(fields=["slug", "name"], name="dashblocktype_slug_name_idx")]


class DashBlock(SmartModel):
Expand Down Expand Up @@ -149,7 +149,9 @@ def __str__(self):

class Meta:
ordering = ["dashblock_type", "title"]
indexes = [models.Index(fields=["org", "is_active", "dashblock_type", "priority"])]
indexes = [
models.Index(fields=["org", "is_active", "dashblock_type", "priority"], name="dashblock_org_typ_prio_idx")
]


class DashBlockImage(SmartModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0.8 on 2024-08-21 16:03

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("orgs", "0032_rename_orgbackend_org_is_active_slug_orgs_orgbac_org_id_607508_idx"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.RenameIndex(
model_name="orgbackend",
new_name="orgs_orgbac_org_slug_idx",
old_name="orgs_orgbac_org_id_607508_idx",
),
migrations.AlterUniqueTogether(
name="orgbackend",
unique_together=set(),
),
migrations.AlterUniqueTogether(
name="taskstate",
unique_together=set(),
),
migrations.AddConstraint(
model_name="orgbackend",
constraint=models.UniqueConstraint(fields=("org", "slug"), name="orgs_orgbackend_org_slug_unique"),
),
migrations.AddConstraint(
model_name="taskstate",
constraint=models.UniqueConstraint(fields=("org", "task_key"), name="orgs_taskstate_org_task_key_unique"),
),
]
6 changes: 3 additions & 3 deletions dash/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def get_time_taken(self):
return (until - self.started_on).total_seconds()

class Meta:
unique_together = ("org", "task_key")
constraints = [models.UniqueConstraint(fields=["org", "task_key"], name="orgs_taskstate_org_task_key_unique")]


class OrgBackend(SmartModel):
Expand All @@ -415,5 +415,5 @@ def __str__(self):
return self.slug

class Meta:
unique_together = ("org", "slug")
indexes = [models.Index(fields=["org", "is_active", "slug"])]
constraints = [models.UniqueConstraint(fields=["org", "slug"], name="orgs_orgbackend_org_slug_unique")]
indexes = [models.Index(fields=["org", "is_active", "slug"], name="orgs_orgbac_org_slug_idx")]
24 changes: 24 additions & 0 deletions dash/tags/migrations/0003_alter_tag_unique_together_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.0.8 on 2024-08-21 16:03

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("orgs", "0033_rename_orgs_orgbac_org_id_607508_idx_orgs_orgbac_org_slug_idx_and_more"),
("tags", "0002_alter_tag_created_by_alter_tag_modified_by"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterUniqueTogether(
name="tag",
unique_together=set(),
),
migrations.AddConstraint(
model_name="tag",
constraint=models.UniqueConstraint(fields=("name", "org"), name="tags_tag_name_org_unique"),
),
]
2 changes: 1 addition & 1 deletion dash/tags/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def __str__(self) -> str:
return self.name

class Meta:
unique_together = ("name", "org")
constraints = [models.UniqueConstraint(fields=["name", "org"], name="tags_tag_name_org_unique")]
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ line-length = 119

[tool.ruff]
line-length = 120
select = ["E", "F", "W"]
ignore = ["E501", "F405"]
fix = true
exclude = ["./.tox/*", "./.venv/*", "./env/*", "*/migrations/*", "./build/*"]

[tool.ruff.lint]
select = ["E", "F", "W"]
ignore = ["E501", "F405"]

[tool.isort]
multi_line_output = 3
force_grid_wrap = 0
Expand Down

0 comments on commit 8913c67

Please sign in to comment.