Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(readonly): added necessary steps to implement readonly access #288

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading