Add a script to backfill placements.
This commit is contained in:
parent
0a62f7f725
commit
471cb26e07
1 changed files with 26 additions and 0 deletions
26
tools/backfillplacements.py
Normal file
26
tools/backfillplacements.py
Normal 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)
|
Reference in a new issue