Adds the full Django application layer on top of sportstime_parser: - core: Sport, Team, Stadium, Game models with aliases and league structure - scraper: orchestration engine, adapter, job management, Celery tasks - cloudkit: CloudKit sync client, sync state tracking, sync jobs - dashboard: staff dashboard for monitoring scrapers, sync, review queue - notifications: email reports for scrape/sync results - Docker setup for deployment (Dockerfile, docker-compose, entrypoint) Game exports now use game_datetime_utc (ISO 8601 UTC) instead of venue-local date+time strings, matching the canonical format used by the iOS app. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
121 lines
8.7 KiB
Python
121 lines
8.7 KiB
Python
# Generated by Django 5.1.15 on 2026-01-26 08:59
|
|
|
|
import django.db.models.deletion
|
|
import simple_history.models
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
initial = True
|
|
|
|
dependencies = [
|
|
('core', '0001_initial'),
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='CloudKitConfiguration',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('name', models.CharField(help_text='Configuration name (e.g., "Production", "Development")', max_length=100, unique=True)),
|
|
('environment', models.CharField(choices=[('development', 'Development'), ('production', 'Production')], default='development', max_length=20)),
|
|
('container_id', models.CharField(default='iCloud.com.sportstime.app', help_text='CloudKit container ID (e.g., iCloud.com.sportstime.app)', max_length=200)),
|
|
('key_id', models.CharField(blank=True, help_text='CloudKit API key ID', max_length=200)),
|
|
('private_key', models.TextField(blank=True, help_text='EC P-256 private key content (PEM format). Paste key here OR use path below.')),
|
|
('private_key_path', models.CharField(blank=True, help_text='Path to EC P-256 private key file (alternative to pasting key above)', max_length=500)),
|
|
('is_active', models.BooleanField(default=False, help_text='Whether this configuration is active for syncing')),
|
|
('batch_size', models.PositiveIntegerField(default=200, help_text='Maximum records per batch upload')),
|
|
('auto_sync_after_scrape', models.BooleanField(default=False, help_text='Automatically sync after scraper jobs complete')),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
],
|
|
options={
|
|
'verbose_name': 'CloudKit Configuration',
|
|
'verbose_name_plural': 'CloudKit Configurations',
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='CloudKitSyncJob',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
|
|
('triggered_by', models.CharField(default='manual', help_text='How the sync was triggered', max_length=50)),
|
|
('started_at', models.DateTimeField(blank=True, null=True)),
|
|
('finished_at', models.DateTimeField(blank=True, null=True)),
|
|
('records_synced', models.PositiveIntegerField(default=0)),
|
|
('records_created', models.PositiveIntegerField(default=0)),
|
|
('records_updated', models.PositiveIntegerField(default=0)),
|
|
('records_deleted', models.PositiveIntegerField(default=0)),
|
|
('records_failed', models.PositiveIntegerField(default=0)),
|
|
('record_type_filter', models.CharField(blank=True, help_text='Only sync this record type (all if blank)', max_length=20)),
|
|
('error_message', models.TextField(blank=True)),
|
|
('celery_task_id', models.CharField(blank=True, max_length=255)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('configuration', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sync_jobs', to='cloudkit.cloudkitconfiguration')),
|
|
('sport_filter', models.ForeignKey(blank=True, help_text='Only sync this sport (all if blank)', null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.sport')),
|
|
],
|
|
options={
|
|
'verbose_name': 'CloudKit Sync Job',
|
|
'verbose_name_plural': 'CloudKit Sync Jobs',
|
|
'ordering': ['-created_at'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='CloudKitSyncState',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('record_type', models.CharField(choices=[('Game', 'Game'), ('Team', 'Team'), ('Stadium', 'Stadium')], max_length=20)),
|
|
('record_id', models.CharField(help_text='Local record ID (canonical ID)', max_length=100)),
|
|
('cloudkit_record_name', models.CharField(blank=True, help_text='CloudKit record name (may differ from local ID)', max_length=200)),
|
|
('local_hash', models.CharField(blank=True, help_text='Hash of local record data for change detection', max_length=64)),
|
|
('remote_change_tag', models.CharField(blank=True, help_text='CloudKit change tag for conflict detection', max_length=200)),
|
|
('sync_status', models.CharField(choices=[('pending', 'Pending Sync'), ('synced', 'Synced'), ('failed', 'Failed'), ('deleted', 'Deleted')], default='pending', max_length=20)),
|
|
('last_synced', models.DateTimeField(blank=True, null=True)),
|
|
('last_error', models.TextField(blank=True, help_text='Last sync error message')),
|
|
('retry_count', models.PositiveSmallIntegerField(default=0)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
],
|
|
options={
|
|
'verbose_name': 'CloudKit Sync State',
|
|
'verbose_name_plural': 'CloudKit Sync States',
|
|
'ordering': ['-updated_at'],
|
|
'indexes': [models.Index(fields=['sync_status', 'record_type'], name='cloudkit_cl_sync_st_cc8bf6_idx'), models.Index(fields=['record_type', 'last_synced'], name='cloudkit_cl_record__d82278_idx')],
|
|
'unique_together': {('record_type', 'record_id')},
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='HistoricalCloudKitConfiguration',
|
|
fields=[
|
|
('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
|
('name', models.CharField(db_index=True, help_text='Configuration name (e.g., "Production", "Development")', max_length=100)),
|
|
('environment', models.CharField(choices=[('development', 'Development'), ('production', 'Production')], default='development', max_length=20)),
|
|
('container_id', models.CharField(default='iCloud.com.sportstime.app', help_text='CloudKit container ID (e.g., iCloud.com.sportstime.app)', max_length=200)),
|
|
('key_id', models.CharField(blank=True, help_text='CloudKit API key ID', max_length=200)),
|
|
('private_key', models.TextField(blank=True, help_text='EC P-256 private key content (PEM format). Paste key here OR use path below.')),
|
|
('private_key_path', models.CharField(blank=True, help_text='Path to EC P-256 private key file (alternative to pasting key above)', max_length=500)),
|
|
('is_active', models.BooleanField(default=False, help_text='Whether this configuration is active for syncing')),
|
|
('batch_size', models.PositiveIntegerField(default=200, help_text='Maximum records per batch upload')),
|
|
('auto_sync_after_scrape', models.BooleanField(default=False, help_text='Automatically sync after scraper jobs complete')),
|
|
('created_at', models.DateTimeField(blank=True, editable=False)),
|
|
('updated_at', models.DateTimeField(blank=True, editable=False)),
|
|
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
|
('history_date', models.DateTimeField(db_index=True)),
|
|
('history_change_reason', models.CharField(max_length=100, null=True)),
|
|
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
|
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
|
],
|
|
options={
|
|
'verbose_name': 'historical CloudKit Configuration',
|
|
'verbose_name_plural': 'historical CloudKit Configurations',
|
|
'ordering': ('-history_date', '-history_id'),
|
|
'get_latest_by': ('history_date', 'history_id'),
|
|
},
|
|
bases=(simple_history.models.HistoricalChanges, models.Model),
|
|
),
|
|
]
|