Skip initial migration if seeding on initialize.py
This commit is contained in:
Родитель
03fae8133e
Коммит
e7014fe61f
|
@ -33,6 +33,7 @@ class Command(BaseDataCommand):
|
|||
"""
|
||||
Create the database.
|
||||
"""
|
||||
logging.info(f'options: {options}')
|
||||
# We need to support skipping loading/seeding when desired.
|
||||
# Like in CI environments where you don't want to load data every time.
|
||||
if settings.DATA_BACKUP_SKIP:
|
||||
|
@ -41,10 +42,12 @@ class Command(BaseDataCommand):
|
|||
)
|
||||
return
|
||||
|
||||
clean = options.get('clean')
|
||||
load = options.get('load')
|
||||
logging.info(f'options: {options}')
|
||||
# If DB empty or we are explicitly cleaning, then bail with data_seed.
|
||||
if options.get('clean') or not self.local_admin_exists():
|
||||
call_command('data_seed')
|
||||
return
|
||||
|
||||
load = options.get('load')
|
||||
# We always migrate the DB.
|
||||
logging.info('Migrating...')
|
||||
call_command('migrate', '--noinput')
|
||||
|
@ -52,9 +55,6 @@ class Command(BaseDataCommand):
|
|||
# If we specify a specifi backup, simply load that.
|
||||
if load:
|
||||
call_command('data_load', '--name', load)
|
||||
# If DB empty or we are explicitly cleaning, then reseed.
|
||||
elif clean or not self.local_admin_exists():
|
||||
call_command('data_seed')
|
||||
# We should reindex even if no data is loaded/modified
|
||||
# because we might have a fresh instance of elasticsearch
|
||||
else:
|
||||
|
|
|
@ -464,16 +464,15 @@ class TestInitializeDataCommand(BaseTestDataCommand):
|
|||
def test_handle_with_clean_and_load_arguments(self):
|
||||
"""
|
||||
Test running the 'initialize' command with both '--clean' and '--load'
|
||||
arguments. Expected: Command should prioritize '--load' and perform
|
||||
migration, loading.
|
||||
arguments. Expected: Command should prioritize '--clean' and perform
|
||||
migration and seeding.
|
||||
"""
|
||||
name = 'test'
|
||||
call_command('initialize', clean=True, load=name)
|
||||
self._assert_commands_called_in_order(
|
||||
self.mocks['mock_call_command'],
|
||||
[
|
||||
self.mock_commands.migrate,
|
||||
self.mock_commands.data_load(name),
|
||||
self.mock_commands.data_seed,
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -487,7 +486,6 @@ class TestInitializeDataCommand(BaseTestDataCommand):
|
|||
self._assert_commands_called_in_order(
|
||||
self.mocks['mock_call_command'],
|
||||
[
|
||||
self.mock_commands.migrate,
|
||||
self.mock_commands.data_seed,
|
||||
],
|
||||
)
|
||||
|
@ -518,7 +516,6 @@ class TestInitializeDataCommand(BaseTestDataCommand):
|
|||
self._assert_commands_called_in_order(
|
||||
self.mocks['mock_call_command'],
|
||||
[
|
||||
self.mock_commands.migrate,
|
||||
self.mock_commands.data_seed,
|
||||
],
|
||||
)
|
||||
|
@ -529,6 +526,7 @@ class TestInitializeDataCommand(BaseTestDataCommand):
|
|||
Expected: The command exits with an error and does not proceed to seeding
|
||||
or loading data.
|
||||
"""
|
||||
self.with_local_admin()
|
||||
self.mocks['mock_call_command'].side_effect = Exception('test')
|
||||
with pytest.raises(Exception) as context:
|
||||
call_command('initialize')
|
||||
|
|
Загрузка…
Ссылка в новой задаче