Fixed an issue where the pgAdmin configuration database wasn't being created on a fresh install when an external database was used for the configuration. #9125

pull/9135/head REL-9_8
Pravesh Sharma 2025-09-02 19:25:04 +05:30 committed by GitHub
parent 5498682934
commit 500a5c7101
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 71 additions and 30 deletions

View File

@ -14,7 +14,7 @@ Supported Database Servers
Bundled PostgreSQL Utilities Bundled PostgreSQL Utilities
**************************** ****************************
**psql**, **pg_dump**, **pg_dumpall**, **pg_restore**: 17.2 **psql**, **pg_dump**, **pg_dumpall**, **pg_restore**: 17.5
New features New features
@ -36,4 +36,5 @@ Bug fixes
| `Issue #9090 <https://github.com/pgadmin-org/pgadmin4/issues/9090>`_ - Pin Paramiko to version 3.5.1 to fix the DSSKey error introduced in the latest release. | `Issue #9090 <https://github.com/pgadmin-org/pgadmin4/issues/9090>`_ - Pin Paramiko to version 3.5.1 to fix the DSSKey error introduced in the latest release.
| `Issue #9095 <https://github.com/pgadmin-org/pgadmin4/issues/9095>`_ - Fixed an issue where pgAdmin config migration was failing while upgrading to v9.7. | `Issue #9095 <https://github.com/pgadmin-org/pgadmin4/issues/9095>`_ - Fixed an issue where pgAdmin config migration was failing while upgrading to v9.7.
| `Issue #9114 <https://github.com/pgadmin-org/pgadmin4/issues/9114>`_ - Fixed Cross-Origin Opener Policy (COOP) vulnerability in the OAuth 2.0 authentication flow (CVE-2025-9636). | `Issue #9114 <https://github.com/pgadmin-org/pgadmin4/issues/9114>`_ - Fixed Cross-Origin Opener Policy (COOP) vulnerability in the OAuth 2.0 authentication flow (CVE-2025-9636).
| `Issue #9116 <https://github.com/pgadmin-org/pgadmin4/issues/9116>`_ - Fixed an issue where editor shortcuts fail when using Option key combinations on macOS, due to macOS treating Option+Key as a different key input. | `Issue #9116 <https://github.com/pgadmin-org/pgadmin4/issues/9116>`_ - Fixed an issue where editor shortcuts fail when using Option key combinations on macOS, due to macOS treating Option+Key as a different key input.
| `Issue #9125 <https://github.com/pgadmin-org/pgadmin4/issues/9125>`_ - Fixed an issue where the pgAdmin configuration database wasn't being created on a fresh install when an external database was used for the configuration.

View File

