Skip to content

Commit

Permalink
Enable specifying a postgres schema by an environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelwedler committed Oct 31, 2024
1 parent a3f7c1b commit e6e9987
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=your_db_port
DB_SCHEMA=public
S3_ENDPOINT_URL=
S3_BUCKET_NAME=
AWS_ACCESS_KEY_ID=
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def upload_to_s3(file_path, bucket_name, object_name):
logger.error("Incomplete credentials provided")

def fetch_and_write(table_config, engine):
postgres_schema_name = os.getenv('DB_SCHEMA')
table_name = table_config['name']
dtypes = table_config['datatypes']
schema = get_pyarrow_schema(dtypes)
Expand All @@ -196,9 +197,9 @@ def fetch_and_write(table_config, engine):
with engine.connect().execution_options(stream_results=True) as connection:


query = text(f"SELECT * FROM {table_name}")
query = text(f"SELECT * FROM {postgres_schema_name}.{table_name}")
if os.getenv('DEBUG_OFFSET'):
query = text(f"SELECT * FROM {table_name} OFFSET {os.getenv('DEBUG_OFFSET')}")
query = text(f"SELECT * FROM {postgres_schema_name}.{table_name} OFFSET {os.getenv('DEBUG_OFFSET')}")
logger.info(f"Executing query for table {table_name}: {query}")

start_time = time.time()
Expand Down

0 comments on commit e6e9987

Please sign in to comment.