Add a script to backfill placements.

This commit is contained in:
Jake Moshenko 2014-06-18 13:01:12 -04:00
parent 0a62f7f725
commit 471cb26e07

View file

@ -0,0 +1,26 @@
import logging
logging.basicConfig(level=logging.DEBUG)
from data.database import ImageStorage, ImageStoragePlacement, ImageStorageLocation
from peewee import *
from app import app
logger = logging.getLogger(__name__)
GROUP_SIZE = 1000
storage_needing_placements = (ImageStorage
.select()
.join(ImageStoragePlacement, JOIN_LEFT_OUTER)
.group_by(ImageStorage)
.having(fn.Count(ImageStoragePlacement.id) == 0))
default_location = ImageStorageLocation.get(name=app.config['DS_BACKFILL_LOCATION'])
while storage_needing_placements.count() > 0:
logger.debug('Starting group of %s', GROUP_SIZE)
for needs_placement in list(storage_needing_placements.limit(GROUP_SIZE)):
logger.debug('Adding placement: %s', needs_placement.id)
ImageStoragePlacement.create(storage=needs_placement, location=default_location)