Added support for post-connection SQL execution, which will be run automatically on each connection made to any database of the server. #4503
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 67 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 43 KiB |
|
|
@ -21,6 +21,7 @@ New features
|
|||
************
|
||||
|
||||
| `Issue #4194 <https://github.com/pgadmin-org/pgadmin4/issues/4194>`_ - Added support to automatically open a file after it is downloaded in the desktop mode.
|
||||
| `Issue #4503 <https://github.com/pgadmin-org/pgadmin4/issues/4503>`_ - Added support for post-connection SQL execution, which will be run automatically on each connection made to any database of the server.
|
||||
| `Issue #5871 <https://github.com/pgadmin-org/pgadmin4/issues/5871>`_ - Add support for restoring plain SQL database dumps.
|
||||
| `Issue #8034 <https://github.com/pgadmin-org/pgadmin4/issues/8034>`_ - Added support for creating Directory nodes in EPAS.
|
||||
| `Issue #8449 <https://github.com/pgadmin-org/pgadmin4/issues/8449>`_ - Change icon buttons to show tooltip even when disabled.
|
||||
|
|
@ -34,6 +35,7 @@ Bug fixes
|
|||
*********
|
||||
|
||||
| `Issue #8006 <https://github.com/pgadmin-org/pgadmin4/issues/8006>`_ - Removed the pre-install script from the Red Hat build function as it was causing a No such file or directory warning during the update.
|
||||
| `Issue #8316 <https://github.com/pgadmin-org/pgadmin4/issues/8316>`_ - Ensure that modal dialogs are not triggered more than once to avoid duplicates.
|
||||
| `Issue #8355 <https://github.com/pgadmin-org/pgadmin4/issues/8355>`_ - Change session files garbage collection strategy.
|
||||
| `Issue #8437 <https://github.com/pgadmin-org/pgadmin4/issues/8437>`_ - Fixed an issue where the PSQL terminal displays keyname for non alphanumeric keys.
|
||||
| `Issue #8462 <https://github.com/pgadmin-org/pgadmin4/issues/8462>`_ - Fixed an issue where geometries in the geometry viewer will render partially when the container was resized.
|
||||
|
|
|
|||
|
|
@ -225,14 +225,14 @@ Use the fields in the *Advanced* tab to configure a connection:
|
|||
|
||||
.. note:: The Password exec option is only supported when pgAdmin is run in desktop mode.
|
||||
|
||||
* Click the *Save* button to save your work.
|
||||
* Click the *Close* button to exit without saving your work.
|
||||
* Click the *Reset* button to return the values specified on the Server dialog
|
||||
to their original condition.
|
||||
Click the *Post Connection SQL* tab to continue.
|
||||
|
||||
.. toctree::
|
||||
.. image:: images/server_post_connection_sql.png
|
||||
:alt: Server dialog post connection sql tab
|
||||
:align: center
|
||||
|
||||
clear_saved_passwords
|
||||
* Use the *Post Connection SQL* field to write the SQL queries that will be
|
||||
executed in autocommit mode for each connection made to any database on this server.
|
||||
|
||||
|
||||
Click the *Tags* tab to continue.
|
||||
|
|
@ -245,6 +245,15 @@ Use the table in the *Tags* tab to add tags. The tags will be shown on the right
|
|||
a server node label in the object explorer tree.
|
||||
|
||||
Click on the *+* button to add a new tag. Some of the parameters are:
|
||||
* *Text* field to specify the tag name.
|
||||
* *Color* field to select the accent color of the tag.
|
||||
|
||||
* *Text* field to specify the tag name.
|
||||
* *Color* field to select the accent color of the tag.
|
||||
|
||||
* Click the *Save* button to save your work.
|
||||
* Click the *Close* button to exit without saving your work.
|
||||
* Click the *Reset* button to return the values specified on the Server dialog
|
||||
to their original condition.
|
||||
|
||||
.. toctree::
|
||||
|
||||
clear_saved_passwords
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
##########################################################################
|
||||
#
|
||||
# pgAdmin 4 - PostgreSQL Tools
|
||||
#
|
||||
# Copyright (C) 2013 - 2025, The pgAdmin Development Team
|
||||
# This software is released under the PostgreSQL Licence
|
||||
#
|
||||
##########################################################################
|
||||
|
||||
"""
|
||||
|
||||
Revision ID: e982c040d9b5
|
||||
Revises: 255e2842e4d7
|
||||
Create Date: 2025-03-13 16:55:26.893395
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e982c040d9b5'
|
||||
down_revision = '255e2842e4d7'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('server', sa.Column('post_connection_sql', sa.String()))
|
||||
|
||||
|
||||
def downgrade():
|
||||
# pgAdmin only upgrades, downgrade not implemented.
|
||||
pass
|
||||
|
|
@ -763,7 +763,8 @@ class ServerNode(PGChildNodeView):
|
|||
'kerberos_conn': 'kerberos_conn',
|
||||
'connection_params': 'connection_params',
|
||||
'prepare_threshold': 'prepare_threshold',
|
||||
'tags': 'tags'
|
||||
'tags': 'tags',
|
||||
'post_connection_sql': 'post_connection_sql'
|
||||
}
|
||||
|
||||
disp_lbl = {
|
||||
|
|
@ -1053,6 +1054,7 @@ class ServerNode(PGChildNodeView):
|
|||
'connection_string': display_connection_str,
|
||||
'prepare_threshold': server.prepare_threshold,
|
||||
'tags': tags,
|
||||
'post_connection_sql': server.post_connection_sql,
|
||||
}
|
||||
|
||||
return ajax_response(response)
|
||||
|
|
@ -1169,7 +1171,8 @@ class ServerNode(PGChildNodeView):
|
|||
kerberos_conn=1 if data.get('kerberos_conn', False) else 0,
|
||||
connection_params=connection_params,
|
||||
prepare_threshold=data.get('prepare_threshold', None),
|
||||
tags=data.get('tags', None)
|
||||
tags=data.get('tags', None),
|
||||
post_connection_sql=data.get('post_connection_sql', None)
|
||||
)
|
||||
db.session.add(server)
|
||||
db.session.commit()
|
||||
|
|
@ -1585,6 +1588,7 @@ class ServerNode(PGChildNodeView):
|
|||
|
||||
return make_json_response(
|
||||
success=1,
|
||||
errormsg=errmsg,
|
||||
info=gettext("Server connected."),
|
||||
data={
|
||||
"sid": server.id,
|
||||
|
|
|
|||
|
|
@ -697,6 +697,13 @@ define('pgadmin.node.server', [
|
|||
To make sure all the menus for database is in the right state */
|
||||
pgBrowser.enable_disable_menus(_item);
|
||||
|
||||
/* Below code is added to show the error message if
|
||||
connection is successful, but there is an error to
|
||||
run the post connection sql queries. */
|
||||
if (res?.errormsg) {
|
||||
pgAdmin.Browser.notifier.error(res.errormsg, null);
|
||||
}
|
||||
|
||||
// We're not reconnecting
|
||||
if (!_wasConnected) {
|
||||
_tree.setInode(_item);
|
||||
|
|
|
|||
|
|
@ -489,6 +489,14 @@ export default class ServerSchema extends BaseUISchema {
|
|||
helpMessageMode: ['edit', 'create'],
|
||||
helpMessage: gettext('If it is set to 0, every query is prepared the first time it is executed. If it is set to blank, prepared statements are disabled on the connection.')
|
||||
},
|
||||
{
|
||||
id: 'post_connection_sql', label: gettext('Post Connection SQL'),
|
||||
group: gettext('Post Connection SQL'),
|
||||
mode: ['properties', 'edit', 'create'],
|
||||
type: 'sql', isFullTab: true,
|
||||
readonly: obj.isConnected,
|
||||
helpMessage: gettext('Any query specified in the control below will be executed with autocommit mode enabled for each connection to any database on this server.'),
|
||||
},
|
||||
{
|
||||
id: 'tags', label: gettext('Tags'),
|
||||
type: 'collection', group: gettext('Tags'),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import config
|
|||
#
|
||||
##########################################################################
|
||||
|
||||
SCHEMA_VERSION = 42
|
||||
SCHEMA_VERSION = 43
|
||||
|
||||
##########################################################################
|
||||
#
|
||||
|
|
@ -215,6 +215,7 @@ class Server(db.Model):
|
|||
db.CheckConstraint('is_adhoc >= 0 AND is_adhoc <= 1'),
|
||||
nullable=False, default=0
|
||||
)
|
||||
post_connection_sql = db.Column(db.String(), nullable=True)
|
||||
|
||||
def clone(self):
|
||||
d = dict(self.__dict__)
|
||||
|
|
|
|||
|
|
@ -600,9 +600,11 @@ WHERE db.datname = current_database()""")
|
|||
|
||||
self._set_server_type_and_password(kwargs, manager)
|
||||
|
||||
ret_msg = self.execute_post_connection_sql(cur, manager)
|
||||
|
||||
manager.update_session()
|
||||
|
||||
return True, None
|
||||
return True, ret_msg
|
||||
|
||||
def _set_user_info(self, cur, manager, **kwargs):
|
||||
"""
|
||||
|
|
@ -669,6 +671,18 @@ WHERE db.datname = current_database()""")
|
|||
manager.server_cls = st
|
||||
break
|
||||
|
||||
def execute_post_connection_sql(self, cur, manager):
|
||||
# Execute post connection SQL if provided in the server dialog
|
||||
errmsg = None
|
||||
if manager.post_connection_sql and manager.post_connection_sql != '':
|
||||
status = self._execute(cur, manager.post_connection_sql)
|
||||
if status is not None:
|
||||
errmsg = gettext(("Failed to execute the post connection SQL "
|
||||
"with below error message:\n{msg}").format(
|
||||
msg=status))
|
||||
current_app.logger.error(errmsg)
|
||||
return errmsg
|
||||
|
||||
def __cursor(self, server_cursor=False, scrollable=False):
|
||||
|
||||
if not get_crypt_key()[0] and config.SERVER_MODE:
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class ServerManager(object):
|
|||
self.connection_params = server.connection_params
|
||||
self.create_connection_string(self.db, self.user)
|
||||
self.prepare_threshold = server.prepare_threshold
|
||||
self.post_connection_sql = server.post_connection_sql
|
||||
|
||||
for con in self.connections:
|
||||
self.connections[con]._release()
|
||||
|
|
|
|||