Skip to content

Commit

Permalink
FixUp
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Sep 25, 2023
1 parent 8c70e1e commit 7ae16e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/layman/layer/db/table.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from psycopg2 import sql

from db import util as db_util
Expand All @@ -7,6 +8,7 @@
from . import get_internal_table_name
from .. import LAYER_TYPE, util as layer_util

logger = logging.getLogger(__name__)
PATCH_MODE = patch_mode.DELETE_IF_DEPENDANT


Expand All @@ -26,6 +28,18 @@ def get_layer_info(workspace, layername,):
db_uri_str = None
else:
db_uri_str = table_uri.db_uri_str
try:
db_util.get_connection_pool(db_uri_str=db_uri_str,)
except BaseException:
result['db'] = {
'schema': table_uri.schema,
'table': table_uri.table,
'geo_column': table_uri.geo_column,
'external_uri': layer_util.redact_uri(table_uri.db_uri_str),
'status': 'NOT_AVAILABLE',
'error': 'Cannot connect to DB.',
}
return result
try:
rows = db_util.run_query(f"""
SELECT schemaname, tablename, tableowner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_new_attribute(self, layer: Publication, rest_args, params, parametrizat
context={'keys': ['table_uri']})['_table_uri']
table_uris[layer_name] = table_uri
old_db_attributes[layer_name] = db.get_all_table_column_names(table_uri.schema, table_uri.table,
uri_str=table_uri, )
uri_str=table_uri.db_uri_str, )
for attr_name in attr_names:
assert attr_name not in old_db_attributes[layer_name], \
f"old_db_attributes={old_db_attributes[layer_name]}, attr_name={attr_name}"
Expand Down Expand Up @@ -284,7 +284,7 @@ def test_new_attribute(self, layer: Publication, rest_args, params, parametrizat
for layer_name, attr_names in new_attributes:
# assert that exactly all attr_names were created in DB table
table_uri = table_uris[layer_name]
db_attributes = db.get_all_table_column_names(table_uri.schema, table_uri.table, uri_str=table_uri)
db_attributes = db.get_all_table_column_names(table_uri.schema, table_uri.table, uri_str=table_uri.db_uri_str)
for attr_name in attr_names:
assert attr_name in db_attributes, f"db_attributes={db_attributes}, attr_name={attr_name}"
assert set(attr_names).union(set(old_db_attributes[layer_name])) == set(db_attributes)
Expand Down

0 comments on commit 7ae16e1

Please sign in to comment.