# Generated by Django 2.2 on 2019-08-20 22:27

from django.db import migrations


def update_version_number(apps, schema_editor):
    SequenceDataset = apps.get_model('tantalus', 'SequenceDataset')

    for dataset in SequenceDataset.objects.filter():
        if dataset.name.endswith('_V1'):
            dataset.version_number = 2
        elif dataset.name.endswith('_V2'):
            dataset.version_number = 3
        elif dataset.name.endswith('_V3'):
            dataset.version_number = 4
        dataset.save()

    for dataset in SequenceDataset.objects.filter():
        if dataset.name.endswith('_V1'):
            dataset.name = dataset.name[:-3]
        elif dataset.name.endswith('_V2'):
            dataset.name = dataset.name[:-3]
        elif dataset.name.endswith('_V3'):
            dataset.name = dataset.name[:-3]
        dataset.name = dataset.name + '_V{}'.format(dataset.version_number)
        assert '__' not in dataset.name
        dataset.save()


class Migration(migrations.Migration):

    dependencies = [
        ('tantalus', '0119_auto_20190820_2217'),
    ]

    operations = [
        migrations.RunPython(update_version_number)
    ]

