Fixed an issue where pgAdmin config migration was failing while upgrading to v9.7 #9095

pull/9121/head
Pravesh Sharma 2025-08-28 10:15:35 +05:30 committed by GitHub
parent 09bc544e83
commit 7caaf2de82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 6 deletions

View File

@ -15,6 +15,7 @@ Revises: e24b1c4def17
Create Date: 2025-07-15 12:27:48.780562
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.orm.session import Session
from pgadmin.model import Preferences, ModulePreference, PreferenceCategory,\
@ -84,15 +85,21 @@ def upgrade():
if pref.name == new_pref.name:
pref_map[pref.id] = new_pref.id
# get metadata from current connection
meta = sa.MetaData()
# define table representation
meta.reflect(op.get_bind(), only=('user_preferences',))
user_pref_table = sa.Table('user_preferences', meta)
# Update the user preferences with new preference ids
for key, val in pref_map.items():
record_to_update = session.query(UserPreference).filter_by(
pid=key).first()
if record_to_update:
record_to_update.pid = val
op.execute(
user_pref_table.update().where(
user_pref_table.c.pid == key).values(pid=val)
)
# Delete the old preferences and categories
session.query(Preferences).filter(Preferences.name.in_(prefs),
Preferences.cid.in_(category_ids)
session.query(Preferences).filter(Preferences.cid.in_(category_ids)
).delete(synchronize_session=False)
session.query(PreferenceCategory).filter(