Only add the constraint if we need to. Catch an exception if we don't.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 7 Aug 2014 21:29:45 +0000 (16:29 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 7 Aug 2014 21:29:45 +0000 (16:29 -0500)
Also, updating the comment about sqlite being crazy :)

mediagoblin/db/migrations.py

index d8a6d1ce18d2ec17cffdd3b2195c291ee77ca7c9..6ca10b57ae63950d809ac4fd3cda8ed7543d1a5d 100644 (file)
@@ -860,8 +860,8 @@ def revert_username_index(db):
         replace_table_hack(db, user_table, new_user_table)
 
     else:
-        # If the db is not run using SQLite, this process is much simpler...
-        # ...as usual ;)
+        # If the db is not run using SQLite, we don't need to do crazy
+        # table copying.
 
         # Remove whichever of the not-used indexes are in place
         if u'ix_core__users_uploader' in indexes:
@@ -872,9 +872,13 @@ def revert_username_index(db):
             index.drop()
         db.commit()
 
-        # Add the unique constraint
-        constraint = UniqueConstraint(
-            'username', table=user_table)
-        constraint.create()
+        try:
+            # Add the unique constraint
+            constraint = UniqueConstraint(
+                'username', table=user_table)
+            constraint.create()
+        except ProgrammingError:
+            # constraint already exists, no need to add
+            pass
 
     db.commit()