Made the columns properly referenced in models and migrations.

This commit is contained in:
tilly-Q 2014-04-23 14:59:53 -04:00
parent 7918f86ac0
commit 9adef07e8f
2 changed files with 9 additions and 14 deletions

View File

@ -723,13 +723,11 @@ def drop_MediaEntry_collected(db):
class PrivilegeUserAssociation_R1(declarative_base()): class PrivilegeUserAssociation_R1(declarative_base()):
__tablename__ = 'rename__privileges_users' __tablename__ = 'rename__privileges_users'
privilege_id = Column( user_id = Column(
'id_of_privilege',
Integer, Integer,
ForeignKey(User.id), ForeignKey(User.id),
primary_key=True) primary_key=True)
user_id = Column( privilege_id = Column(
'id_of_user',
Integer, Integer,
ForeignKey(Privilege.id), ForeignKey(Privilege.id),
primary_key=True) primary_key=True)
@ -739,7 +737,7 @@ def fix_privilege_user_association_table(db):
""" """
There was an error in the PrivilegeUserAssociation table that allowed for a 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 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 = MetaData(bind=db.bind)
@ -752,10 +750,11 @@ def fix_privilege_user_association_table(db):
metadata, 'rename__privileges_users') metadata, 'rename__privileges_users')
result = db.execute(privilege_user_assoc.select()) result = db.execute(privilege_user_assoc.select())
for row in result: 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( db.execute(new_privilege_user_assoc.insert().values(
id_of_privilege=priv_id, user_id=user_id,
id_of_user=user_id)) privilege_id=priv_id))
db.commit() db.commit()
@ -763,5 +762,3 @@ def fix_privilege_user_association_table(db):
new_privilege_user_assoc.rename('core__privileges_users') new_privilege_user_assoc.rename('core__privileges_users')
db.commit() db.commit()

View File

@ -875,13 +875,11 @@ class PrivilegeUserAssociation(Base):
__tablename__ = 'core__privileges_users' __tablename__ = 'core__privileges_users'
privilege_id = Column( user_id = Column(
'id_of_privilege',
Integer, Integer,
ForeignKey(User.id), ForeignKey(User.id),
primary_key=True) primary_key=True)
user_id = Column( privilege_id = Column(
'id_of_user',
Integer, Integer,
ForeignKey(Privilege.id), ForeignKey(Privilege.id),
primary_key=True) primary_key=True)