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):
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,

View file

@ -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()

View file

@ -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)