Skip to content

Commit

Permalink
WIP: Do not pool connections internally
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Sep 21, 2023
1 parent 85268aa commit 7f5238a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/layman/geoserver_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ def ensure_attributes_in_db(attributes_by_db):
(schema, table, attr): (workspace, layer, attr)
for workspace, layer, attr, schema, table in attr_tuples
}
conn_cur = db_util.get_connection_cursor(db_uri_str=db_uri_str)
db_attr_tuples = list(db_layman_attr_mapping.keys())
created_db_attr_tuples = db.ensure_attributes(db_attr_tuples, conn_cur)
created_db_attr_tuples = db.ensure_attributes(db_attr_tuples, db_uri_str=db_uri_str)
all_created_attr_tuples.update({db_layman_attr_mapping[a] for a in created_db_attr_tuples})
return all_created_attr_tuples

Expand Down
6 changes: 3 additions & 3 deletions src/layman/layer/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ def get_missing_attributes(attribute_tuples, conn_cur=None):
return missing_attributes


def ensure_attributes(attribute_tuples, conn_cur):
missing_attributes = get_missing_attributes(attribute_tuples, conn_cur)
def ensure_attributes(attribute_tuples, db_uri_str):
missing_attributes = get_missing_attributes(attribute_tuples, db_uri_str)
if missing_attributes:
dangerous_attribute_names = {
a for _, _, a in missing_attributes
Expand All @@ -546,7 +546,7 @@ def ensure_attributes(attribute_tuples, conn_cur):
'expected': r'Attribute names matching regex ^[a-zA-Z_][a-zA-Z_0-9]*$',
'found': sorted(dangerous_attribute_names),
})
create_string_attributes(missing_attributes, conn_cur)
create_string_attributes(missing_attributes, db_uri_str)
return missing_attributes


Expand Down
3 changes: 1 addition & 2 deletions test_tools/external_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ def ensure_db():
with app.app_context():
db_util.run_statement(statement)

conn_cur = db_util.get_connection_cursor(URI_STR)
statement = f"""
CREATE USER {READ_ONLY_USER} WITH PASSWORD '{READ_ONLY_PASSWORD}';
GRANT CONNECT ON DATABASE {EXTERNAL_DB_NAME} TO {READ_ONLY_USER};
ALTER DEFAULT PRIVILEGES GRANT SELECT ON TABLES TO {READ_ONLY_USER};
"""
db_util.run_statement(statement, conn_cur=conn_cur)
db_util.run_statement(statement, )

yield

Expand Down

0 comments on commit 7f5238a

Please sign in to comment.