Skip to content

make docker image multimodal and don't apply migration by default.#1037

Open
benanhalt wants to merge 1 commit into
mainfrom
issue-1034
Open

make docker image multimodal and don't apply migration by default.#1037
benanhalt wants to merge 1 commit into
mainfrom
issue-1034

Conversation

@benanhalt

@benanhalt benanhalt commented Oct 22, 2021

Copy link
Copy Markdown
Contributor

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 sp7migrate to 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.yml file.

Finally sp7migrate-and-start implements the old behavior and can be useful for testing.

@benanhalt benanhalt linked an issue Oct 22, 2021 that may be closed by this pull request
@benanhalt
benanhalt marked this pull request as ready for review October 22, 2021 22:02
@benanhalt
benanhalt requested a review from maxpatiiuk October 22, 2021 22:02
Comment thread docker-entrypoint.sh
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")')

Comment thread docker-entrypoint.sh
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@maxpatiiuk

Copy link
Copy Markdown
Member

Other than the possible documentation improvements, this worked fine with the development composition and the all-in-one composition.

Workbench was working too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 - Archive Pull requests that may be useful in the future but have been archived

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django migration fails with Table 'django_content_type' already exists Improve handling of Django database migrations.

3 participants