diff --git a/ddcz/migrations/0003_plurals_20241229_1738.py b/ddcz/migrations/0003_plurals_20241229_1738.py index 2ca2317..3de5534 100644 --- a/ddcz/migrations/0003_plurals_20241229_1738.py +++ b/ddcz/migrations/0003_plurals_20241229_1738.py @@ -4,26 +4,37 @@ class Migration(migrations.Migration): - dependencies = [ - ('ddcz', '0002_auto_20240818_1740'), + ("ddcz", "0002_auto_20240818_1740"), ] operations = [ migrations.AlterModelOptions( - name='rangerspell', - options={'verbose_name': 'Hraníčářské kouzlo', 'verbose_name_plural': 'Hraníčářská kouzla'}, + name="rangerspell", + options={ + "verbose_name": "Hraníčářské kouzlo", + "verbose_name_plural": "Hraníčářská kouzla", + }, ), migrations.AlterModelOptions( - name='scheduledemail', - options={'verbose_name': 'Plánovaný e-mail', 'verbose_name_plural': 'Plánované e-maily'}, + name="scheduledemail", + options={ + "verbose_name": "Plánovaný e-mail", + "verbose_name_plural": "Plánované e-maily", + }, ), migrations.AlterModelOptions( - name='schedulednotification', - options={'verbose_name': 'Plánovaná notifikace', 'verbose_name_plural': 'Plánované notifikace'}, + name="schedulednotification", + options={ + "verbose_name": "Plánovaná notifikace", + "verbose_name_plural": "Plánované notifikace", + }, ), migrations.AlterModelOptions( - name='userprofile', - options={'verbose_name': 'Uživatelský profil', 'verbose_name_plural': 'Uživatelské profily'}, + name="userprofile", + options={ + "verbose_name": "Uživatelský profil", + "verbose_name_plural": "Uživatelské profily", + }, ), ] diff --git a/ddcz/migrations/0004_market_created.py b/ddcz/migrations/0004_market_created.py index 3f998d2..9326084 100644 --- a/ddcz/migrations/0004_market_created.py +++ b/ddcz/migrations/0004_market_created.py @@ -4,15 +4,14 @@ class Migration(migrations.Migration): - dependencies = [ - ('ddcz', '0003_plurals_20241229_1738'), + ("ddcz", "0003_plurals_20241229_1738"), ] operations = [ migrations.AddField( - model_name='market', - name='created', - field=models.DateTimeField(blank=True, null=True, verbose_name='Přidáno'), + model_name="market", + name="created", + field=models.DateTimeField(blank=True, null=True, verbose_name="Přidáno"), ), ] diff --git a/ddcz/migrations/0005_market_dates_20241229_1747.py b/ddcz/migrations/0005_market_dates_20241229_1747.py new file mode 100644 index 0000000..fde9047 --- /dev/null +++ b/ddcz/migrations/0005_market_dates_20241229_1747.py @@ -0,0 +1,58 @@ +# Generated by Django 3.1.14 on 2024-12-29 16:47 + +from django.db import migrations +from datetime import datetime + +import sentry_sdk + + +def migrate_dates(apps, schema_editor): + Market = apps.get_model("ddcz", "Market") + + for market in Market.objects.all(): + if not market.published_varchar: + sentry_sdk.capture_message( + f"Market entry without date", + level="error", + extras={ + "market_id": market.id, + "invalid_date": market.published_varchar, + }, + ) + + try: + parsed_date = datetime.strptime(market.published_varchar, "%-d. %-m. %Y") + except ValueError: + # If both formats fail, report to Sentry + sentry_sdk.capture_message( + f"Failed to parse date in Market record", + level="error", + extras={ + "market_id": market.id, + "invalid_date": market.published_varchar, + }, + ) + continue + + market.created = parsed_date + market.save() + + +def reverse_migrate_dates(apps, schema_editor): + Market = apps.get_model("ddcz", "Market") + + for market in Market.objects.all(): + if not market.created: + continue + + # Convert back to the original format with leading zeros + market.published_varchar = market.created.strftime("%d. %m. %Y") + market.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("ddcz", "0004_market_created"), + ] + + operations = [migrations.RunPython(migrate_dates, reverse_migrate_dates)]