Commit b0e6948f by Feanil Patel

Update the migration commands.

We need more params to be able to run the commands against an arbitrary application.
parent 6d67d77d
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
# #
# - application_path - the path where the Django application with potential migrations is installed # - application_path - the path where the Django application with potential migrations is installed
# NOTE: It is assumed that edx-django-release-util is one of its INSTALLED_APPS. # NOTE: It is assumed that edx-django-release-util is one of its INSTALLED_APPS.
# - applicaiton_name - The name of the application that we are migrating.
# - application_user - user which is meant to run the application # - application_user - user which is meant to run the application
# - unapplied_migrations_output - the filename where the unapplied migration YAML output is stored # - unapplied_migrations_output - the filename where the unapplied migration YAML output is stored
# - migration_output - the filename where the migration output is saved # - migration_output - the filename where the migration output is saved
...@@ -26,44 +27,43 @@ ...@@ -26,44 +27,43 @@
- hosts: all - hosts: all
vars: vars:
application_path: /usr/src/my_django_app
application_user: appuser
unapplied_migrations_output: unapplied_migrations.yml unapplied_migrations_output: unapplied_migrations.yml
migration_output: migration_output.yml migration_output: migration_output.yml
hipchat_url: https://api.hipchat.com/v2/ HIPCHAT_URL: https://api.hipchat.com/v2/
COMMAND_PREFIX: ". {{ APPLICATION_PATH }}/{{ APPLICATION_NAME }}_env; DB_MIGRATION_USER={{ DB_MIGRATION_USER }} DB_MIGRATION_PASS={{ DB_MIGRATION_PASS }} /edx/bin/python.{{ APPLICATION_NAME }} /edx/bin/manage.{{ APPLICATION_NAME }} "
gather_facts: False gather_facts: False
connection: local
tasks: tasks:
- name: Create a temporary directory for the migration output. - name: Create a temporary directory for the migration output.
command: mktemp -d command: mktemp -d
become_user: "{{ APPLICATION_USER }}"
register: temp_output_dir register: temp_output_dir
- name: generate list of unapplied migrations - name: generate list of unapplied migrations
command: python manage.py show_unapplied_migrations --output_file "{{ temp_output_dir.stdout }}/{{ unapplied_migrations_output }}" shell: '{{ COMMAND_PREFIX }} show_unapplied_migrations --output_file "{{ temp_output_dir.stdout }}/{{ unapplied_migrations_output }}"'
become: true become_user: "{{ APPLICATION_USER }}"
become_user: "{{ application_user }}"
args:
chdir: "{{ application_path }}"
- name: migrate to apply any unapplied migrations - name: migrate to apply any unapplied migrations
command: python manage.py run_migrations "{{ temp_output_dir.stdout }}/{{ unapplied_migrations_output }}" --output_file "{{ temp_output_dir.stdout }}/{{ migration_output }}" shell: '{{ COMMAND_PREFIX }} run_migrations "{{ temp_output_dir.stdout }}/{{ unapplied_migrations_output }}" --output_file "{{ temp_output_dir.stdout }}/{{ migration_output }}"'
become: true become: true
become_user: "{{ application_user }}" become_user: "{{ APPLICATION_USER }}"
args:
chdir: "{{ application_path }}"
- name: Transfer artifacts to the proper place. - name: Transfer artifacts to the proper place.
copy: fetch:
src: "{{ temp_output_dir.stdout }}/" src: "{{ temp_output_dir.stdout }}/{{ item }}"
dest: "{{ artifact_path }}" dest: "{{ ARTIFACT_PATH }}"
flat: True
fail_on_missing: True
mode: 0700 mode: 0700
with_items:
- "{{ unapplied_migrations_output }}"
- "{{ migration_output }}"
- name: Send Hipchat notification cleanup has finished - name: Send Hipchat notification cleanup has finished
hipchat_2_0_0_1: hipchat_2_0_0_1:
api: "{{ hipchat_url }}" api: "{{ HIPCHAT_URL }}"
token: "{{ hipchat_token }}" token: "{{ HIPCHAT_TOKEN }}"
room: "{{ hipchat_room }}" room: "{{ HIPCHAT_ROOM }}"
msg: "Migrations have completed." msg: "Migrations have completed."
ignore_errors: yes ignore_errors: yes
when: hipchat_token is defined when: hipchat_token is defined
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment