Tweak the uuid backfill to leave the uuid column nullable.

This commit is contained in:
Jake Moshenko 2014-11-19 15:32:30 -05:00
parent 7c8a438b58
commit e863b96166
3 changed files with 11 additions and 10 deletions

View file

@ -137,7 +137,7 @@ class BaseModel(ReadSlaveModel):
class User(BaseModel): 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) username = CharField(unique=True, index=True)
password_hash = CharField(null=True) password_hash = CharField(null=True)
email = CharField(unique=True, index=True, email = CharField(unique=True, index=True,

View file

@ -15,8 +15,9 @@ import sqlalchemy as sa
from sqlalchemy.dialects import mysql from sqlalchemy.dialects import mysql
from util.backfill_user_uuids import backfill_user_uuids from util.backfill_user_uuids import backfill_user_uuids
def upgrade(tables): 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() backfill_user_uuids()

View file

@ -1,7 +1,7 @@
import logging import logging
import uuid import uuid
from data.database import User, configure, db from data.database import User, db
from app import app from app import app
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@ -11,15 +11,14 @@ def backfill_user_uuids():
LOGGER.setLevel(logging.DEBUG) LOGGER.setLevel(logging.DEBUG)
LOGGER.debug('User UUID Backfill: Began execution') 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. # Check to see if any users are missing uuids.
has_missing_uuids = bool(list(User has_missing_uuids = True
.select(User.id) try:
.where(User.uuid >> None) User.select().where(User.uuid >> None).get()
.limit(1))) except User.DoesNotExist:
has_missing_uuids = False
if not has_missing_uuids: if not has_missing_uuids:
LOGGER.debug('User UUID Backfill: No migration needed') LOGGER.debug('User UUID Backfill: No migration needed')
return return
@ -46,6 +45,7 @@ def backfill_user_uuids():
except User.DoesNotExist: except User.DoesNotExist:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logging.getLogger('boto').setLevel(logging.CRITICAL) logging.getLogger('boto').setLevel(logging.CRITICAL)