from django.core.management.base import BaseCommand
from service.utils import run_sql_command, log_to_telegram

CMD_PIVOT_DIST = """CALL public.pivot_dist();"""

CMD_PIVOT_DIST_PRE = """CALL public.prepivot_dist();"""
class Command(BaseCommand):
    help = 'Create views'

    def handle(self, *args, **kwargs):
        try:
            log_to_telegram('Creating views')
            run_sql_command(CMD_PIVOT_DIST)
            log_to_telegram('pivot_dist created')
            run_sql_command(CMD_PIVOT_DIST_PRE)
            log_to_telegram('prepivot_dist created')
        except Exception as e:
            log_to_telegram('Error creating views: ' + str(e))