# Generated by Django 3.2.9 on 2025-08-24 00:29

from django.conf import settings
import django.contrib.gis.db.models.fields
import django.contrib.postgres.indexes
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('rog', '0005_create_gps_tables'),
    ]

    operations = [
        migrations.CreateModel(
            name='Location2025',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('cp_number', models.IntegerField(db_index=True, verbose_name='CP番号')),
                ('cp_name', models.CharField(max_length=255, verbose_name='CP名')),
                ('latitude', models.FloatField(blank=True, null=True, verbose_name='緯度')),
                ('longitude', models.FloatField(blank=True, null=True, verbose_name='経度')),
                ('location', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='位置')),
                ('cp_point', models.IntegerField(default=10, verbose_name='チェックポイント得点')),
                ('photo_point', models.IntegerField(default=0, verbose_name='写真ポイント')),
                ('buy_point', models.IntegerField(default=0, verbose_name='買い物ポイント')),
                ('checkin_radius', models.FloatField(default=15.0, verbose_name='チェックイン範囲(m)')),
                ('auto_checkin', models.BooleanField(default=False, verbose_name='自動チェックイン')),
                ('shop_closed', models.BooleanField(default=False, verbose_name='休業中')),
                ('shop_shutdown', models.BooleanField(default=False, verbose_name='閉業')),
                ('opening_hours', models.TextField(blank=True, null=True, verbose_name='営業時間')),
                ('address', models.CharField(blank=True, max_length=512, null=True, verbose_name='住所')),
                ('phone', models.CharField(blank=True, max_length=32, null=True, verbose_name='電話番号')),
                ('website', models.URLField(blank=True, null=True, verbose_name='ウェブサイト')),
                ('description', models.TextField(blank=True, null=True, verbose_name='説明')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='有効')),
                ('sort_order', models.IntegerField(default=0, verbose_name='表示順')),
                ('csv_source_file', models.CharField(blank=True, max_length=255, null=True, verbose_name='CSVファイル名')),
                ('csv_upload_date', models.DateTimeField(blank=True, null=True, verbose_name='CSVアップロード日時')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='作成日時')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新日時')),
            ],
            options={
                'verbose_name': 'チェックポイント2025',
                'verbose_name_plural': 'チェックポイント2025',
                'db_table': 'rog_location2025',
                'ordering': ['event', 'sort_order', 'cp_number'],
            },
        ),

        migrations.RemoveIndex(
            model_name='gpscheckin',
            name='rog_gpschec_event_c_9f1a75_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpscheckin',
            name='rog_gpschec_zekken_8e7f42_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpscheckin',
            name='rog_gpschec_serial__1b5e3a_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpscheckin',
            name='rog_gpschec_cp_numb_d7c8e5_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpslog',
            name='rog_gpslog_event_c_8a2b94_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpslog',
            name='rog_gpslog_zekken_7c5f39_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpslog',
            name='rog_gpslog_serial__6d4e28_idx',
        ),
        migrations.RemoveIndex(
            model_name='gpslog',
            name='rog_gpslog_cp_numb_5b3a17_idx',
        ),
        migrations.RemoveIndex(
            model_name='newevent2',
            name='rog_neweven_event_c_e79a96_idx',
        ),
        migrations.RemoveIndex(
            model_name='team',
            name='rog_team_zekken__2c50d1_idx',
        ),
        migrations.RenameField(
            model_name='gpslog',
            old_name='record_time',
            new_name='create_at',
        ),
        migrations.RenameField(
            model_name='gpslog',
            old_name='mobserver_id',
            new_name='late_point',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='checkin_time',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='event',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='lat',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='lng',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='location',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='mobserver_id',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='record_time',
        ),
        migrations.RemoveField(
            model_name='gpscheckin',
            name='zekken',
        ),

        migrations.AddField(
            model_name='gpscheckin',
            name='buy_flag',
            field=models.BooleanField(default=False, help_text='購入フラグ：協賛店で購入した場合、無条件でTRUEにする。'),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='colabo_company_memo',
            field=models.TextField(default='', help_text='グループコード：複数のイベントで合算する場合に使用する'),
        ),
        migrations.RunSQL(
            sql="""
            DO $$ 
            BEGIN
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_gpscheckin' 
                    AND column_name = 'create_at'
                ) THEN
                    ALTER TABLE rog_gpscheckin ADD COLUMN create_at TIMESTAMP WITH TIME ZONE;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE rog_gpscheckin DROP COLUMN IF EXISTS create_at CASCADE;"
        ),
        migrations.RunSQL(
            sql="""
            DO $$ 
            BEGIN
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_gpscheckin' 
                    AND column_name = 'create_user'
                ) THEN
                    ALTER TABLE rog_gpscheckin ADD COLUMN create_user TEXT;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE rog_gpscheckin DROP COLUMN IF EXISTS create_user CASCADE;"
        ),
        migrations.RunSQL(
            sql="""
            DO $$ 
            BEGIN
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_gpscheckin' 
                    AND column_name = 'event_id'
                ) THEN
                    ALTER TABLE rog_gpscheckin ADD COLUMN event_id INTEGER;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE rog_gpscheckin DROP COLUMN IF EXISTS event_id CASCADE;"
        ),
        migrations.RunSQL(
            sql="""
            DO $$ 
            BEGIN
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_gpscheckin' 
                    AND column_name = 'goal_time'
                ) THEN
                    ALTER TABLE rog_gpscheckin ADD COLUMN goal_time TEXT;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE rog_gpscheckin DROP COLUMN IF EXISTS goal_time CASCADE;"
        ),
        migrations.RunSQL(
            sql="""
            DO $$ 
            BEGIN
                IF NOT EXISTS (
                    SELECT 1 FROM information_schema.columns 
                    WHERE table_name = 'rog_gpscheckin' 
                    AND column_name = 'image_address'
                ) THEN
                    ALTER TABLE rog_gpscheckin ADD COLUMN image_address TEXT;
                END IF;
            END $$;
            """,
            reverse_sql="ALTER TABLE rog_gpscheckin DROP COLUMN IF EXISTS image_address CASCADE;"
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='image_qr',
            field=models.BooleanField(default=False, help_text='QRコードスキャンフラグ'),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='image_receipt',
            field=models.TextField(blank=True, default=False, help_text='レシート画像のパス', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='late_point',
            field=models.IntegerField(blank=True, help_text='遅刻ポイント：ゴールの時刻が制限時間を超えた場合、１分につき-50点が加算。', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='lattitude',
            field=models.FloatField(blank=True, help_text='緯度：写真から取得', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='longitude',
            field=models.FloatField(blank=True, help_text='経度：写真から取得', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='minus_photo_flag',
            field=models.BooleanField(default=False, help_text='MobServer gps_information.minus_photo_flag'),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='path_order',
            field=models.IntegerField(default=0, help_text='チェックポイントの順序番号'),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='points',
            field=models.IntegerField(blank=True, help_text='ポイント：このチェックインによる獲得ポイント。通常ポイントと買い物ポイントは分離される。ゴールの場合には減点なども含む。', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='update_at',
            field=models.DateTimeField(blank=True, help_text='更新日時', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='update_user',
            field=models.TextField(blank=True, help_text='更新ユーザー', null=True),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='validate_location',
            field=models.BooleanField(default=False, help_text='位置情報検証フラグ：画像認識で検証した結果'),
        ),
        migrations.AddField(
            model_name='gpscheckin',
            name='zekken_number',
            field=models.TextField(default='', help_text='ゼッケン番号'),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='buy_flag',
            field=models.BooleanField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='colabo_company_memo',
            field=models.TextField(default=''),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='create_user',
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='goal_time',
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='image_address',
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='is_service_checked',
            field=models.BooleanField(default=False),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='minus_photo_flag',
            field=models.BooleanField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='score',
            field=models.IntegerField(blank=True, default=0, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='scoreboard_url',
            field=models.URLField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='update_at',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='update_user',
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name='gpslog',
            name='zekken_number',
            field=models.TextField(default=''),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='checkpoint',
            field=models.ForeignKey(blank=True, help_text='統合チェックポイントリレーション', null=True, on_delete=django.db.models.deletion.CASCADE, to='rog.checkpoint'),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='cp_number',
            field=models.IntegerField(blank=True, help_text='チェックポイント番号', null=True),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='event_code',
            field=models.TextField(default='', help_text='イベントコード'),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='id',
            field=models.AutoField(primary_key=True, serialize=False),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='serial_number',
            field=models.IntegerField(blank=True, help_text='MobServer gps_information.serial_number', null=True),
        ),
        migrations.AlterField(
            model_name='gpscheckin',
            name='team',
            field=models.ForeignKey(blank=True, help_text='統合チームリレーション', null=True, on_delete=django.db.models.deletion.CASCADE, to='rog.team'),
        ),
        migrations.AlterField(
            model_name='gpslog',
            name='checkin_time',
            field=models.DateTimeField(auto_now_add=True),
        ),
        migrations.AlterField(
            model_name='gpslog',
            name='cp_number',
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name='gpslog',
            name='event_code',
            field=models.TextField(default=''),
        ),
        migrations.AlterField(
            model_name='gpslog',
            name='id',
            field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
        ),
        migrations.AlterField(
            model_name='gpslog',
            name='serial_number',
            field=models.IntegerField(),
        ),
        migrations.AlterField(
            model_name='newevent2',
            name='event_code',
            field=models.CharField(blank=True, max_length=50, null=True, unique=True),
        ),
        migrations.AlterField(
            model_name='newevent2',
            name='event_day',
            field=models.CharField(blank=True, max_length=20, null=True),
        ),
        migrations.AlterField(
            model_name='newevent2',
            name='start_time',
            field=models.CharField(blank=True, max_length=20, null=True),
        ),
        migrations.AlterField(
            model_name='team',
            name='created_at',
            field=models.DateTimeField(auto_now_add=True, null=True),
        ),
        migrations.AlterField(
            model_name='team',
            name='trial',
            field=models.BooleanField(default=False),
        ),
        migrations.AlterField(
            model_name='team',
            name='updated_at',
            field=models.DateTimeField(auto_now=True, null=True),
        ),
        migrations.AlterField(
            model_name='team',
            name='zekken_number',
            field=models.CharField(blank=True, max_length=20, null=True),
        ),
        migrations.AlterUniqueTogether(
            name='gpslog',
            unique_together={('serial_number', 'zekken_number', 'event_code', 'colabo_company_memo')},
        ),
        migrations.AddIndex(
            model_name='checkpoint',
            index=django.contrib.postgres.indexes.GistIndex(fields=['location'], name='idx_checkpoint_location'),
        ),
        migrations.AddIndex(
            model_name='gpscheckin',
            index=models.Index(fields=['zekken_number', 'event_code', 'path_order'], name='idx_zekken_event'),
        ),
        migrations.AddIndex(
            model_name='gpscheckin',
            index=models.Index(fields=['create_at'], name='idx_create_at'),
        ),
        migrations.AddIndex(
            model_name='gpslog',
            index=models.Index(fields=['zekken_number', 'event_code'], name='gpslog_zekken_event_idx'),
        ),
        migrations.AddIndex(
            model_name='gpslog',
            index=models.Index(fields=['create_at'], name='gpslog_create_at_idx'),
        ),
        migrations.AddConstraint(
            model_name='team',
            constraint=models.UniqueConstraint(condition=models.Q(('event__isnull', False), ('zekken_number__isnull', False)), fields=('zekken_number', 'event'), name='unique_team_per_event'),
        ),
        migrations.AlterModelTable(
            name='gpscheckin',
            table='gps_checkins',
        ),

        migrations.AddField(
            model_name='location2025',
            name='created_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location2025_created', to=settings.AUTH_USER_MODEL, verbose_name='作成者'),
        ),
        migrations.AddField(
            model_name='location2025',
            name='csv_upload_user',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location2025_csv_uploads', to=settings.AUTH_USER_MODEL, verbose_name='CSVアップロードユーザー'),
        ),
        migrations.AddField(
            model_name='location2025',
            name='event',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rog.newevent2', verbose_name='イベント'),
        ),
        migrations.AddField(
            model_name='location2025',
            name='updated_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='location2025_updated', to=settings.AUTH_USER_MODEL, verbose_name='更新者'),
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='checkpoint',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='event',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='lat',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='lng',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='location',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='team',
        ),
        migrations.RemoveField(
            model_name='gpslog',
            name='zekken',
        ),
        migrations.AddIndex(
            model_name='location2025',
            index=models.Index(fields=['event', 'cp_number'], name='location2025_event_cp_idx'),
        ),
        migrations.AddIndex(
            model_name='location2025',
            index=models.Index(fields=['event', 'is_active'], name='location2025_event_active_idx'),
        ),
        migrations.AddIndex(
            model_name='location2025',
            index=models.Index(fields=['csv_upload_date'], name='location2025_csv_date_idx'),
        ),
        migrations.AddIndex(
            model_name='location2025',
            index=django.contrib.postgres.indexes.GistIndex(fields=['location'], name='location2025_location_gist_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='location2025',
            unique_together={('cp_number', 'event')},
        ),
    ]
