# Generated by Django 4.2.30 on 2026-09-16 13:34

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


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0002_user_approval_pin_user_approval_pin_failed_attempts_and_more'),
    ]

    operations = [
        migrations.CreateModel(
            name='Permission',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('codename', models.CharField(max_length=100, unique=True)),
                ('name', models.CharField(max_length=150)),
                ('category', models.CharField(help_text='Groups permissions in the role editor, e.g. "Inventory".', max_length=50)),
                ('kind', models.CharField(choices=[('ACTION', 'Action'), ('COLUMN', 'Column visibility')], default='ACTION', max_length=10)),
            ],
            options={
                'ordering': ['category', 'kind', 'name'],
            },
        ),
        migrations.CreateModel(
            name='Role',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50, unique=True)),
                ('description', models.TextField(blank=True)),
                ('is_system', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('permissions', models.ManyToManyField(blank=True, related_name='roles', to='accounts.permission')),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        # Deliberately NOT an AlterField on the existing 'role' CharField: SQLite's
        # schema editor rebuilds the table in place and tries to copy the old
        # string value ('MANAGER'/'SELLER') straight into the new integer FK
        # column, which fails FK integrity checks. Add the FK under a temporary
        # name instead; migration 0004 populates it from the old column's data
        # while both still exist, then 0005 drops 'role' and renames this into it.
        migrations.AddField(
            model_name='user',
            name='role_v2',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='users', to='accounts.role'),
        ),
    ]
