Skip to content

Commit f83e09b

Browse files
committed
consolidate migration
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 2cf7fdc commit f83e09b

3 files changed

Lines changed: 26 additions & 51 deletions

File tree

notification/migrations/0002_webhooksubscription_webhookdelivery.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
from django.db import migrations, models
77

88

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+
928
class Migration(migrations.Migration):
1029
dependencies = [
1130
("dje", "0015_alter_dataspaceconfiguration_purldb_api_key_and_more"),
@@ -172,4 +191,11 @@ class Migration(migrations.Migration):
172191
},
173192
bases=(dje.models.DataspaceForeignKeyValidationMixin, models.Model),
174193
),
194+
migrations.RunPython(
195+
migrate_webhooks_to_subscriptions,
196+
reverse_code=migrations.RunPython.noop,
197+
),
198+
migrations.DeleteModel(
199+
name="Webhook",
200+
),
175201
]

notification/migrations/0003_migrate_webhook_to_webhooksubscription.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

notification/migrations/0004_delete_webhook.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)