# Generated by Django 2.2.13 on 2021-06-04 07:44

from django.conf import settings
from django.db import migrations, models


def modify_job_templates(apps, schema_editor):

    if not settings.MIGRATE_INITIAL_DATA:
        return

    JobTemplate = apps.get_model('dashboard', 'JobTemplate')

    JobTemplate.objects.filter(job_template_type="pulltrans").update(
        job_template_params="{package_name,repo_type,repo_branch,pipeline_uuid,target_langs,workflow_step}",
        job_template_json_str='{"job":{"ci_pipeline":"%PIPELINE_UUID%","exception":"raise","execution":"sequential",'
                              '"name":"pull translations","package":"%PACKAGE_NAME%","return_type":"json",'
                              '"tasks":[{"download":[{"name":"Pull translations"},{"target_langs":"%TARGET_LANGS%"},'
                              '{"workflow_step":"%WORKFLOW_STEP%"}]},{"upload":[{"name":"Submit translations"},'
                              '{"type":"%REPO_TYPE%"},{"branch":"%REPO_BRANCH%"},{"conflicts":"replace-translated"},'
                              '{"method":"translate"}]}],"type":"pulltrans"}}'
    )


class Migration(migrations.Migration):

    dependencies = [
        ('dashboard', '0011_auto_20210209_1316'),
    ]

    operations = [
        migrations.AddField(
            model_name='package',
            name='downstream_name',
            field=models.CharField(blank=True, max_length=1000, null=True, verbose_name='Downstream Name'),
        ),
        migrations.RunPython(modify_job_templates, reverse_code=migrations.RunPython.noop),
    ]
