Skip to content

Commit a45db75

Browse files
Changes in github workflows to install postgis extension
Fixed typo in github workflow Fixing issue in github workflow when installing postgis Fixed issue in workflow Removed postgis for testing checking for logs Testing changes in github workflows file to add postgis and review comments changes in github workflows file to add postgis and review comments
1 parent 23eeb1f commit a45db75

File tree

7 files changed

+47
-19
lines changed

7 files changed

+47
-19
lines changed

.github/workflows/run-python-tests-epas.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
if: ${{ matrix.os == 'ubuntu-22.04' }}
4949
run: |
5050
sudo apt update
51-
sudo apt install -y libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev edb-as${{ matrix.pgver }}-server edb-as${{ matrix.pgver }}-server-pldebugger
51+
sudo apt install -y libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev edb-as${{ matrix.pgver }}-server edb-as${{ matrix.pgver }}-server-pldebugger edb-as${{ matrix.pgver }}-postgis34
5252
5353
- name: Install pgagent on Linux
5454
if: ${{ matrix.os == 'ubuntu-22.04' && matrix.pgver <= 16 }}
@@ -105,6 +105,10 @@ jobs:
105105
- name: Create pgagent extension on Linux
106106
if: ${{ matrix.os == 'ubuntu-22.04' && matrix.pgver <= 16 }}
107107
run: psql -U enterprisedb -d postgres -p 58${{ matrix.pgver }} -c 'CREATE EXTENSION IF NOT EXISTS pgagent;'
108+
109+
- name: Create postgis extension on Linux
110+
if: ${{ matrix.os == 'ubuntu-22.04' && matrix.pgver <= 16 }}
111+
run: psql -U enterprisedb -d postgres -p 58${{ matrix.pgver }} -c 'CREATE EXTENSION IF NOT EXISTS postgis;'
108112

109113
- name: Install Python dependencies on Linux
110114
if: ${{ matrix.os == 'ubuntu-22.04' }}

