#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4 coding=utf-8
from django.core.management.base import BaseCommand
from django.utils.translation import ugettext as _, ugettext_lazy

from onadata.apps.restservice.models import RestService


class Command(BaseCommand):

    help = ugettext_lazy("Updates KPI rest service endpoint")

    def handle(self, *args, **kwargs):

        rest_services = RestService.objects.filter(name="kpi_hook").all()
        for rest_service in rest_services:
            service_url = rest_service.service_url
            if service_url.endswith("/submissions/"):
                service_url = service_url.replace("/submissions/", "/hook-signal/")
                rest_service.service_url = service_url
                rest_service.save(update_fields=["service_url"])

        print("Done!")

@@ -261,16 +261,348 @@
 ommand):
+%0A    %22%22%22%0A    A faster method is available with PostgreSQL:%0A        UPDATE restservice_restservice%0A            SET service_url = REGEXP_REPLACE(%0A                service_url,%0A                '/assets/(%5B%5E/%5D*)/submissions/',%0A                '/assets/%5C1/hook-signal/'%0A            )%0A            WHERE service_url LIKE '/assets/%25';%0A    %22%22%22
 %0A%0A    he

Include note about SQL command from #523