# Generated by Django 4.2.8 on 2024-05-10 05:43

from django.db import migrations, models
import django.db.models.deletion


def migrate_models(apps, schema_editor):
    try:
        OldModel1 = apps.get_model('netbox_cloud_pilot', 'NetBoxConfiguration')
        OldModel2 = apps.get_model('netbox_cloud_pilot', 'NetBoxDBBackup')
    except LookupError:
        # Skip if the old models don't exist
        return

    NewModel1 = apps.get_model('netbox_paas', 'NetBoxConfiguration')
    NewModel2 = apps.get_model('netbox_paas', 'NetBoxDBBackup')

    # Migrate data from old models to new models
    for old_instance in OldModel1.objects.all():
        new_instance = NewModel1(
            id=old_instance.id,
            key=old_instance.key,
            env_name_storage=old_instance.env_name_storage,
            license=old_instance.license,
            description=old_instance.description,
            created=old_instance.created,
            last_updated=old_instance.last_updated,
            custom_field_data=old_instance.custom_field_data,
            comments=old_instance.comments,
        )
        new_instance.save()

    for old_instance in OldModel2.objects.all():
        new_instance = NewModel2(
            id=old_instance.id,
            created=old_instance.created,
            last_updated=old_instance.last_updated,
            crontab=old_instance.crontab,
            keep_backups=old_instance.keep_backups,
            netbox_env_id=old_instance.netbox_env.id,
        )
        new_instance.save()


class Migration(migrations.Migration):
    dependencies = [
        ('netbox_paas', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(migrate_models),
    ]
