Skip to content

Commit

Permalink
fix(readonly): added necessary steps to implement readonly access
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Jan 14, 2025
1 parent 4597fec commit 7cf8011
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
30 changes: 16 additions & 14 deletions API/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
LOG_LEVEL,
SENTRY_DSN,
SENTRY_RATE,
SETUP_INITIAL_TABLES,
USE_CONNECTION_POOLING,
USE_S3_TO_UPLOAD,
get_db_connection_params,
Expand Down Expand Up @@ -158,20 +159,21 @@ async def on_startup():
e: if connection is rejected to database
"""
try:
sql_file_path = os.path.join(
os.path.realpath(os.path.dirname(__file__)), "data/tables.sql"
)
with open(sql_file_path, "r", encoding="UTF-8") as sql_file:
create_tables_sql = sql_file.read()
conn = psycopg2.connect(**get_db_connection_params())
cursor = conn.cursor()
# Execute SQL statements
cursor.execute(create_tables_sql)
conn.commit()

# Close the cursor and connection
cursor.close()
conn.close()
if SETUP_INITIAL_TABLES:
sql_file_path = os.path.join(
os.path.realpath(os.path.dirname(__file__)), "data/tables.sql"
)
with open(sql_file_path, "r", encoding="UTF-8") as sql_file:
create_tables_sql = sql_file.read()
conn = psycopg2.connect(**get_db_connection_params())
cursor = conn.cursor()
# Execute SQL statements
cursor.execute(create_tables_sql)
conn.commit()

# Close the cursor and connection
cursor.close()
conn.close()

if USE_CONNECTION_POOLING:
database_instance.connect()
Expand Down
4 changes: 3 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from src.config import EXPORT_PATH as export_path
from src.config import INDEX_THRESHOLD as index_threshold
from src.config import (
LOG_LEVEL,
MAX_WORKERS,
PARALLEL_PROCESSING_CATEGORIES,
POLYGON_STATISTICS_API_URL,
Expand Down Expand Up @@ -1929,7 +1930,8 @@ def upload_dataset(self, dump_config_to_s3=False):
dataset_info["hdx_upload"] = "SUCCESS"
except Exception as ex:
logging.error(ex)
# raise ex
if LOG_LEVEL == "DEBUG":
raise ex
dataset_info["hdx_upload"] = "FAILED"

dataset_info["name"] = self.dataset["name"]
Expand Down
6 changes: 6 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def not_raises(func, *args, **kwargs):
config.getboolean("API_CONFIG", "ALLOW_BIND_ZIP_FILTER", fallback=False),
)

SETUP_INITIAL_TABLES = get_bool_env_var(
"SETUP_INITIAL_TABLES",
config.getboolean("API_CONFIG", "SETUP_INITIAL_TABLES", fallback=False),
)


ENABLE_SOZIP = get_bool_env_var(
"ENABLE_SOZIP",
config.getboolean("API_CONFIG", "ENABLE_SOZIP", fallback=False),
Expand Down

0 comments on commit 7cf8011

Please sign in to comment.