class PrivilegeUserAssociation_R1(declarative_base()):
__tablename__ = 'rename__privileges_users'
- privilege_id = Column(
- 'id_of_privilege',
+ user_id = Column(
Integer,
ForeignKey(User.id),
primary_key=True)
- user_id = Column(
- 'id_of_user',
+ privilege_id = Column(
Integer,
ForeignKey(Privilege.id),
primary_key=True)
"""
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.
+ unique, and properly referenced.
"""
metadata = MetaData(bind=db.bind)
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']
+ # The columns were improperly named before, so we switch the columns
+ user_id, priv_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))
+ user_id=user_id,
+ privilege_id=priv_id))
db.commit()
new_privilege_user_assoc.rename('core__privileges_users')
db.commit()
-
-