# Path: srs/models.py
# class Map(models.Model):
#     name = models.CharField(max_length=128, db_index=True)
#     startpos = models.CharField(max_length=1024, blank=True, null=True)
#     height = models.IntegerField()
#     width = models.IntegerField()
#     metadata2 = JSONTextField(blank=True, null=True, default=None)
# 
#     def __repr__(self):
#         return "Map({}, {})".format(self.pk, self.name)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse("srs/rmap", args=[self.name])
# 
#     @property
#     def replay_count(self):
#         return Replay.objects.filter(map_info=self).count()
# 
#     class Meta:
#         ordering = ["name"]


import logging
import time
from django.core.management.base import BaseCommand
from srs.models import Map
# under the GPLv3.
#
# Copyright (C) 2020 Daniel Troeder (daniel #at# admin-box #dot# com)
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Django manage.py command to migrate Map.metadata to Map.metadata2.
"""




logger = logging.getLogger(__name__)


class Command(BaseCommand):
    def handle(self, *args, **options):
        maps = Map.objects.filter(metadata2=None).order_by("pk")
        total = maps.count()
        logger.info("Going to migrate %d metadata fields...", total)
        for current, a_map in enumerate(maps, start=1):
            logger.info("Migrating %d/%d: %r...", current, total, a_map)
            a_map.metadata2 = a_map.metadata
            a_map.save(update_fields=("metadata2",))
            time.sleep(0.2)  # be gentile to the lobby servers I/O
        logger.info("Finished migrating metadata fields.")
        logger.info(
            "Maps with empty 'metadata2' fields: %d",

# Path: srs/models.py
# class Map(models.Model):
#     name = models.CharField(max_length=128, db_index=True)
#     startpos = models.CharField(max_length=1024, blank=True, null=True)
#     height = models.IntegerField()
#     width = models.IntegerField()
#     metadata2 = JSONTextField(blank=True, null=True, default=None)
# 
#     def __repr__(self):
#         return "Map({}, {})".format(self.pk, self.name)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse("srs/rmap", args=[self.name])
# 
#     @property
#     def replay_count(self):
#         return Replay.objects.filter(map_info=self).count()
# 
#     class Meta:
#         ordering = ["name"]


# Path: srs/management/commands/migarate_metadata_field.py
import logging
import time
from django.core.management.base import BaseCommand
from srs.models import Map

# under the GPLv3.
#
# Copyright (C) 2020 Daniel Troeder (daniel #at# admin-box #dot# com)
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Django manage.py command to migrate Map.metadata to Map.metadata2.
"""




logger = logging.getLogger(__name__)


class Command(BaseCommand):
    def handle(self, *args, **options):
        maps = Map.objects.filter(metadata2=None).order_by("pk")
        total = maps.count()
        logger.info("Going to migrate %d metadata fields...", total)
        for current, a_map in enumerate(maps, start=1):
            logger.info("Migrating %d/%d: %r...", current, total, a_map)
            a_map.metadata2 = a_map.metadata
            a_map.save(update_fields=("metadata2",))
            time.sleep(0.2)  # be gentile to the lobby servers I/O
        logger.info("Finished migrating metadata fields.")
        logger.info(
            "Maps with empty 'metadata2' fields: %d",

            Map.objects.filter(metadata2=None).count(),