from django.core.management.base import BaseCommand
from django.db import connection


class Command(BaseCommand):
    help = "Copy ChartRecord data from scrobbles to charts app"

    def handle(self, *args, **options):
        with connection.cursor() as cursor:
            cursor.execute(
                """
                INSERT OR IGNORE INTO charts_chartrecord 
                (created, modified, user_id, rank, count, year, month, week, day, 
                 video_id, series_id, artist_id, track_id, period_start, period_end)
                SELECT created, modified, user_id, rank, count, year, month, week, day,
                       video_id, series_id, artist_id, track_id, period_start, period_end
                FROM scrobbles_chartrecord
            """
            )
            self.stdout.write(
                self.style.SUCCESS("Copied ChartRecord data to charts app")
            )
