healthchecks_healthchecks/hc/api/migrations/0107_fix_legacy_timezones.py
Pēteris Caune b2c5e91c70
Implement legacy -> canonical timezone conversion
There are three related changes:

* Removed legacy timezones from hc.lib.tz.all_timezones
* Added data migration to update existing Check.tz values
* For backwards compatibility, added code to automatically
  replace a legacy timezone with a canonical timezone when a
  legacy timezone is passed to an API call

I used the timezone mapping on
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
2024-06-14 12:55:57 +03:00

25 lines
601 B
Python

# Generated by Django 5.0.4 on 2024-06-14 09:42
from __future__ import annotations
from typing import Any
from django.apps.registry import Apps
from django.db import migrations
from hc.lib.tz import legacy_timezones
def fix_tz(apps: Apps, schema_editor: Any) -> None:
Check = apps.get_model("api", "Check")
for old, new in legacy_timezones.items():
Check.objects.filter(tz=old).update(tz=new)
class Migration(migrations.Migration):
dependencies = [
("api", "0106_fix_tz_kiev_kyiv"),
]
operations = [migrations.RunPython(fix_tz, migrations.RunPython.noop)]