# Generated by Django 2.2.13 on 2020-06-16 11:27

from django.db import migrations, transaction
import sequences


def forward(apps, schema_editor):
    Invoice = apps.get_model("oscar_invoices", "Invoice")
    invoices = Invoice.objects.select_for_update().order_by("pk")
    with transaction.atomic():
        last_invoice = invoices.last()
        if last_invoice is not None:
            sequences.get_next_value("oscar_invoices", initial_value=last_invoice.pk)


class Migration(migrations.Migration):

    dependencies = [
        ("oscar_invoices", "0001_initial"),
        ("sequences", "0001_initial"),
    ]

    operations = [
        migrations.RunPython(forward, migrations.RunPython.noop),
    ]
