Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit field back population migration #28287

Merged
merged 4 commits into from
Aug 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions corehq/apps/hqadmin/migrations/0018_back_populate_deploy_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 2.2.13 on 2020-07-30 18:59

from django.db import migrations
from corehq.util.django_migrations import skip_on_fresh_install


@skip_on_fresh_install
def back_populate(apps, schema_editor):
HqDeploy = apps.get_model('hqadmin', 'hqdeploy')
for deploy in HqDeploy.objects.all():
if deploy.diff_url and not deploy.commit:
deploy.commit = _get_commit_from_url(deploy.diff_url)
deploy.save()


def _get_commit_from_url(diff_url):
try:
ref_comparison = diff_url.split('/')[-1]
last_deploy_sha, current_deploy_sha = ref_comparison.split('...')
return current_deploy_sha
except ValueError:
# print('not a real diff_url', diff_url)
return None


class Migration(migrations.Migration):

dependencies = [
('hqadmin', '0017_hqdeploy_commit'),
]

operations = [
migrations.RunPython(
back_populate, reverse_code=migrations.RunPython.noop, elidable=True),
]