Skip to content

Commit 5c6a7e9

Browse files
authored
Merge pull request #1 from alliedmodders/psy/expose-table-name
Expose commit log table name
2 parents 56315e1 + 8eb9b94 commit 5c6a7e9

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ database:
6161
user: "sm_commit_update"
6262
password: "..." # env: DATABASE__PASSWORD
6363
name: "sourcemod"
64+
commit_log_table: "sm_commit_log" # env: DATABASE__COMMIT_LOG_TABLE; default: sm_commit_log
6465

6566
repo:
6667
owner: "alliedmodders"

app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class DatabaseSettings(BaseModel):
5656
user: str
5757
password: str
5858
name: str = "sourcemod"
59+
commit_log_table: str = "sm_commit_log"
5960

6061

6162
class RepoSettings(BaseModel):
@@ -145,6 +146,7 @@ def _run_reconcile():
145146
download_fn=lambda url, path: download_file(url, path),
146147
product_name=config.repo.product_name,
147148
max_age_days=config.repo.reconcile_max_age_days,
149+
commit_log_table=config.database.commit_log_table,
148150
)
149151
except Exception:
150152
logger.exception("Scheduled reconciliation failed")
@@ -402,6 +404,7 @@ def process_artifacts(
402404
_releases_client,
403405
config.database,
404406
config.repo.version_branches,
407+
commit_log_table=config.database.commit_log_table,
405408
)
406409
except Exception:
407410
logger.exception(

config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ api:
1212
# user: "mysql-user"
1313
# password: "your-db-password" # Or set DATABASE__PASSWORD env var
1414
# name: "sourcemod"
15+
# commit_log_table: "sm_commit_log" # Table to write build records to; defaults to sm_commit_log
1516

1617
# repo:
1718
# owner: "alliedmodders"

db.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ def get_connection(config):
2727
conn.close()
2828

2929

30-
def get_known_builds(conn) -> dict[str, dict[int, dict]]:
30+
def get_known_builds(
31+
conn, table_name: str = "sm_commit_log"
32+
) -> dict[str, dict[int, dict]]:
3133
"""
32-
Return {branch: {build_num: {windows_url, linux_url}}} for all rows in sm_commit_log.
34+
Return {branch: {build_num: {windows_url, linux_url}}} for all rows in the commit log.
3335
URLs may be None if not yet populated.
3436
"""
3537
with conn.cursor() as cur:
36-
cur.execute("SELECT branch, build, windows_url, linux_url FROM sm_commit_log")
38+
cur.execute(f"SELECT branch, build, windows_url, linux_url FROM `{table_name}`") # noqa: S608
3739
known: dict[str, dict[int, dict]] = {}
3840
for row in cur.fetchall():
3941
known.setdefault(row["branch"], {})[row["build"]] = {
@@ -43,12 +45,20 @@ def get_known_builds(conn) -> dict[str, dict[int, dict]]:
4345
return known
4446

4547

46-
def update_build_urls(conn, *, branch, build_num, windows_url, linux_url):
48+
def update_build_urls(
49+
conn,
50+
*,
51+
branch,
52+
build_num,
53+
windows_url,
54+
linux_url,
55+
table_name: str = "sm_commit_log",
56+
):
4757
"""Fill in NULL URL columns for an existing build. Non-NULL values are never overwritten."""
4858
with conn.cursor() as cur:
4959
cur.execute(
50-
"""
51-
UPDATE sm_commit_log
60+
f"""
61+
UPDATE `{table_name}`
5262
SET windows_url = COALESCE(%s, windows_url),
5363
linux_url = COALESCE(%s, linux_url)
5464
WHERE branch = %s AND build = %s
@@ -58,16 +68,25 @@ def update_build_urls(conn, *, branch, build_num, windows_url, linux_url):
5868

5969

6070
def upsert_build(
61-
conn, *, branch, sha, build_num, timestamp, message, windows_url, linux_url
71+
conn,
72+
*,
73+
branch,
74+
sha,
75+
build_num,
76+
timestamp,
77+
message,
78+
windows_url,
79+
linux_url,
80+
table_name: str = "sm_commit_log",
6281
):
6382
"""
6483
Insert a build record, or on duplicate key fill in any NULL URL columns.
6584
Existing non-NULL URLs are never overwritten.
6685
"""
6786
with conn.cursor() as cur:
6887
cur.execute(
69-
"""
70-
INSERT INTO sm_commit_log
88+
f"""
89+
INSERT INTO `{table_name}`
7190
(branch, hash, build, date, message, windows_url, linux_url)
7291
VALUES (%s, %s, %s, FROM_UNIXTIME(%s), %s, %s, %s)
7392
ON DUPLICATE KEY UPDATE

reconciler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def upsert_from_release(
1717
client: GitHubReleasesClient,
1818
db_config,
1919
version_branches: dict[str, str],
20+
commit_log_table: str = "sm_commit_log",
2021
) -> bool:
2122
"""
2223
Resolve and upsert a single GitHub release to the DB.
@@ -59,6 +60,7 @@ def upsert_from_release(
5960
message=message,
6061
windows_url=windows_url,
6162
linux_url=linux_url,
63+
table_name=commit_log_table,
6264
)
6365

6466
logger.info("DB updated for build %d (branch %s, tag %s)", build_num, branch, tag)
@@ -118,6 +120,7 @@ def reconcile(
118120
download_fn: Callable | None = None,
119121
product_name: str | None = None,
120122
max_age_days: int | None = 90,
123+
commit_log_table: str = "sm_commit_log",
121124
) -> int:
122125
"""
123126
Fetch GitHub releases and reconcile DB records, build archives, and symbols.
@@ -140,7 +143,7 @@ def reconcile(
140143
Returns the number of newly DB-inserted builds.
141144
"""
142145
with get_connection(db_config) as conn:
143-
known = get_known_builds(conn)
146+
known = get_known_builds(conn, table_name=commit_log_table)
144147

145148
new_count = 0
146149

@@ -199,6 +202,7 @@ def reconcile(
199202
build_num=build_num,
200203
windows_url=windows_url,
201204
linux_url=linux_url,
205+
table_name=commit_log_table,
202206
)
203207
known.setdefault(branch, {})[build_num] = {
204208
"windows_url": windows_url
@@ -234,6 +238,7 @@ def reconcile(
234238
message=message,
235239
windows_url=windows_url,
236240
linux_url=linux_url,
241+
table_name=commit_log_table,
237242
)
238243

239244
known.setdefault(branch, {})[build_num] = {

0 commit comments

Comments
 (0)