diff --git a/django_elastic_migrations/indexes.py b/django_elastic_migrations/indexes.py index 5232a1a..59e9701 100644 --- a/django_elastic_migrations/indexes.py +++ b/django_elastic_migrations/indexes.py @@ -342,16 +342,6 @@ def activate_index(cls, index_name, exact_mode=False): action = ActivateIndexAction() return cls._start_action_for_indexes(action, index_name, exact_mode) - @classmethod - def deactivate_index(cls, index_name, exact_mode=False): - """ - Given the named index, activate the latest version of the index - """ - # avoid circular import - from django_elastic_migrations.models import DeactivateIndexAction - action = DeactivateIndexAction() - return cls._start_action_for_indexes(action, index_name, exact_mode) - @classmethod def clear_index(cls, index_name, exact_mode=False, older_mode=False): """ diff --git a/django_elastic_migrations/management/commands/es.py b/django_elastic_migrations/management/commands/es.py index e9bec6d..130247c 100644 --- a/django_elastic_migrations/management/commands/es.py +++ b/django_elastic_migrations/management/commands/es.py @@ -9,7 +9,6 @@ 'create': 'Create indexes; calls es_create', 'activate': 'Activate indexes; calls es_activate', 'update': 'Update indexes; calls es_update', - 'deactivate': 'Deactivate indexes; calls es_drop', 'clear': 'Clears indexes; calls es_clear', 'drop': 'Drop indexes; calls es_drop', 'dangerous_reset': 'Dangerously drops all indexes and recreates all indexes (!)' diff --git a/django_elastic_migrations/management/commands/es_deactivate.py b/django_elastic_migrations/management/commands/es_deactivate.py index 698ead9..e69de29 100644 --- a/django_elastic_migrations/management/commands/es_deactivate.py +++ b/django_elastic_migrations/management/commands/es_deactivate.py @@ -1,24 +0,0 @@ -from django_elastic_migrations import DEMIndexManager -from django_elastic_migrations.management.commands.es import ESCommand - - -class Command(ESCommand): - help = "django-elastic-migrations: deactivate an index" - - def add_arguments(self, parser): - self.get_index_specifying_arguments(parser) - - def handle(self, *args, **options): - indexes, exact_mode, apply_all, _, _ = self.get_index_specifying_options(options) - - if apply_all: - DEMIndexManager.deactivate_index( - 'all', - exact_mode=exact_mode, - ) - elif indexes: - for index_name in indexes: - DEMIndexManager.deactivate_index( - index_name, - exact_mode=exact_mode, - ) diff --git a/django_elastic_migrations/migrations/0007_auto_20181112_0937.py b/django_elastic_migrations/migrations/0007_auto_20181112_0937.py new file mode 100644 index 0000000..17bf831 --- /dev/null +++ b/django_elastic_migrations/migrations/0007_auto_20181112_0937.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-11-12 09:37 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_elastic_migrations', '0006_auto_20180709_2101'), + ] + + operations = [ + migrations.DeleteModel( + name='DeactivateIndexAction', + ), + migrations.AlterField( + model_name='indexaction', + name='action', + field=models.CharField(choices=[('create_index', 'create_index'), ('update_index', 'update_index'), ('activate_index', 'activate_index'), ('clear_index', 'clear_index'), ('drop_index', 'drop_index'), ('partial_update_index', 'partial_update_index')], max_length=64), + ), + ] diff --git a/django_elastic_migrations/models.py b/django_elastic_migrations/models.py index 8a744b7..5b96c27 100644 --- a/django_elastic_migrations/models.py +++ b/django_elastic_migrations/models.py @@ -63,14 +63,6 @@ def get_new_version(self, dem_index=None): version.save() return version - def deactivate(self): - """ - Remove any active version from this index - """ - if self.active_version: - self.active_version = None - self.save() - def get_available_versions(self): return self.indexversion_set.filter(deleted_time__isnull=True) @@ -216,13 +208,12 @@ class IndexAction(models.Model): ACTION_CREATE_INDEX = 'create_index' ACTION_UPDATE_INDEX = 'update_index' ACTION_ACTIVATE_INDEX = 'activate_index' - ACTION_DEACTIVATE_INDEX = 'deactivate_index' ACTION_CLEAR_INDEX = 'clear_index' ACTION_DROP_INDEX = 'drop_index' ACTION_PARTIAL_UPDATE_INDEX = 'partial_update_index' ACTIONS_ALL = [ ACTION_CREATE_INDEX, ACTION_UPDATE_INDEX, ACTION_ACTIVATE_INDEX, - ACTION_DEACTIVATE_INDEX, ACTION_CLEAR_INDEX, ACTION_DROP_INDEX, ACTION_PARTIAL_UPDATE_INDEX + ACTION_CLEAR_INDEX, ACTION_DROP_INDEX, ACTION_PARTIAL_UPDATE_INDEX ] ACTIONS_ALL_CHOICES = [(i, i) for i in ACTIONS_ALL] @@ -497,7 +488,6 @@ class ActivateIndexAction(IndexAction): DEFAULT_ACTION = IndexAction.ACTION_ACTIVATE_INDEX def __init__(self, *args, **kwargs): - self.deactivate = kwargs.pop('deactivate', False) super(ActivateIndexAction, self).__init__(*args, **kwargs) class Meta: @@ -513,16 +503,10 @@ def perform_action(self, dem_index, *args, **kwargs): self.index_version = version_model index = self.index - if self.deactivate and index.active_version == version_model: - index.active_version = None - self.add_log( - "Deactivating index version '{index_version_name}' " - "because you said to do so.".format(**msg_params)) - else: - index.active_version = version_model - self.add_log( - "Activating index version '{index_version_name}' " - "because you said to do so.".format(**msg_params)) + index.active_version = version_model + self.add_log( + "Activating index version '{index_version_name}' " + "because you said to do so.".format(**msg_params)) index.save() # by reinitializing, we ensure this worker knows about the update immediately DEMIndexManager.initialize() @@ -543,22 +527,7 @@ def perform_action(self, dem_index, *args, **kwargs): active_version = self.index.active_version msg_params.update({"index_version_name": latest_version.name}) - if self.deactivate: - if self.index.active_version: - self.index.active_version = None - self.add_log( - "For index '{index_name}', DEactivating " - "'{index_version_name}' " - "because you said so.".format( - **msg_params)) - self.index.save() - else: - self.add_log( - "For index '{index_name}', there is no active version; " - "so there is no version to deactivate. \n" - "No action performed.".format(**msg_params) - ) - elif active_version != latest_version: + if active_version != latest_version: self.index.active_version = latest_version self.index.save() # by reinitializing, we ensure this worker knows about the update immediately @@ -712,70 +681,6 @@ def perform_action(self, dem_index, *args, **kwargs): ) -class DeactivateIndexAction(IndexAction): - DEFAULT_ACTION = IndexAction.ACTION_DEACTIVATE_INDEX - - class Meta: - # https://docs.djangoproject.com/en/2.0/topics/db/models/#proxy-models - proxy = True - - def perform_action(self, dem_index, *args, **kwargs): - msg_params = {"index_name": self.index.name} - if dem_index.get_version_id(): - # we have instantiated this DEMIndex with a specific IndexVersion - version_model = dem_index.get_version_model() - msg_params.update({"index_version_name": version_model.name}) - self.index_version = version_model - index = self.index - - index.active_version = None - if index.active_version == version_model: - self.add_log( - "Deactivating formerly active index version " - "'{index_version_name}' " - "because you said to do so.".format(**msg_params)) - index.save() - # re-initialize so as to ensure this worker gets the message - DEMIndexManager.initialize() - else: - self.add_log( - "There is no need to deactivate '{index_version_name}' " - "because is it not active.".format(**msg_params)) - - else: - # use the active version of the index if one exists. - - # first, check if *any* version exists. - latest_version = self.index.get_latest_version() - if not latest_version: - raise NoCreatedIndexVersion( - "You must have created a version of the " - "'{index_name}' index to call es_deactivate " - "index.".format(**msg_params) - ) - - # at least one version is available. - - msg_params.update({"index_version_name": latest_version.name}) - - if self.index.active_version: - self.index.active_version = None - self.add_log( - "For index '{index_name}', DEactivating " - "'{index_version_name}' " - "because you said so.".format( - **msg_params)) - self.index.save() - # re-initialize so as to ensure this worker gets the message - DEMIndexManager.initialize() - else: - self.add_log( - "For index '{index_name}', there is no active version; " - "so there is no version to deactivate. \n" - "No action performed.".format(**msg_params) - ) - - class DropIndexAction(OlderModeMixin, IndexAction): DEFAULT_ACTION = IndexAction.ACTION_DROP_INDEX