@ -18,9 +18,7 @@ Create Date: 2025-07-15 12:27:48.780562
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op from alembic import op
from sqlalchemy.orm.session import Session from sqlalchemy.orm.session import Session
from pgadmin.model import Preferences, ModulePreference, PreferenceCategory,\ from pgadmin.model import Preferences, ModulePreference, PreferenceCategory
UserPreference
from pgadmin.browser import register_editor_preferences
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
@ -30,21 +28,11 @@ branch_labels = None
depends_on = None depends_on = None
class Migration:
"""
This is a placeholder class for registering editor preferences
"""
def __init__(self, value=None):
self.editor_preference = value
def upgrade(): def upgrade():
migration_obj = Migration()
register_editor_preferences(migration_obj, migration_gettext=lambda x: x)
session = Session(bind=op.get_bind()) session = Session(bind=op.get_bind())
pref_categories = ['keyboard_shortcuts', 'editor', 'Editor'] old_pref_categories = ['keyboard_shortcuts', 'editor', 'Editor']
new_categories = ['keyboard_shortcuts', 'sql_formatting', 'options'] new_pref_categories = ['keyboard_shortcuts', 'sql_formatting', 'options']
prefs = ['find', 'replace', 'goto_line_col', prefs = ['find', 'replace', 'goto_line_col',
'comment', 'format_sql', 'plain_editor_mode', 'comment', 'format_sql', 'plain_editor_mode',
'code_folding', 'wrap_code', 'insert_pair_brackets', 'code_folding', 'wrap_code', 'insert_pair_brackets',
@ -54,14 +42,76 @@ def upgrade():
'data_type_case', 'spaces_around_operators', 'tab_size', 'data_type_case', 'spaces_around_operators', 'tab_size',
'use_spaces', 'expression_width', 'logical_operator_new_line', 'use_spaces', 'expression_width', 'logical_operator_new_line',
'lines_between_queries', 'new_line_before_semicolon'] 'lines_between_queries', 'new_line_before_semicolon']
preference_map = {
'keyboard_shortcuts': [
'find', 'replace', 'goto_line_col', 'comment', 'format_sql'
],
'options': [
'plain_editor_mode', 'code_folding', 'cursor_blink_rate',
'wrap_code', 'insert_pair_brackets', 'highlight_selection_matches',
'brace_matching', 'sql_font_size', 'sql_font_ligatures',
'sql_font_family', 'indent_new_line'
],
'sql_formatting': [
'keyword_case', 'identifier_case', 'function_case',
'data_type_case', 'spaces_around_operators', 'tab_size',
'use_spaces', 'expression_width', 'logical_operator_new_line',
'lines_between_queries', 'new_line_before_semicolon'
]
}
category_ids = [] category_ids = []
new_ids = [] new_ids = []
pref_map = {} pref_map = {}
# get metadata from current connection
meta = sa.MetaData()
# define table representation
meta.reflect(op.get_bind(), only=('user_preferences', 'module_preference',
'preference_category', 'preferences'))
module_pref_table = sa.Table('module_preference', meta)
module_id = session.query(ModulePreference).filter_by(
name='editor').first()
# Insert the 'editor' module in module_preference table
if not module_id:
op.execute(
module_pref_table.insert().values(name='editor')
)
module_id = session.query(ModulePreference).filter_by(
name='editor').first().id
# Insert the new preference categories in preference_category table
pref_category_table = sa.Table('preference_category', meta)
op.bulk_insert(pref_category_table, [
{'mid': module_id, 'name': 'keyboard_shortcuts'},
{'mid': module_id, 'name': 'sql_formatting'},
{'mid': module_id, 'name': 'options'},
])
# Insert the new preferences in preferences table
prefs_table = sa.Table('preferences', meta)
for category in new_pref_categories:
category_id = session.query(PreferenceCategory
).filter_by(name=category,
mid=module_id).first().id
op.bulk_insert(
prefs_table,
[
{'cid':category_id, 'name': pref_name}
for pref_name in preference_map[category]
]
)
# Migrate the preferences from 'sqleditor' module to 'editor'
category_data = session.query(ModulePreference, PreferenceCategory,).join( category_data = session.query(ModulePreference, PreferenceCategory,).join(
PreferenceCategory).filter( PreferenceCategory).filter(
ModulePreference.name == 'sqleditor', ModulePreference.name == 'sqleditor',
PreferenceCategory.name.in_(pref_categories)).all() PreferenceCategory.name.in_(old_pref_categories)).all()
for module_data, pref_cat in category_data: for module_data, pref_cat in category_data:
category_ids.append(pref_cat.id) category_ids.append(pref_cat.id)
@ -69,7 +119,7 @@ def upgrade():
new_data = session.query(ModulePreference, PreferenceCategory).join( new_data = session.query(ModulePreference, PreferenceCategory).join(
PreferenceCategory).filter( PreferenceCategory).filter(
ModulePreference.name == 'editor', PreferenceCategory.name.in_( ModulePreference.name == 'editor', PreferenceCategory.name.in_(
new_categories)).all() new_pref_categories)).all()
for module_data, pref_cat in new_data: for module_data, pref_cat in new_data:
new_ids.append(pref_cat.id) new_ids.append(pref_cat.id)
@ -85,10 +135,6 @@ def upgrade():
if pref.name == new_pref.name: if pref.name == new_pref.name:
pref_map[pref.id] = new_pref.id 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) user_pref_table = sa.Table('user_preferences', meta)
# Update the user preferences with new preference ids # Update the user preferences with new preference ids

View File

@ -18,16 +18,10 @@ LOWER_CASE_STR = gettext('Lower case')
PRESERVE_STR = gettext('Preserve') PRESERVE_STR = gettext('Preserve')
def register_editor_preferences(self, migration_gettext=None): def register_editor_preferences(self):
""" """
Registers the editor preferences Registers the editor preferences
""" """
# migration_getttext is used once in case of migration
# In that case gettext will be used from migration_gettext
# instead of flask_babel gettext.
from flask_babel import gettext
if migration_gettext is not None:
gettext = migration_gettext
self.editor_preference = Preferences( self.editor_preference = Preferences(
'editor', gettext('Editor') 'editor', gettext('Editor')