# Generated by Django 6.0.3 on 2026-08-04 03:26

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


def copy_version_files(apps, schema_editor):
    """Move each Version's single file into a VersionFile row."""
    Version = apps.get_model('library', 'Version')
    VersionFile = apps.get_model('library', 'VersionFile')
    for version in Version.objects.all():
        if version.file_id:
            VersionFile.objects.create(
                version=version, file_id=version.file_id, kind='release',
            )


class Migration(migrations.Migration):

    dependencies = [
        ('library', '0004_projectdraft_tempupload'),
    ]

    operations = [
        migrations.CreateModel(
            name='VersionFile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('kind', models.CharField(choices=[('release', 'Release'), ('markdown', 'Markdown'), ('png', 'PNG')], default='release', max_length=16)),
                ('note', models.CharField(blank=True, default='', max_length=255)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='version_file', to='library.fileindex')),
                ('version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='files', to='library.version')),
            ],
            options={
                'ordering': ['created_at', 'pk'],
            },
        ),
        migrations.RunPython(copy_version_files, migrations.RunPython.noop),
        migrations.RemoveField(
            model_name='version',
            name='file',
        ),
    ]
