Skip to content

Commit 52508d1

Browse files
Merge pull request #288 from hotosm/feature/readonlyaccess
fix(readonly): added necessary steps to implement readonly access
2 parents 4597fec + 7cf8011 commit 52508d1

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

API/main.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
LOG_LEVEL,
4040
SENTRY_DSN,
4141
SENTRY_RATE,
42+
SETUP_INITIAL_TABLES,
4243
USE_CONNECTION_POOLING,
4344
USE_S3_TO_UPLOAD,
4445
get_db_connection_params,
@@ -158,20 +159,21 @@ async def on_startup():
158159
e: if connection is rejected to database
159160
"""
160161
try:
161-
sql_file_path = os.path.join(
162-
os.path.realpath(os.path.dirname(__file__)), "data/tables.sql"
163-
)
164-
with open(sql_file_path, "r", encoding="UTF-8") as sql_file:
165-
create_tables_sql = sql_file.read()
166-
conn = psycopg2.connect(**get_db_connection_params())
167-
cursor = conn.cursor()
168-
# Execute SQL statements
169-
cursor.execute(create_tables_sql)
170-
conn.commit()
171-
172-
# Close the cursor and connection
173-
cursor.close()
174-
conn.close()
162+
if SETUP_INITIAL_TABLES:
163+
sql_file_path = os.path.join(
164+
os.path.realpath(os.path.dirname(__file__)), "data/tables.sql"
165+
)
166+
with open(sql_file_path, "r", encoding="UTF-8") as sql_file:
167+
create_tables_sql = sql_file.read()
168+
conn = psycopg2.connect(**get_db_connection_params())
169+
cursor = conn.cursor()
170+
# Execute SQL statements
171+
cursor.execute(create_tables_sql)
172+
conn.commit()
173+
174+
# Close the cursor and connection
175+
cursor.close()
176+
conn.close()
175177

176178
if USE_CONNECTION_POOLING:
177179
database_instance.connect()

src/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from src.config import EXPORT_PATH as export_path
6565
from src.config import INDEX_THRESHOLD as index_threshold
6666
from src.config import (
67+
LOG_LEVEL,
6768
MAX_WORKERS,
6869
PARALLEL_PROCESSING_CATEGORIES,
6970
POLYGON_STATISTICS_API_URL,
@@ -1929,7 +1930,8 @@ def upload_dataset(self, dump_config_to_s3=False):
19291930
dataset_info["hdx_upload"] = "SUCCESS"
19301931
except Exception as ex:
19311932
logging.error(ex)
1932-
# raise ex
1933+
if LOG_LEVEL == "DEBUG":
1934+
raise ex
19331935
dataset_info["hdx_upload"] = "FAILED"
19341936

19351937
dataset_info["name"] = self.dataset["name"]

src/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ def not_raises(func, *args, **kwargs):
185185
config.getboolean("API_CONFIG", "ALLOW_BIND_ZIP_FILTER", fallback=False),
186186
)
187187

188+
SETUP_INITIAL_TABLES = get_bool_env_var(
189+
"SETUP_INITIAL_TABLES",
190+
config.getboolean("API_CONFIG", "SETUP_INITIAL_TABLES", fallback=False),
191+
)
192+
193+
188194
ENABLE_SOZIP = get_bool_env_var(
189195
"ENABLE_SOZIP",
190196
config.getboolean("API_CONFIG", "ENABLE_SOZIP", fallback=False),

0 commit comments

Comments
 (0)