Skip to content

Commit 04d3225

Browse files
Made pulling config from db optional so IF the project is defined in dot_congig.yml, it's taken from there - if not, it's taken from the db. Also reverted changes in dot_config_github.yml to prevent selftests in GH from failing.
1 parent 3a0ecbf commit 04d3225

2 files changed

Lines changed: 43 additions & 45 deletions

File tree

dot/config/example/self_tests/dot_config_github.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ dot_db:
1010
dbname: dot_db
1111
schema: self_tests_dot
1212
threads: 4
13-
13+
ScanProject1_db:
14+
type: postgres
15+
host: localhost
16+
user: postgres
17+
pass: postgres
18+
port: 5432
19+
dbname: dot_db
20+
schema: self_tests_public
21+
threads: 4

dot/utils/configuration_utils.py

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -134,55 +134,45 @@ def load_config_from_db(project_id: str):
134134
config = load_config_file()
135135
db_credentials = config.get("dot_db", {})
136136

137-
db_credentials["pass"] = os.getenv("POSTGRES_PASSWORD", "postgres")
138-
139-
engine = create_engine(
140-
"postgresql://"
141-
+ db_credentials["user"]
142-
+ ":"
143-
+ db_credentials["pass"]
144-
+ "@"
145-
+ db_credentials["host"]
146-
+ ":"
147-
+ str(db_credentials["port"])
148-
+ "/"
149-
+ db_credentials["dbname"],
150-
paramstyle="format",
151-
executemany_mode="values",
152-
executemany_values_page_size=1000,
153-
executemany_batch_page_size=200,
154-
)
137+
if f"{project_id}_db" not in config:
138+
139+
db_credentials["pass"] = os.getenv("POSTGRES_PASSWORD", "postgres")
140+
141+
engine = create_engine(
142+
"postgresql://"
143+
+ db_credentials["user"]
144+
+ ":"
145+
+ db_credentials["pass"]
146+
+ "@"
147+
+ db_credentials["host"]
148+
+ ":"
149+
+ str(db_credentials["port"])
150+
+ "/"
151+
+ db_credentials["dbname"],
152+
paramstyle="format",
153+
executemany_mode="values",
154+
executemany_values_page_size=1000,
155+
executemany_batch_page_size=200,
156+
)
157+
158+
# establish_db_connection(with db_config creds)
159+
sql = f"SELECT project_schema FROM dot.projects WHERE project_id = '{project_id}';"
155160

156-
# establish_db_connection(with db_config creds)
157-
sql = f"SELECT project_schema FROM dot.projects WHERE project_id = '{project_id}';"
158-
sql_selftest = f"SELECT project_schema FROM self_tests_public.projects WHERE project_id = '{project_id}';"
159-
with engine.begin() as conn:
160-
result = conn.execute(sql_selftest)
161-
row = result.fetchone()
162-
project_schema = row['project_schema']
163-
164-
"""#try with block, if it fails, print error
165-
try:
166-
with engine.begin() as conn:
167-
result = conn.execute(sql)
168-
row = result.fetchone()
169-
170-
if row is None:
171-
raise Exception(f"Looks like the project_id '{project_id}' has not been set up. "
172-
f"Please check the projects in appsmith or under the dot.projects table in the dot_db and try again.")
173-
else:
161+
#try with block, if it fails, print error
162+
try:
163+
with engine.begin() as conn:
164+
result = conn.execute(sql)
165+
row = result.fetchone()
174166
project_schema = row['project_schema']
175167

176-
except Exception as e:
177-
with engine.begin() as conn:
178-
result = conn.execute(sql_selftest)
179-
row = result.fetchone()
180-
project_schema = row['project_schema']"""
168+
except Exception as e:
169+
raise Exception(f"Looks like the project_id '{project_id}' has not been set up. "
170+
f"Please check the projects in appsmith or under the dot.projects table in the dot_db and try again.")
181171

182-
project = project_id + "_db"
183-
new_entry = {project: {'type': 'postgres', 'host': 'dot_db', 'user': 'postgres', 'pass': os.getenv("POSTGRES_PASSWORD"), 'port': 5432, 'dbname': 'dot_db', 'schema': project_schema, 'threads': 4}}
172+
project = project_id + "_db"
173+
new_entry = {project: {'type': 'postgres', 'host': 'dot_db', 'user': 'postgres', 'pass': os.getenv("POSTGRES_PASSWORD"), 'port': 5432, 'dbname': 'dot_db', 'schema': project_schema, 'threads': 4}}
184174

185-
config[project] = new_entry[project]
175+
config[project] = new_entry[project]
186176

187177
return config
188178

0 commit comments

Comments
 (0)