# Generated manually on 2025-08-30 to fix pghistory event table schema

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("accounts", "0010_auto_20250830_1657"),
        ("django_cloudflareimages_toolkit", "0001_initial"),
    ]

    operations = [
        # Remove the old avatar field from the event table
        migrations.RunSQL(
            "ALTER TABLE accounts_userprofileevent DROP COLUMN IF EXISTS avatar;",
            reverse_sql="-- Cannot reverse this operation",
        ),
        # Add the new avatar_id field to match the main table (only if it doesn't exist)
        migrations.RunSQL(
            """
            DO $$
            BEGIN
                IF NOT EXISTS (
                    SELECT column_name
                    FROM information_schema.columns
                    WHERE table_name='accounts_userprofileevent'
                    AND column_name='avatar_id'
                ) THEN
                    ALTER TABLE accounts_userprofileevent ADD COLUMN avatar_id uuid;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE accounts_userprofileevent DROP COLUMN IF EXISTS avatar_id;",
        ),
    ]
