Skip to content

Commit

Permalink
Reindex on data_load
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Sep 24, 2024
1 parent 74812d5 commit 189201c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Makefile-docker
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ data_load:
.PHONY: initialize_db
initialize_db: ## create a new database
rm -rf ./user-media/* ./tmp/*
# Seed the database with initial data
./manage.py data_seed
# Load the data from the initial dump
$(MAKE) data_load ARGS="--name _init"

.PHONY: reindex_data
reindex_data: ## reindex the data in elasticsearch
Expand Down
5 changes: 2 additions & 3 deletions docs/topics/development/data_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ These commands rely internally on [django-dbbackup](https://django-dbbackup.read
make data_load [ARGS="--name <name>"]
```

This command will load data from an existing backup directory. The name is required and must match a directory in the `DATA_BACKUP_DIRNAME` directory.
This command will load data from an existing backup directory, synchronize the storage directory and reindex elasticsearch.
The name is required and must match a directory in the `DATA_BACKUP_DIRNAME` directory.

> NOTE: This command will NOT reindex elasticsearch. In most cases you should use the `make initialize_data` command instead.
> You can specify the `--load <name>` argument to load a specific backup and ensure the index is recreated.

## Hard Reset Database

Expand Down
5 changes: 5 additions & 0 deletions src/olympia/amo/management/commands/data_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ def handle(self, *args, **options):
uncompress=True,
replace=True,
)

# reindex --wipe will force the ES mapping to be re-installed.
# After loading data from a backup, we should always reindex
# to make sure the mapping is correct.
self.call_command('reindex', '--wipe', '--force', '--noinput')
4 changes: 1 addition & 3 deletions src/olympia/amo/management/commands/data_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def handle(self, *args, **options):
self.logger.info('Resetting database...')
self.call_command('flush', '--noinput')
self.call_command('migrate', '--noinput')
# reindex --wipe will force the ES mapping to be re-installed. Useful to
# make sure the mapping is correct before adding a bunch of add-ons.
self.call_command('reindex', '--wipe', '--force', '--noinput')

self.logger.info('Loading initial data...')
self.call_command('loaddata', 'initial.json')
Expand All @@ -43,3 +40,4 @@ def handle(self, *args, **options):
self.call_command('generate_default_addons_for_frontend')

self.call_command('data_dump', '--name', self.data_backup_init)
self.call_command('data_load', '--name', self.data_backup_init)
4 changes: 2 additions & 2 deletions src/olympia/amo/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ class Commands:
flush = mock.call('flush', '--noinput')
migrate = mock.call('migrate', '--noinput')
data_seed = mock.call('data_seed')
reindex = mock.call('reindex', '--noinput', '--force')

flush = mock.call('flush', '--noinput')
reindex = mock.call('reindex', '--wipe', '--force', '--noinput')
Expand Down Expand Up @@ -563,6 +562,7 @@ def test_loads_correct_path(self, mock_call_command):
[
self.mock_commands.db_restore(db_path),
self.mock_commands.media_restore(storage_path),
self.mock_commands.reindex,
],
)

Expand Down Expand Up @@ -602,7 +602,6 @@ def test_default(self):
[
self.mock_commands.flush,
self.mock_commands.migrate,
self.mock_commands.reindex,
self.mock_commands.load_initial_data,
self.mock_commands.import_prod_versions,
self.mock_commands.createsuperuser,
Expand All @@ -612,5 +611,6 @@ def test_default(self):
self.mock_commands.generate_themes(5),
self.mock_commands.generate_default_addons_for_frontend,
self.mock_commands.data_dump(self.base_data_command.data_backup_init),
self.mock_commands.data_load(self.base_data_command.data_backup_init),
],
)

0 comments on commit 189201c

Please sign in to comment.