Merge remote-tracking branch 'refs/remotes/tilly-q/ticket-874' into mergetest
Conflicts: mediagoblin/db/migrations.py
This commit is contained in:
commit
70bceff85f
@ -708,6 +708,7 @@ def create_moderation_tables(db):
|
|||||||
is_admin.drop()
|
is_admin.drop()
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
@RegisterMigration(19, MIGRATIONS)
|
@RegisterMigration(19, MIGRATIONS)
|
||||||
def drop_MediaEntry_collected(db):
|
def drop_MediaEntry_collected(db):
|
||||||
"""
|
"""
|
||||||
@ -722,6 +723,7 @@ def drop_MediaEntry_collected(db):
|
|||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
@RegisterMigration(20, MIGRATIONS)
|
@RegisterMigration(20, MIGRATIONS)
|
||||||
def add_metadata_column(db):
|
def add_metadata_column(db):
|
||||||
metadata = MetaData(bind=db.bind)
|
metadata = MetaData(bind=db.bind)
|
||||||
@ -733,3 +735,47 @@ def add_metadata_column(db):
|
|||||||
col.create(media_entry)
|
col.create(media_entry)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
class PrivilegeUserAssociation_R1(declarative_base()):
|
||||||
|
__tablename__ = 'rename__privileges_users'
|
||||||
|
user_id = Column(
|
||||||
|
Integer,
|
||||||
|
ForeignKey(User.id),
|
||||||
|
primary_key=True)
|
||||||
|
privilege_id = Column(
|
||||||
|
Integer,
|
||||||
|
ForeignKey(Privilege.id),
|
||||||
|
primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
@RegisterMigration(21, 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, and properly referenced.
|
||||||
|
"""
|
||||||
|
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:
|
||||||
|
# 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(
|
||||||
|
user_id=user_id,
|
||||||
|
privilege_id=priv_id))
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
privilege_user_assoc.drop()
|
||||||
|
new_privilege_user_assoc.rename('core__privileges_users')
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
@ -877,13 +877,11 @@ class PrivilegeUserAssociation(Base):
|
|||||||
|
|
||||||
__tablename__ = 'core__privileges_users'
|
__tablename__ = 'core__privileges_users'
|
||||||
|
|
||||||
privilege_id = Column(
|
user_id = Column(
|
||||||
'core__privilege_id',
|
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(User.id),
|
ForeignKey(User.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
user_id = Column(
|
privilege_id = Column(
|
||||||
'core__user_id',
|
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(Privilege.id),
|
ForeignKey(Privilege.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user