From e863b96166eb56c8959576a7e04cb3909e3007f8 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Wed, 19 Nov 2014 15:32:30 -0500 Subject: [PATCH] Tweak the uuid backfill to leave the uuid column nullable. --- data/database.py | 2 +- .../17f11e265e13_add_uuid_field_to_user.py | 3 ++- util/backfill_user_uuids.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/data/database.py b/data/database.py index 95c0331d7..2cb1a51ca 100644 --- a/data/database.py +++ b/data/database.py @@ -137,7 +137,7 @@ class BaseModel(ReadSlaveModel): class User(BaseModel): - uuid = CharField(default=uuid_generator, max_length=36) + uuid = CharField(default=uuid_generator, max_length=36, null=True) username = CharField(unique=True, index=True) password_hash = CharField(null=True) email = CharField(unique=True, index=True, diff --git a/data/migrations/versions/17f11e265e13_add_uuid_field_to_user.py b/data/migrations/versions/17f11e265e13_add_uuid_field_to_user.py index 7a9da4bea..56943ee8e 100644 --- a/data/migrations/versions/17f11e265e13_add_uuid_field_to_user.py +++ b/data/migrations/versions/17f11e265e13_add_uuid_field_to_user.py @@ -15,8 +15,9 @@ import sqlalchemy as sa from sqlalchemy.dialects import mysql from util.backfill_user_uuids import backfill_user_uuids + def upgrade(tables): - op.add_column('user', sa.Column('uuid', sa.String(length=36), nullable=False)) + op.add_column('user', sa.Column('uuid', sa.String(length=36), nullable=True)) backfill_user_uuids() diff --git a/util/backfill_user_uuids.py b/util/backfill_user_uuids.py index 701004a23..ab9ca4567 100644 --- a/util/backfill_user_uuids.py +++ b/util/backfill_user_uuids.py @@ -1,7 +1,7 @@ import logging import uuid -from data.database import User, configure, db +from data.database import User, db from app import app LOGGER = logging.getLogger(__name__) @@ -11,15 +11,14 @@ def backfill_user_uuids(): LOGGER.setLevel(logging.DEBUG) LOGGER.debug('User UUID Backfill: Began execution') - # Make sure we have a reference to the current DB. - configure(app.config) - LOGGER.debug('User UUID Backfill: Database configured') # Check to see if any users are missing uuids. - has_missing_uuids = bool(list(User - .select(User.id) - .where(User.uuid >> None) - .limit(1))) + has_missing_uuids = True + try: + User.select().where(User.uuid >> None).get() + except User.DoesNotExist: + has_missing_uuids = False + if not has_missing_uuids: LOGGER.debug('User UUID Backfill: No migration needed') return @@ -46,6 +45,7 @@ def backfill_user_uuids(): except User.DoesNotExist: pass + if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) logging.getLogger('boto').setLevel(logging.CRITICAL)