0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-07 22:25:35 +00:00

Add data migration to move Check.body -> Check.body_raw

We used "body" to store request body as text.
In 2022 we added "body_raw" and started to use it to store request
body as bytes.

In python code we currently need to inspect both fields,
because the data could be in "body" (for old pings) or in
"body_raw" (for newer pings). My plan is to eventually get rid
of the "body" field, and have "body_raw" only. This data migration
is a step towards that: for any Ping objects that have non-empty
"body" field, it moves the data to the "body_raw" field. After
applying this migration, the "body" field should be empty (empty
string or null) for all Ping objects.
This commit is contained in:
Pēteris Caune 2024-07-11 14:38:36 +03:00
parent bc8fb90fed
commit daaee30c88
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2

View file

@ -0,0 +1,28 @@
# Generated by Django 5.0.7 on 2024-07-11 10:43
from __future__ import annotations
from typing import Any
from django.apps.registry import Apps
from django.db import migrations
def move_body_to_body_raw(apps: Apps, schema_editor: Any) -> None:
Ping = apps.get_model("api", "Ping")
i = 0
for ping in Ping.objects.exclude(body="").exclude(body=None):
Ping.objects.filter(id=ping.id).update(body_raw=ping.body.encode(), body=None)
i += 1
if i % 1000 == 0:
print(i)
class Migration(migrations.Migration):
dependencies = [
("api", "0107_fix_legacy_timezones"),
]
operations = [
migrations.RunPython(move_body_to_body_raw, migrations.RunPython.noop)
]