Skip to content

Commit c6b4e04

Browse files
committed
Enable migrating DB without seeding
1 parent 916ac21 commit c6b4e04

File tree

9 files changed

+45
-40
lines changed

9 files changed

+45
-40
lines changed

.github/actions/run-docker/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ inputs:
1515
logs:
1616
description: 'Show logs'
1717
required: false
18-
data_backup_skip:
18+
skip_data_seed:
1919
description: 'Skip data backup'
2020
required: false
2121
default: 'true'
@@ -43,7 +43,7 @@ runs:
4343
DOCKER_TARGET="${{ inputs.target }}" \
4444
OLYMPIA_UID="$(id -u)" \
4545
OLYMPIA_DEPS="${{ inputs.deps }}" \
46-
DATA_BACKUP_SKIP="${{ inputs.data_backup_skip }}" \
46+
SKIP_DATA_SEED="${{ inputs.skip_data_seed }}" \
4747
DOCKER_WAIT="true"
4848
4949

.github/workflows/_test_check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,4 @@ jobs:
160160
- uses: ./.github/actions/run-docker
161161
with:
162162
version: ${{ inputs.version }}
163-
data_backup_skip: false
164163
run: echo true

.github/workflows/health_check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
target: development
2626
version: local
2727
logs: true
28-
data_backup_skip: ''
2928
run: ./scripts/health_check.py --env ${{ matrix.environment }} --verbose
3029

3130

Makefile-os

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DOCKER_WAIT ?=
1414
export DOCKER_COMMIT ?=
1515
export DOCKER_BUILD ?=
1616
export DOCKER_VERSION ?=
17-
export DATA_BACKUP_SKIP ?=
17+
export SKIP_DATA_SEED ?=
1818
override DOCKER_MYSQLD_VOLUME = addons-server_data_mysqld
1919

2020
INITIALIZE_ARGS ?=

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ x-env-mapping: &env
2121
- HISTCONTROL=erasedups
2222
- ENV=local
2323
- CIRCLECI
24-
- DATA_BACKUP_SKIP
24+
- SKIP_DATA_SEED
2525

2626
x-olympia: &olympia
2727
<<: *env

settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
DBBACKUP_CONNECTOR_MAPPING = {
3434
'olympia.core.db.mysql': 'dbbackup.db.mysql.MysqlDumpConnector',
3535
}
36-
DATA_BACKUP_SKIP = os.environ.get('DATA_BACKUP_SKIP', False)
36+
SKIP_DATA_SEED = os.environ.get('SKIP_DATA_SEED', False)
3737

3838
# Override logging config to enable DEBUG logs for (almost) everything.
3939
LOGGING['root']['level'] = logging.DEBUG

src/olympia/amo/management/commands/initialize.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,33 @@ def handle(self, *args, **options):
4646
# Always ensure "olympia" database exists and is accessible.
4747
call_command('monitors', services=['olympia_database', 'elastic'])
4848

49-
# If we are not skipping data backup
50-
# then run the logic to ensure the DB is ready.
51-
if not settings.DATA_BACKUP_SKIP:
52-
# If DB empty or we are explicitly cleaning, then bail with data_seed.
53-
if options.get('clean') or not self.local_admin_exists():
54-
call_command('data_seed')
55-
# Otherwise, we're working with a pre-existing DB.
49+
if (
50+
# If we are not skipping data seeding
51+
not settings.SKIP_DATA_SEED
52+
# and we are either explicitly cleaning or loading a fresh db
53+
and (options.get('clean') or not self.local_admin_exists())
54+
):
55+
call_command('data_seed')
56+
# Otherwise, we're working with a pre-existing DB.
57+
else:
58+
load = options.get('load')
59+
# We always migrate the DB.
60+
logging.info('Migrating...')
61+
call_command('migrate', '--noinput')
62+
63+
# If we specify a specific backup, simply load that.
64+
if load:
65+
call_command('data_load', '--name', load)
66+
# We should reindex even if no data is loaded/modified
67+
# because we might have a fresh instance of elasticsearch
5668
else:
57-
load = options.get('load')
58-
# We always migrate the DB.
59-
logging.info('Migrating...')
60-
call_command('migrate', '--noinput')
61-
62-
# If we specify a specific backup, simply load that.
63-
if load:
64-
call_command('data_load', '--name', load)
65-
# We should reindex even if no data is loaded/modified
66-
# because we might have a fresh instance of elasticsearch
67-
else:
68-
call_command(
69-
'reindex', '--wipe', '--force', '--noinput', '--skip-if-exists'
70-
)
71-
72-
# By now, we excpect the database to exist, and to be migrated
73-
# so our database tables should be accessible
74-
call_command('monitors', services=['database'])
69+
call_command(
70+
'reindex', '--wipe', '--force', '--noinput', '--skip-if-exists'
71+
)
72+
73+
# By now, we excpect the database to exist, and to be migrated
74+
# so our database tables should be accessible
75+
call_command('monitors', services=['database'])
7576

