Skip to content

Commit 500a5c7

Browse files
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
1 parent 5498682 commit 500a5c7

File tree

3 files changed

+71
-30
lines changed

3 files changed

+71
-30
lines changed

docs/en_US/release_notes_9_8.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Supported Database Servers
1414

1515
Bundled PostgreSQL Utilities
1616
****************************
17-
**psql**, **pg_dump**, **pg_dumpall**, **pg_restore**: 17.2
17+
**psql**, **pg_dump**, **pg_dumpall**, **pg_restore**: 17.5
1818

1919

2020
New features
@@ -36,4 +36,5 @@ Bug fixes
3636
| `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.
3737
| `Issue #9095 <https://github.com/pgadmin-org/pgadmin4/issues/9095>`_ - Fixed an issue where pgAdmin config migration was failing while upgrading to v9.7.
3838
| `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).
39-
| `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.
39+
| `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.
40+
| `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.

web/migrations/versions/e6ed5dac37c2_.py

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import sqlalchemy as sa
1919
from alembic import op
2020
from sqlalchemy.orm.session import Session
21-
from pgadmin.model import Preferences, ModulePreference, PreferenceCategory,\
22-
UserPreference
23-
from pgadmin.browser import register_editor_preferences
21+
from pgadmin.model import Preferences, ModulePreference, PreferenceCategory
2422

2523

2624
# revision identifiers, used by Alembic.
@@ -30,21 +28,11 @@
3028
depends_on = None
3129

3230

33-
class Migration:
34-
"""
35-
This is a placeholder class for registering editor preferences
36-
"""
37-
def __init__(self, value=None):
38-
self.editor_preference = value
39-
40-
4131
def upgrade():
42-
migration_obj = Migration()
43-
register_editor_preferences(migration_obj, migration_gettext=lambda x: x)
4432

4533
session = Session(bind=op.get_bind())
46-
pref_categories = ['keyboard_shortcuts', 'editor', 'Editor']
47-
new_categories = ['keyboard_shortcuts', 'sql_formatting', 'options']
34+
old_pref_categories = ['keyboard_shortcuts', 'editor', 'Editor']
35+
new_pref_categories = ['keyboard_shortcuts', 'sql_formatting', 'options']
4836
prefs = ['find', 'replace', 'goto_line_col',
4937
'comment', 'format_sql', 'plain_editor_mode',
5038
'code_folding', 'wrap_code', 'insert_pair_brackets',
@@ -54,22 +42,84 @@ def upgrade():
5442
'data_type_case', 'spaces_around_operators', 'tab_size',
5543
'use_spaces', 'expression_width', 'logical_operator_new_line',
5644
'lines_between_queries', 'new_line_before_semicolon']
45+
preference_map = {
46+
'keyboard_shortcuts': [
47+
'find', 'replace', 'goto_line_col', 'comment', 'format_sql'
48+
],
49+
'options': [
50+
'plain_editor_mode', 'code_folding', 'cursor_blink_rate',
51+
'wrap_code', 'insert_pair_brackets', 'highlight_selection_matches',
52+
'brace_matching', 'sql_font_size', 'sql_font_ligatures',
53+
'sql_font_family', 'indent_new_line'
54+
],
55+
'sql_formatting': [
56+
'keyword_case', 'identifier_case', 'function_case',
57+
'data_type_case', 'spaces_around_operators', 'tab_size',
58+
'use_spaces', 'expression_width', 'logical_operator_new_line',
59+
'lines_between_queries', 'new_line_before_semicolon'
60+
]
61+
}
5762
category_ids = []
5863
new_ids = []
5964
pref_map = {}
6065

66+
# get metadata from current connection
67+
meta = sa.MetaData()
68+
# define table representation
69+
meta.reflect(op.get_bind(), only=('user_preferences', 'module_preference',
70+
'preference_category', 'preferences'))
71+
module_pref_table = sa.Table('module_preference', meta)
72+
73+
module_id = session.query(ModulePreference).filter_by(
74+
name='editor').first()
75+
76+
# Insert the 'editor' module in module_preference table
77+
if not module_id:
78+
op.execute(
79+
module_pref_table.insert().values(name='editor')
80+
)
81+
82+
module_id = session.query(ModulePreference).filter_by(
83+
name='editor').first().id
84+
85+
# Insert the new preference categories in preference_category table
86+
pref_category_table = sa.Table('preference_category', meta)
87+
88+
op.bulk_insert(pref_category_table, [
89+
{'mid': module_id, 'name': 'keyboard_shortcuts'},
90+
{'mid': module_id, 'name': 'sql_formatting'},
91+
{'mid': module_id, 'name': 'options'},
92+
])
93+
94+
# Insert the new preferences in preferences table
95+
prefs_table = sa.Table('preferences', meta)
96+
97+
for category in new_pref_categories:
98+
category_id = session.query(PreferenceCategory
99+
).filter_by(name=category,
100+
mid=module_id).first().id
101+
102+
op.bulk_insert(
103+
prefs_table,
104+
[
105+
{'cid':category_id, 'name': pref_name}
106+
for pref_name in preference_map[category]
107+
]
108+
)
109+
110+
# Migrate the preferences from 'sqleditor' module to 'editor'
61111
category_data = session.query(ModulePreference, PreferenceCategory,).join(
62112
PreferenceCategory).filter(
63113
ModulePreference.name == 'sqleditor',
64-
PreferenceCategory.name.in_(pref_categories)).all()
114+
PreferenceCategory.name.in_(old_pref_categories)).all()
65115

66116
for module_data, pref_cat in category_data:
67117
category_ids.append(pref_cat.id)
68118

69119
new_data = session.query(ModulePreference, PreferenceCategory).join(
70120
PreferenceCategory).filter(
71121
ModulePreference.name == 'editor', PreferenceCategory.name.in_(
72-
new_categories)).all()
122+
new_pref_categories)).all()
73123

74124
for module_data, pref_cat in new_data:
75125
new_ids.append(pref_cat.id)
@@ -85,10 +135,6 @@ def upgrade():
85135
if pref.name == new_pref.name:
86136
pref_map[pref.id] = new_pref.id
87137

88-
# get metadata from current connection
89-
meta = sa.MetaData()
90-
# define table representation
91-
meta.reflect(op.get_bind(), only=('user_preferences',))
92138
user_pref_table = sa.Table('user_preferences', meta)
93139

94140
# Update the user preferences with new preference ids

web/pgadmin/browser/register_editor_preferences.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,10 @@
1818
PRESERVE_STR = gettext('Preserve')
1919

2020

21-
def register_editor_preferences(self, migration_gettext=None):
21+
def register_editor_preferences(self):
2222
"""
2323
Registers the editor preferences
2424
"""
25-
# migration_getttext is used once in case of migration
26-
# In that case gettext will be used from migration_gettext
27-
# instead of flask_babel gettext.
28-
from flask_babel import gettext
29-
if migration_gettext is not None:
30-
gettext = migration_gettext
3125

3226
self.editor_preference = Preferences(
3327
'editor', gettext('Editor')

0 commit comments

Comments
 (0)