Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions treeherder/model/migrations/0046_repository_repo_url_active_idx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.db import migrations, models


class Migration(migrations.Migration):
# Use non-atomic so we can create the index CONCURRENTLY
atomic = False

dependencies = [
("model", "0045_alter_failureline_expected_alter_failureline_level_and_more"),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
sql="CREATE INDEX CONCURRENTLY IF NOT EXISTS repo_url_active_idx ON repository (url, active_status);",
reverse_sql="DROP INDEX IF EXISTS repo_url_active_idx;",
),
],
state_operations=[
migrations.AddIndex(
model_name="repository",
index=models.Index(fields=["url", "active_status"], name="repo_url_active_idx"),
),
],
),
]
3 changes: 3 additions & 0 deletions treeherder/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class Repository(models.Model):
class Meta:
db_table = "repository"
verbose_name_plural = "repositories"
indexes = [
models.Index(fields=["url", "active_status"], name="repo_url_active_idx"),
]

@classmethod
def fetch_all_names(cls) -> list[str]:
Expand Down