Files
dashboard-cpsp/backend/apps/operations/migrations/0007_backfill_iotpanel_timestamp.py
T
2026-08-26 13:46:05 +07:00

29 lines
816 B
Python

from datetime import datetime, time
from django.db import migrations
from django.utils import timezone
def backfill_timestamps(apps, schema_editor):
IotPanel = apps.get_model("operations", "IotPanel")
for row in IotPanel.objects.filter(timestamp__isnull=True):
row.timestamp = timezone.make_aware(
datetime.combine(row.date, time(0, 0)), timezone.get_current_timezone()
)
row.save(update_fields=["timestamp"])
def unset_timestamps(apps, schema_editor):
IotPanel = apps.get_model("operations", "IotPanel")
IotPanel.objects.update(timestamp=None)
class Migration(migrations.Migration):
dependencies = [
("operations", "0006_iotpanel_timestamp"),
]
operations = [
migrations.RunPython(backfill_timestamps, unset_timestamps),
]