Skip to content

Commit 6549234

Browse files
committed
Search: migrate null ranks to zero
1 parent f125074 commit 6549234

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 2.2.12 on 2020-07-07 23:31
2+
3+
from django.db import migrations
4+
5+
6+
def forwards_func(apps, schema_editor):
7+
"""Sets all null ranks to zero."""
8+
ImportedFile = apps.get_model('projects', 'ImportedFile')
9+
ImportedFile.objects.filter(rank=None).update(rank=0)
10+
11+
12+
class Migration(migrations.Migration):
13+
14+
dependencies = [
15+
('projects', '0057_add_page_rank'),
16+
]
17+
18+
operations = [
19+
migrations.RunPython(forwards_func),
20+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 2.2.12 on 2020-07-07 23:35
2+
3+
import django.core.validators
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('projects', '0058_migrate_null_rank'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='importedfile',
16+
name='rank',
17+
field=models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(-10), django.core.validators.MaxValueValidator(10)], verbose_name='Page search rank'),
18+
),
19+
]

readthedocs/projects/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,7 @@ class ImportedFile(models.Model):
13551355
modified_date = models.DateTimeField(_('Modified date'), auto_now=True)
13561356
rank = models.IntegerField(
13571357
_('Page search rank'),
1358-
# default=0,
1359-
# TODO: remove after migration
1360-
null=True,
1358+
default=0,
13611359
validators=[MinValueValidator(-10), MaxValueValidator(10)],
13621360
)
13631361

readthedocs/search/documents.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ class Meta:
9494
ignore_signals = True
9595

9696
def prepare_rank(self, html_file):
97-
# TODO: remove when the migration is done
98-
if html_file.rank is None or not (-10 <= html_file.rank <= 10):
97+
if not (-10 <= html_file.rank <= 10):
9998
return 0
10099
return html_file.rank
101100

readthedocs/search/tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ def test_search_custom_ranking(self, api_client):
516516
page_guides = HTMLFile.objects.get(path='guides/index.html')
517517

518518
# Query with the default ranking
519-
assert page_index.rank is None
520-
assert page_guides.rank is None
519+
assert page_index.rank == 0
520+
assert page_guides.rank == 0
521521

522522
search_params = {
523523
'project': project.slug,

0 commit comments

Comments
 (0)