Skip to content

Conversation

@Alef-Burzmali
Copy link
Contributor

Fixes: #11223 and #11248

Add the possibility to reindex all the models of an app_label via the management command reindex.

The second commit modifies the reindex call in migration extras.0083_search to reindex only the models of core NetBox, to prevent plugins from blocking the migration as in #11248. Plugins should add their own reindex migration when they add a SearchIndex, such as:

import sys

from django.core import management
from django.db import migrations

def reindex(apps, schema_editor):
    # Build the search index (except during tests)
    if "test" not in sys.argv:
        management.call_command("reindex", "<plugin_label>")

class Migration(migrations.Migration):
    dependencies = [
        ("<plugin_label>", "<NNNN_previous_migration>"),
    ]

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

@Alef-Burzmali Alef-Burzmali force-pushed the 11223-reindex-app_label branch from 00eb108 to cb7905c Compare December 28, 2022 20:06
@jeremystretch
Copy link
Member

Thanks for taking this on @Alef-Burzmali!

@jeremystretch jeremystretch merged commit b7cdbd3 into netbox-community:develop Dec 28, 2022
@Alef-Burzmali Alef-Burzmali deleted the 11223-reindex-app_label branch December 28, 2022 21:40
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reindex command does not accept app_label as argument

2 participants