Renamed the columns on core__privileges_users table so that they are unique and
authortilly-Q <nattilypigeonfowl@gmail.com>
Tue, 22 Apr 2014 17:32:47 +0000 (13:32 -0400)
committertilly-Q <nattilypigeonfowl@gmail.com>
Tue, 22 Apr 2014 18:36:23 +0000 (14:36 -0400)
will not cause any more problems.

mediagoblin/db/migrations.py
mediagoblin/db/models.py

index 426080a2def9b0b573ef182e01336fa0e8489efd..66b503b573e74de56a290c856ed1db94e9925689 100644 (file)
@@ -720,3 +720,48 @@ def drop_MediaEntry_collected(db):
     media_collected.drop()
 
     db.commit()
+
+class PrivilegeUserAssociation_R1(declarative_base()):
+    __tablename__ = 'rename__privileges_users'
+    privilege_id = Column(
+        'id_of_privilege',
+        Integer,
+        ForeignKey(User.id),
+        primary_key=True)
+    user_id = Column(
+        'id_of_user',
+        Integer,
+        ForeignKey(Privilege.id),
+        primary_key=True)
+
+@RegisterMigration(20, MIGRATIONS)
+def fix_privilege_user_association_table(db):
+    """
+    There was an error in the PrivilegeUserAssociation table that allowed for a
+    dangerous sql error. We need to the change the name of the columns to be
+    unique.
+    """
+    metadata = MetaData(bind=db.bind)
+
+    privilege_user_assoc = inspect_table(
+        metadata, 'core__privileges_users')
+    PrivilegeUserAssociation_R1.__table__.create(db.bind)
+    db.commit()
+
+    new_privilege_user_assoc = inspect_table(
+        metadata, 'rename__privileges_users')
+    result = db.execute(privilege_user_assoc.select())
+    for row in result:
+        priv_id, user_id = row['core__privilege_id'], row['core__user_id']
+        db.execute(new_privilege_user_assoc.insert().values(
+            id_of_privilege=priv_id,
+            id_of_user=user_id))
+
+    db.commit()
+
+    privilege_user_assoc.drop()
+    new_privilege_user_assoc.rename('core__privileges_users')
+
+    db.commit()
+
+    
index b750375d7b68b12b560c4fcb80dd93686e1d6585..58635419896586c0402f6d5f8157687bdc9dcc8d 100644 (file)
@@ -876,12 +876,12 @@ class PrivilegeUserAssociation(Base):
     __tablename__ = 'core__privileges_users'
 
     privilege_id = Column(
-        'core__privilege_id',
+        'id_of_privilege',
         Integer,
         ForeignKey(User.id),
         primary_key=True)
     user_id = Column(
-        'core__user_id',
+        'id_of_user',
         Integer,
         ForeignKey(Privilege.id),
         primary_key=True)