|
6 | 6 | from django.db import migrations, models |
7 | 7 |
|
8 | 8 |
|
| 9 | +def migrate_webhooks_to_subscriptions(apps, schema_editor): |
| 10 | + Webhook = apps.get_model("notification", "Webhook") |
| 11 | + WebhookSubscription = apps.get_model("notification", "WebhookSubscription") |
| 12 | + |
| 13 | + subscriptions = [ |
| 14 | + WebhookSubscription( |
| 15 | + dataspace=webhook.dataspace, |
| 16 | + target_url=webhook.target, |
| 17 | + is_active=webhook.is_active, |
| 18 | + event=webhook.event, |
| 19 | + extra_payload=webhook.extra_payload, |
| 20 | + extra_headers=webhook.extra_headers, |
| 21 | + ) |
| 22 | + for webhook in Webhook.objects.select_related("dataspace").iterator() |
| 23 | + ] |
| 24 | + |
| 25 | + WebhookSubscription.objects.bulk_create(subscriptions) |
| 26 | + |
| 27 | + |
9 | 28 | class Migration(migrations.Migration): |
10 | 29 | dependencies = [ |
11 | 30 | ("dje", "0015_alter_dataspaceconfiguration_purldb_api_key_and_more"), |
@@ -172,4 +191,11 @@ class Migration(migrations.Migration): |
172 | 191 | }, |
173 | 192 | bases=(dje.models.DataspaceForeignKeyValidationMixin, models.Model), |
174 | 193 | ), |
| 194 | + migrations.RunPython( |
| 195 | + migrate_webhooks_to_subscriptions, |
| 196 | + reverse_code=migrations.RunPython.noop, |
| 197 | + ), |
| 198 | + migrations.DeleteModel( |
| 199 | + name="Webhook", |
| 200 | + ), |
175 | 201 | ] |
0 commit comments