# Generated by Claude Code on 2025-12-27

from django.db import migrations, models


def set_existing_snapshots_to_old_version(apps, schema_editor):
    """Set existing snapshots to 0.8.0 since they use the old filesystem layout."""
    Snapshot = apps.get_model('core', 'Snapshot')
    # Set all existing snapshots to 0.8.0 (the previous version's layout)
    Snapshot.objects.all().update(fs_version='0.8.0')


def reverse_migration(apps, schema_editor):
    """Reverse migration - do nothing."""
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('core', '0027_alter_archiveresult_created_by_and_more'),
    ]

    operations = [
        # Add field with temporary default to allow NULL initially
        migrations.AddField(
            model_name='snapshot',
            name='fs_version',
            field=models.CharField(
                max_length=10,
                default='0.8.0',  # Temporary default for adding the column
                help_text='Filesystem version of this snapshot (e.g., "0.7.0", "0.8.0", "0.9.0"). Used to trigger lazy migration on save().'
            ),
        ),
        # Set existing snapshots to old version
        migrations.RunPython(set_existing_snapshots_to_old_version, reverse_migration),
        # Update default to current version for new snapshots going forward
        migrations.AlterField(
            model_name='snapshot',
            name='fs_version',
            field=models.CharField(
                max_length=10,
                default='0.9.0',  # Hardcoded for this migration - new migration when version bumps
                help_text='Filesystem version of this snapshot (e.g., "0.7.0", "0.8.0", "0.9.0"). Used to trigger lazy migration on save().'
            ),
        ),
    ]
