# Generated by Django 3.2.9 on 2025-08-24 22:16

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('rog', '0007_add_validation_fields'),
    ]

    operations = [
        # 安全な条件付きテーブル操作
        migrations.RunSQL(
            """
            DO $$
            BEGIN
                -- TeamStartテーブルが存在する場合のみフィールドを削除
                IF EXISTS (SELECT FROM pg_tables WHERE tablename = 'rog_teamstart') THEN
                    ALTER TABLE rog_teamstart DROP COLUMN IF EXISTS entry_id;
                END IF;
                
                -- TeamGoalテーブルが存在する場合のみ削除
                IF EXISTS (SELECT FROM pg_tables WHERE tablename = 'rog_teamgoal') THEN
                    DROP TABLE rog_teamgoal;
                END IF;
                
                -- TeamStartテーブルが存在する場合のみ削除
                IF EXISTS (SELECT FROM pg_tables WHERE tablename = 'rog_teamstart') THEN
                    DROP TABLE rog_teamstart;
                END IF;
                
                -- zekken_labelカラムが存在しない場合のみ追加
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_entry' 
                    AND column_name = 'zekken_label'
                ) THEN
                    ALTER TABLE rog_entry ADD COLUMN zekken_label VARCHAR(255) NULL;
                END IF;
            END
            $$;
            """,
            reverse_sql=migrations.RunSQL.noop
        ),
    ]
