Skip to content

Commit 912c7b5

Browse files
authored
fix: simplify migrations when building postgres db image (ietf-tools#4889)
* chore: remove the effectively unused DATABASE_TEST_OPTIONS setting * fix: simplify default settings_local so that db-include-fix.py is not needed in CI * fix: simplify migrations in db-pg-migrate.sh
1 parent f09ad38 commit 912c7b5

8 files changed

Lines changed: 13 additions & 43 deletions

File tree

dev/deploy-to-container/settings_local.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
},
2121
}
2222

23-
DATABASE_TEST_OPTIONS = {
24-
'init_command': 'SET storage_engine=InnoDB',
25-
}
26-
2723
SECRET_KEY = "__SECRETKEY__"
2824

2925
CELERY_BROKER_URL = '__MQCONNSTR__'

dev/diff/settings_local.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
},
2121
}
2222

23-
DATABASE_TEST_OPTIONS = {
24-
'init_command': 'SET storage_engine=InnoDB',
25-
}
2623

2724
IDSUBMIT_IDNITS_BINARY = "/usr/local/bin/idnits"
2825
IDSUBMIT_REPOSITORY_PATH = "test/id/"

dev/tests/settings_local.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
},
2121
}
2222

23-
DATABASE_TEST_OPTIONS = {
24-
'init_command': 'SET storage_engine=InnoDB',
25-
}
2623

2724
IDSUBMIT_IDNITS_BINARY = "/usr/local/bin/idnits"
2825
IDSUBMIT_REPOSITORY_PATH = "test/id/"

docker/configs/settings_local.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,8 @@
55

66
ALLOWED_HOSTS = ['*']
77

8-
DATABASES = {
9-
'default': {
10-
'HOST': 'db',
11-
'PORT': 3306,
12-
'NAME': 'ietf_utf8',
13-
'ENGINE': 'django.db.backends.mysql',
14-
'USER': 'django',
15-
'PASSWORD': 'RkTkDPFnKpko',
16-
'OPTIONS': {
17-
'sql_mode': 'STRICT_TRANS_TABLES',
18-
'init_command': 'SET storage_engine=InnoDB; SET names "utf8"',
19-
},
20-
},
21-
}
8+
from ietf.settings_mysqldb import DATABASES
229

23-
DATABASE_TEST_OPTIONS = {
24-
'init_command': 'SET storage_engine=InnoDB',
25-
}
2610

2711
IDSUBMIT_IDNITS_BINARY = "/usr/local/bin/idnits"
2812
IDSUBMIT_REPOSITORY_PATH = "test/id/"

docker/configs/settings_mysqldb.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@
1212
},
1313
},
1414
}
15-
16-
DATABASE_TEST_OPTIONS = {
17-
'init_command': 'SET storage_engine=InnoDB',
18-
}

docker/scripts/db-pg-migrate.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ echo "Waiting for DB containers to come online..."
4545
echo "Running initial checks..."
4646
/usr/local/bin/python ./ietf/manage.py check --settings=settings_local
4747

48-
# Migrate, adjusting to what the current state of the underlying database might be:
49-
/usr/local/bin/python ./ietf/manage.py migrate --settings=settings_local
50-
51-
# We may be starting with a post 9.0.0 deploy dump, so run the migrations again before switching engines to catch any pre-postgres migrations that may be merged in from main post 9.0.0 (and any that are specific to feat/postgres that need to run before we switch engines)
48+
# The mysql database is always freshly build container from the
49+
# image build of last-night's dump when this script is run
50+
# The first run of migrations will run anything merged from main that
51+
# that hasn't been released, and the few pre-engine-shift migrations
52+
# that the feat/postgres branch adds. It is guaranteed to fail at
53+
# utils.migrations.0004_pause_to_change_database_engines (where it
54+
# fails on purpose, hence the `|| true` so we may proceed
5255
/usr/local/bin/python ./ietf/manage.py migrate --settings=settings_local || true
5356

5457
cat ./ietf/settings_local.py | sed 's/from ietf.settings_mysqldb import DATABASES/from ietf.settings_postgresqldb import DATABASES/' > /tmp/settings_local.py && mv /tmp/settings_local.py ./ietf/settings_local.py
5558

5659
# Now transfer the migrated database from mysql to postgres unless that's already happened.
5760
echo "Transferring migrated database from MySQL to PostgreSQL..."
58-
if psql -U django -h pgdb -d ietf -c "\dt" 2>&1 | grep -q "Did not find any relations."; then
61+
EMPTY_CHECK=`psql -U django -h pgdb -d ietf -c "\dt" 2>&1`
62+
if echo ${EMPTY_CHECK} | grep -q "Did not find any relations."; then
5963
cat << EOF > cast.load
6064
LOAD DATABASE
6165
FROM mysql://django:RkTkDPFnKpko@db/ietf_utf8
@@ -65,6 +69,9 @@ EOF
6569
time pgloader --verbose --logfile=ietf_pgloader.run --summary=ietf_pgloader.summary cast.load
6670
rm cast.load
6771
/usr/local/bin/python ./ietf/manage.py migrate --settings=settings_local
72+
else
73+
echo "The postgres database is in an unexpected state"
74+
echo ${EMPTY_CHECK}
6875
fi
6976

7077
# Stop postgreSQL container

ietf/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
},
9292
}
9393

94-
DATABASE_TEST_OPTIONS = {
95-
# Comment this out if your database doesn't support InnoDB
96-
'init_command': 'SET storage_engine=InnoDB',
97-
}
9894

9995
# Local time zone for this installation. Choices can be found here:
10096
# http://www.postgresql.org/docs/8.1/static/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE

ietf/utils/test_runner.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ def safe_create_test_db(self, verbosity, *args, **kwargs):
229229
keepdb = kwargs.get('keepdb', False)
230230
if not keepdb:
231231
print(" Creating test database...")
232-
if settings.DATABASES["default"]["ENGINE"] == 'django.db.backends.mysql':
233-
settings.DATABASES["default"]["OPTIONS"] = settings.DATABASE_TEST_OPTIONS
234-
print(" Using OPTIONS: %s" % settings.DATABASES["default"]["OPTIONS"])
235232
test_database_name = old_create(self, 0, *args, **kwargs)
236233

237234
if settings.GLOBAL_TEST_FIXTURES:

0 commit comments

Comments
 (0)