.github/workflows/run-python-tests-pg.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
if: ${{ matrix.os == 'ubuntu-22.04' }}
5252
run: |
5353
sudo apt update
54-
sudo apt install -y libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev postgresql-${{ matrix.pgver }} postgresql-${{ matrix.pgver }}-pldebugger pgagent
54+
sudo apt install -y libpq-dev libffi-dev libssl-dev libkrb5-dev zlib1g-dev postgresql-${{ matrix.pgver }} postgresql-${{ matrix.pgver }}-pldebugger pgagent postgresql-${{ matrix.pgver }}-postgis-3
5555
5656
- name: Install platform dependencies on macOS
5757
if: ${{ matrix.os == 'macos-latest' }}
@@ -113,6 +113,7 @@ jobs:
113113
114114
psql -U postgres -p 59${{ matrix.pgver }} -c 'CREATE EXTENSION pgagent;'
115115
psql -U postgres -p 59${{ matrix.pgver }} -c 'CREATE EXTENSION pldbgapi;'
116+
psql -U postgres -p 59${{ matrix.pgver }} -c 'CREATE EXTENSION postgis;'
116117
117118
- name: Start PostgreSQL on macOS
118119
if: ${{ matrix.os == 'macos-latest' }}

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/utils.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ def column_formatter(conn, tid, clid, data, edit_types_list=None,
133133
# Fetch length and precision
134134
data = fetch_length_precision(data)
135135

136-
data = fetch_geometry_details(data)
137-
138136
# We need to fetch inherited tables for each table
139137
is_error, errmsg = _fetch_inherited_tables(
140138
tid, data, fetch_inherited_tables, template_path, conn)
@@ -451,19 +449,24 @@ def fetch_length_precision(data):
451449
data['attlen'] = None
452450
data['attprecision'] = None
453451

452+
match_obj = fetch_length_precision_details(fulltype, data)
453+
454454
# If we have length & precision both
455455
if length and precision:
456-
match_obj = re.search(r'(\d+),(\d+)', fulltype)
457456
if match_obj:
458457
data['attlen'] = match_obj.group(1)
459-
data['attprecision'] = match_obj.group(2)
458+
data['attprecision'] = match_obj.group(3)
460459
elif length:
461460
# If we have length only
462-
match_obj = re.search(r'(\d+)', fulltype)
463461
if match_obj:
464462
data['attlen'] = match_obj.group(1)
465463
data['attprecision'] = None
466464

465+
# If we have geometry column
466+
if 'typname' in data and (data['typname'] in ('geometry', 'geography')):
467+
data['geometry'] = match_obj.group(2)
468+
data['srid'] = match_obj.group(3)
469+
467470
return data
468471

469472

@@ -477,10 +480,19 @@ def parse_column_variables(col_variables):
477480
return spcoptions
478481

479482

480-
def fetch_geometry_details(data):
481-
if 'typname' in data and (data['typname'] in ('geometry', 'geography')):
482-
match_obj = re.search(r'([a-zA-Z]+),(\d+)', data['cltype'])
483-
if match_obj:
484-
data['geometry'] = match_obj.group(1)
485-
data['srid'] = match_obj.group(2)
486-
return data
483+
def fetch_length_precision_details(fulltype, data):
484+
"""
485+
This function will fetch length and precision details
486+
from fulltype.
487+
488+
:param fulltype: Full type.
489+
:param data: Data.
490+
"""
491+
492+
match_obj = None
493+
regex = r'\((\d*)([a-zA-Z]*),?(\d*)\)'
494+
if data['typname'] in ('geometry', 'geography'):
495+
match_obj = re.search(regex, data['cltype'])
496+
else:
497+
match_obj = re.search(regex, fulltype)
498+
return match_obj

web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,7 @@ def is_postgis_present(self):
657657
self.server['port'],
658658
self.server['sslmode'])
659659
pg_cursor = connection.cursor()
660-
pg_cursor.execute('''SELECT COUNT(*) FROM pg_extension WHERE
661-
extname='postgis' ''')
662-
res = pg_cursor.fetchone()
660+
res = utils.check_extension_exists(pg_cursor, 'postgis')
663661
connection.close()
664662
if res and len(res) > 0 and int(res[0]) == 1:
665663
return True

web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pgadmin.browser.collection import CollectionNodeModule
1919
from pgadmin.utils.ajax import internal_server_error
2020
from pgadmin.utils.driver import get_driver
21+
from pgadmin.utils import check_extension_exists
2122
from config import PG_DEFAULT_DRIVER
2223
from pgadmin.utils.constants import DATATYPE_TIME_WITH_TIMEZONE,\
2324
DATATYPE_TIME_WITHOUT_TIMEZONE,\
@@ -194,8 +195,7 @@ def get_types(self, conn, condition, add_serials=False, schema_oid=''):
194195

195196
def get_geometry_types(self, conn):
196197
types = []
197-
sql = "SELECT * FROM pg_extension WHERE extname = 'postgis';"
198-
status, res = conn.execute_scalar(sql)
198+
status, res = check_extension_exists(conn, 'postgis')
199199
if not status:
200200
return status, res
201201
if res:

web/pgadmin/utils/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,9 @@ def get_safe_post_logout_redirect():
984984
if url.startswith(item):
985985
return url
986986
return url_for('security.login')
987+
988+
989+
def check_extension_exists(conn, extension_name):
990+
sql = f"SELECT * FROM pg_extension WHERE extname = '{extension_name}'"
991+
status, res = conn.execute_scalar(sql)
992+
return status, res

web/regression/python_test_utils/test_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,3 +1885,10 @@ def module_patch(*args):
18851885

18861886
# did not find a module, just return the default mock
18871887
return mock.patch(*args)
1888+
1889+
1890+
def check_extension_exists(cursor, extension_name):
1891+
cursor.execute(f"""SELECT COUNT(*) FROM pg_extension
1892+
WHERE extname='{extension_name}'""")
1893+
res = cursor.fetchone()
1894+
return res

0 commit comments

Comments
 (0)