Fix migration issues:

- MySQL 5.5 doesn't support the now() call as a default
  - Postgres migration isn't auto-committed, so we have to check if the table exists first
This commit is contained in:
Joseph Schorr 2014-11-03 15:25:55 -05:00
parent 225c2be355
commit 9aa72c5cc2
3 changed files with 21 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import zlib
import sys
from data import model
from data.database import ImageStorage
from data.database import ImageStorage, configure
from app import app, storage as store
from data.database import db, db_random_func
from util.gzipstream import ZLIB_GZIP_WINDOW
@ -14,11 +14,13 @@ logger = logging.getLogger(__name__)
CHUNK_SIZE = 5 * 1024 * 1024
def backfill_sizes_from_data():
logger.setLevel(logging.DEBUG)
logger.debug('Starting uncompressed image size backfill')
# Make sure we have a reference to the current DB.
configure(app.config)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch = logging.StreamHandler(sys.stdout)
@ -27,6 +29,14 @@ def backfill_sizes_from_data():
encountered = set()
# Try reading the ImageStorage table count. If it doesn't exist, then this is a postgres
# initial setup migration and we can skip this step anyway.
try:
ImageStorage.select().count()
except:
logger.debug('Skipping migration for new setup')
return
while True:
# Load the record from the DB.
batch_ids = list(ImageStorage