from django.db import migrations

class Migration(migrations.Migration):
    dependencies = [
        ('users', '0010_add_enhanced_permissions'),
    ]

    operations = [
        migrations.RunSQL(
            """
            SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS 
                              WHERE TABLE_SCHEMA = DATABASE() 
                              AND TABLE_NAME = 'role_permissions' 
                              AND COLUMN_NAME = 'is_default');
            SET @sql = IF(@col_exists = 0, 
                         'ALTER TABLE role_permissions ADD COLUMN is_default TINYINT(1) NOT NULL DEFAULT 1', 
                         'SELECT "Column already exists"');
            PREPARE stmt FROM @sql;
            EXECUTE stmt;
            DEALLOCATE PREPARE stmt;
            """,
            "ALTER TABLE role_permissions DROP COLUMN is_default;"
        ),
    ]
