Switch "user_id" to "privilege" and "privilege_id" to "user".
This builds on the previous code Natalie wrote, but makes some changes: - More direct alterations for non-sqlite code - In both cases, I've made it so that we switched the field names from privilege_id and user_id to user and privilege respectively. This way we can do the name swap, but in one case it's "easy": just changing the name. (In the sqlite case it's still tricky though.)
This commit is contained in:
parent
70bceff85f
commit
c56a88b43e
@ -709,6 +709,7 @@ def create_moderation_tables(db):
|
|||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
@RegisterMigration(19, MIGRATIONS)
|
@RegisterMigration(19, MIGRATIONS)
|
||||||
def drop_MediaEntry_collected(db):
|
def drop_MediaEntry_collected(db):
|
||||||
"""
|
"""
|
||||||
@ -739,16 +740,15 @@ def add_metadata_column(db):
|
|||||||
|
|
||||||
class PrivilegeUserAssociation_R1(declarative_base()):
|
class PrivilegeUserAssociation_R1(declarative_base()):
|
||||||
__tablename__ = 'rename__privileges_users'
|
__tablename__ = 'rename__privileges_users'
|
||||||
user_id = Column(
|
user = Column(
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(User.id),
|
ForeignKey(User.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
privilege_id = Column(
|
privilege = Column(
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(Privilege.id),
|
ForeignKey(Privilege.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
@RegisterMigration(21, MIGRATIONS)
|
@RegisterMigration(21, MIGRATIONS)
|
||||||
def fix_privilege_user_association_table(db):
|
def fix_privilege_user_association_table(db):
|
||||||
"""
|
"""
|
||||||
@ -760,6 +760,8 @@ def fix_privilege_user_association_table(db):
|
|||||||
|
|
||||||
privilege_user_assoc = inspect_table(
|
privilege_user_assoc = inspect_table(
|
||||||
metadata, 'core__privileges_users')
|
metadata, 'core__privileges_users')
|
||||||
|
|
||||||
|
if db.bind.url.drivername == 'sqlite':
|
||||||
PrivilegeUserAssociation_R1.__table__.create(db.bind)
|
PrivilegeUserAssociation_R1.__table__.create(db.bind)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
@ -770,12 +772,16 @@ def fix_privilege_user_association_table(db):
|
|||||||
# The columns were improperly named before, so we switch the columns
|
# The columns were improperly named before, so we switch the columns
|
||||||
user_id, priv_id = row['core__privilege_id'], row['core__user_id']
|
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(
|
||||||
user_id=user_id,
|
user=user_id,
|
||||||
privilege_id=priv_id))
|
privilege=priv_id))
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
privilege_user_assoc.drop()
|
privilege_user_assoc.drop()
|
||||||
new_privilege_user_assoc.rename('core__privileges_users')
|
new_privilege_user_assoc.rename('core__privileges_users')
|
||||||
|
|
||||||
|
else:
|
||||||
|
privilege_user_assoc.c.user_id.alter(name="privilege")
|
||||||
|
privilege_user_assoc.c.privilege_id.alter(name="user")
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
@ -877,11 +877,11 @@ class PrivilegeUserAssociation(Base):
|
|||||||
|
|
||||||
__tablename__ = 'core__privileges_users'
|
__tablename__ = 'core__privileges_users'
|
||||||
|
|
||||||
user_id = Column(
|
user = Column(
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(User.id),
|
ForeignKey(User.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
privilege_id = Column(
|
privilege = Column(
|
||||||
Integer,
|
Integer,
|
||||||
ForeignKey(Privilege.id),
|
ForeignKey(Privilege.id),
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user