make docker image multimodal and don't apply migration by default.#1037
make docker image multimodal and don't apply migration by default.#1037benanhalt wants to merge 1 commit into
Conversation
| printf "Apply the migrations by:\n" | ||
| printf "1. Stopping any process that could be accessing your database \"$DATABASE_NAME\".\n" | ||
| printf "2. Backing up the database \"$DATABASE_NAME\".\n" | ||
| printf "3. Applying the migrations by running \"docker-compose run --rm THIS-CONTAINER sp7migrate\".\n" |
There was a problem hiding this comment.
It seems like docker-compose run requires SERVICE name, instead of CONTAINER name.
The service name is specify7, so this command would look like this:
docker-compose run --rm specify7 sp7migrate
There was a problem hiding this comment.
Just for reference, I received the following exception when trying to run a migration on a all-in-one composition, having forgotten to put any database into the seed-database folder.
Applying Django migrations.
[24/Nov/2021 18:47:27] [WARNING] [specifyweb.specify.load_datamodel:248] missing table or relationship setting dependent field: Deaccession.deaccessionpreparations
Operations to perform:
Apply all migrations: notifications
Running migrations:
Applying notifications.0001_initial...Traceback (most recent call last):
File "/opt/specify7/ve/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/opt/specify7/ve/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File "/opt/specify7/ve/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1005, 'Can\'t create table `specify`.`notifications_message` (errno: 150 "Foreign key constraint is incorrectly formed")')| if (ve/bin/python manage.py showmigrations notifications workbench | grep -q '\[ \]'); then | ||
| printf "\n\nSpecify 7 cannot start because Django migrations need to be applied.\n\n" | ||
| printf "Apply the migrations by:\n" | ||
| printf "1. Stopping any process that could be accessing your database \"$DATABASE_NAME\".\n" |
There was a problem hiding this comment.
Do we need to clarify that the database container should not be stopped?
Alternatively, this command would start the container if it wasn't running
docker container start DATABASE_CONTAINER
docker-compose run --rm specify7 sp7migrate|
Other than the possible documentation improvements, this worked fine with the development composition and the Workbench was working too. |
This PR makes the Specify 7 docker image explicitly multi modal with several commands defined in
docker-entrypoint.sh.The idea is that the normal start up checks if db migrations are needed and refuses to start if so.
There is now a command sp7migrate that can be issued as
docker-compose run --rm specify7 sp7migrateto allow the migrations to be applied when the database is quiescent and properly backed up.The command sp7worker is also added to simplify the
docker-compose.ymlfile.Finally sp7migrate-and-start implements the old behavior and can be useful for testing.