From 21aaf85dd8dcf9658c897fcc4bcd1ad1df4afaa5 Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Thu, 7 Apr 2022 15:29:24 -0400 Subject: [PATCH 1/2] Check for both alembic and SQLAlchemy Migrate errors Because this needs to support both pre- and post-alembic versions. --- tasks/database.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tasks/database.yml b/tasks/database.yml index 45485d2..e38783b 100644 --- a/tasks/database.yml +++ b/tasks/database.yml @@ -10,7 +10,10 @@ chdir: "{{ galaxy_server_dir }}" register: current_db_version changed_when: no - failed_when: current_db_version.rc != 0 and 'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr + failed_when: + - current_db_version.rc != 0 + - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" + - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" when: not ansible_check_mode - name: Get maximum Galaxy DB version @@ -25,13 +28,21 @@ debug: msg: "Current database version is {{ current_db_version.stdout }} and the maximum version is {{ max_db_version.stdout }}." changed_when: True - when: "(not ansible_check_mode) and (current_db_version.stdout != max_db_version.stdout and 'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr)" + when: + - not ansible_check_mode + - current_db_version.stdout != max_db_version.stdout + - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" + - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" - name: Upgrade Galaxy DB command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} upgrade" args: chdir: "{{ galaxy_server_dir }}" - when: "(not ansible_check_mode) and current_db_version.stdout != max_db_version.stdout and 'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" + when: + - not ansible_check_mode + - current_db_version.stdout != max_db_version.stdout + - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" + - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" remote_user: "{{ galaxy_remote_users.galaxy | default(__galaxy_remote_user) }}" become: "{{ true if galaxy_become_users.galaxy is defined else __galaxy_become }}" From 06a8860ad35b4c144d5a00f1a01c08bcdc2ecc1b Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Fri, 8 Apr 2022 12:33:48 -0400 Subject: [PATCH 2/2] Check for different error --- tasks/database.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/database.yml b/tasks/database.yml index e38783b..903ea44 100644 --- a/tasks/database.yml +++ b/tasks/database.yml @@ -13,7 +13,7 @@ failed_when: - current_db_version.rc != 0 - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" - - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" + - "'galaxy.model.migrations.NoVersionTableError' not in current_db_version.stderr" when: not ansible_check_mode - name: Get maximum Galaxy DB version @@ -32,7 +32,7 @@ - not ansible_check_mode - current_db_version.stdout != max_db_version.stdout - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" - - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" + - "'galaxy.model.migrations.NoVersionTableError' not in current_db_version.stderr" - name: Upgrade Galaxy DB command: "{{ galaxy_venv_dir }}/bin/python {{ galaxy_server_dir }}/scripts/manage_db.py -c {{ galaxy_config_file }} upgrade" @@ -42,7 +42,7 @@ - not ansible_check_mode - current_db_version.stdout != max_db_version.stdout - "'migrate.exceptions.DatabaseNotControlledError' not in current_db_version.stderr" - - "'galaxy.model.migrations.IncorrectVersionError' not in current_db_version.stderr" + - "'galaxy.model.migrations.NoVersionTableError' not in current_db_version.stderr" remote_user: "{{ galaxy_remote_users.galaxy | default(__galaxy_remote_user) }}" become: "{{ true if galaxy_become_users.galaxy is defined else __galaxy_become }}"