7677
# Ensure that the storage directories exist.
7778
self.make_storage(clean=False)

src/olympia/amo/tests/test_commands.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _assert_commands_called_in_order(self, mock_call_command, expected_commands)
237237
)
238238

239239

240-
@override_settings(DATA_BACKUP_SKIP=False)
240+
@override_settings(SKIP_DATA_SEED=False)
241241
class TestInitializeDataCommand(BaseTestDataCommand):
242242
def setUp(self):
243243
super().setUp()
@@ -262,34 +262,40 @@ def with_local_admin(self):
262262
username=settings.LOCAL_ADMIN_USERNAME, email=settings.LOCAL_ADMIN_EMAIL
263263
)
264264

265-
@override_settings(DATA_BACKUP_SKIP=True)
265+
@override_settings(SKIP_DATA_SEED=True)
266266
def test_handle_with_skip_data_initialize(self):
267267
"""
268-
Test running the 'initialize' command with the DATA_BACKUP_SKIP flag set.
269-
Expected: nothing happens except verifying the dependencies.
268+
Test running the 'initialize' command with the SKIP_DATA_SEED flag set.
269+
Expected: Run migrations and reindex.
270270
"""
271271
call_command('initialize')
272272
self._assert_commands_called_in_order(
273273
self.mocks['mock_call_command'],
274274
[
275275
self.mock_commands.monitors_olympia_database,
276+
self.mock_commands.migrate,
277+
self.mock_commands.reindex_skip_if_exists,
278+
self.mock_commands.monitors_database,
276279
self.mock_commands.monitors,
277280
self.mock_commands.check,
278281
],
279282
)
280283

281-
@override_settings(DATA_BACKUP_SKIP=True)
284+
@override_settings(SKIP_DATA_SEED=True)
282285
def test_handle_with_load_argument_and_skip_data_initialize(self):
283286
"""
284287
Test running the 'initialize' command with both '--load' argument
285-
and DATA_BACKUP_SKIP flag. Expected:
286-
nothing happens except verifying the dependencies.
288+
and SKIP_DATA_SEED flag. Expected:
289+
Run data migration and load the specified backup.x
287290
"""
288291
call_command('initialize', load='test')
289292
self._assert_commands_called_in_order(
290293
self.mocks['mock_call_command'],
291294
[
292295
self.mock_commands.monitors_olympia_database,
296+
self.mock_commands.migrate,
297+
self.mock_commands.data_load('test'),
298+
self.mock_commands.monitors_database,
293299
self.mock_commands.monitors,
294300
self.mock_commands.check,
295301
],

tests/make/make.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('docker-compose.yml', () => {
7171
DOCKER_TARGET,
7272
DOCKER_VERSION,
7373
DEBUG: 'debug',
74-
DATA_BACKUP_SKIP: 'skip',
74+
SKIP_DATA_SEED: 'skip',
7575
};
7676

7777
it('.services.(web|worker) should have the correct configuration', () => {

0 commit comments

Comments
 (0)